perf: 取消API Token的配置

pull/6815/head
Michael Bai 3 years ago committed by Jiangjie.Bai
parent 773f7048be
commit 1a1ad0f1a2

@ -298,28 +298,33 @@ class IndexApi(DatesLoginMetricMixin, APIView):
class HealthApiMixin(APIView):
def is_token_right(self):
token = self.request.query_params.get('token')
ok_token = settings.HEALTH_CHECK_TOKEN
if ok_token and token != ok_token:
return False
return True
def is_localhost(self):
ip = get_request_ip(self.request)
return ip in ['localhost', '127.0.0.1']
def check_permissions(self, request):
if self.is_token_right():
return
if self.is_localhost():
return
msg = '''
Health check token error,
Please set query param in url and same with setting HEALTH_CHECK_TOKEN.
eg: $PATH/?token=$HEALTH_CHECK_TOKEN
'''
self.permission_denied(request, message={'error': msg}, code=403)
pass
# 先去掉 Health Api 的权限校验,方便各组件直接调用
# def is_token_right(self):
# token = self.request.query_params.get('token')
# ok_token = settings.HEALTH_CHECK_TOKEN
# if ok_token and token != ok_token:
# return False
# return True
# def is_localhost(self):
# ip = get_request_ip(self.request)
# return ip in ['localhost', '127.0.0.1']
# def check_permissions(self, request):
# if self.is_token_right():
# return
# if self.is_localhost():
# return
# msg = '''
# Health check token error,
# Please set query param in url and
# same with setting HEALTH_CHECK_TOKEN.
# eg: $PATH/?token=$HEALTH_CHECK_TOKEN
# '''
# self.permission_denied(request, message={'error': msg}, code=403)
class HealthCheckView(HealthApiMixin):

@ -17,9 +17,9 @@ class AuthSettingSerializer(serializers.Serializer):
FORGOT_PASSWORD_URL = serializers.CharField(
required=False, max_length=1024, label=_("Forgot password url")
)
HEALTH_CHECK_TOKEN = serializers.CharField(
required=False, max_length=1024, label=_("Health check token")
)
# HEALTH_CHECK_TOKEN = serializers.CharField(
# required=False, max_length=1024, label=_("Health check token")
# )
LOGIN_REDIRECT_MSG_ENABLED = serializers.BooleanField(
required=False, label=_("Enable login redirect msg")
)

Loading…
Cancel
Save