mirror of https://github.com/jumpserver/jumpserver
fix: api/health/健康检测添加localhost
parent
654ec4970e
commit
bf6b685e8c
|
@ -17,9 +17,10 @@ from terminal.models import Session
|
||||||
from terminal.utils import ComponentsPrometheusMetricsUtil
|
from terminal.utils import ComponentsPrometheusMetricsUtil
|
||||||
from orgs.utils import current_org
|
from orgs.utils import current_org
|
||||||
from common.permissions import IsOrgAdmin, IsOrgAuditor
|
from common.permissions import IsOrgAdmin, IsOrgAuditor
|
||||||
from common.utils import lazyproperty
|
from common.utils import lazyproperty, get_request_ip
|
||||||
from orgs.caches import OrgResourceStatisticsCache
|
from orgs.caches import OrgResourceStatisticsCache
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['IndexApi']
|
__all__ = ['IndexApi']
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,12 +305,21 @@ class HealthApiMixin(APIView):
|
||||||
return False
|
return False
|
||||||
return True
|
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):
|
def check_permissions(self, request):
|
||||||
if not self.is_token_right():
|
if self.is_token_right():
|
||||||
msg = 'Health check token error, ' \
|
return
|
||||||
'Please set query param in url and same with setting HEALTH_CHECK_TOKEN. ' \
|
if self.is_localhost():
|
||||||
'eg: $PATH/?token=$HEALTH_CHECK_TOKEN'
|
return
|
||||||
self.permission_denied(request, message={'error': msg}, code=403)
|
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):
|
||||||
|
|
Loading…
Reference in New Issue