1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Exclude /metrics from LOGIN_REQUIRED

This commit is contained in:
Lars Weiler
2019-04-30 16:09:10 +02:00
parent 4d2ac1ca53
commit 99f0e7b939

View File

@ -19,9 +19,10 @@ class LoginRequiredMiddleware(object):
def __call__(self, request):
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
# performs its own authentication.
# performs its own authentication. Also metrics can be read without login.
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) or request.path_info.startswith('/metrics'))
and request.path_info != settings.LOGIN_URL):
return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info))
return self.get_response(request)