perf: 取消API Token的配置

pull/6815/head
Michael Bai 2021-09-13 13:47:34 +08:00 committed by Jiangjie.Bai
parent 773f7048be
commit 1a1ad0f1a2
2 changed files with 28 additions and 23 deletions

View File

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

View File

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