Merge pull request #3124 from larsweiler/develop-2.6-metrics

Exclude /metrics from LOGIN_REQUIRED
This commit is contained in:
John Anderson 2019-04-30 11:08:55 -04:00 committed by GitHub
commit f9a74b68c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,9 +19,9 @@ class LoginRequiredMiddleware(object):
def __call__(self, request): def __call__(self, request):
if LOGIN_REQUIRED and not request.user.is_authenticated: if LOGIN_REQUIRED and not request.user.is_authenticated:
# Redirect unauthenticated requests to the login page. API requests are exempt from redirection as the API # Redirect unauthenticated requests to the login page. API requests are exempt from redirection as the API
# performs its own authentication. # performs its own authentication. Also metrics can be read without login.
api_path = reverse('api-root') api_path = reverse('api-root')
if not request.path_info.startswith(api_path) and request.path_info != settings.LOGIN_URL: if not request.path_info.startswith((api_path, '/metrics')) and request.path_info != settings.LOGIN_URL:
return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info)) return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info))
return self.get_response(request) return self.get_response(request)