mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 07:56:06 -03:30
related #6753 allow metrics for anonymous users
Signed-off-by: Nico Ohnezat <nico@no-12.net>
This commit is contained in:
@@ -96,6 +96,15 @@ register(
|
|||||||
category=_('Authentication'),
|
category=_('Authentication'),
|
||||||
category_slug='authentication',
|
category_slug='authentication',
|
||||||
)
|
)
|
||||||
|
register(
|
||||||
|
'ALLOW_METRICS_FOR_ANONYMOUS_USERS',
|
||||||
|
field_class=fields.BooleanField,
|
||||||
|
default=False,
|
||||||
|
label=_('Allow anonymous users to poll metrics'),
|
||||||
|
help_text=_('If false, only superusers and system auditors are allowed to poll metrics.'),
|
||||||
|
category=_('Authentication'),
|
||||||
|
category_slug='authentication',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def authentication_validate(serializer, attrs):
|
def authentication_validate(serializer, attrs):
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
|
from rest_framework.permissions import AllowAny
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
|
|
||||||
@@ -31,9 +33,14 @@ class MetricsView(APIView):
|
|||||||
|
|
||||||
renderer_classes = [renderers.PlainTextRenderer, renderers.PrometheusJSONRenderer, renderers.BrowsableAPIRenderer]
|
renderer_classes = [renderers.PlainTextRenderer, renderers.PrometheusJSONRenderer, renderers.BrowsableAPIRenderer]
|
||||||
|
|
||||||
|
def initialize_request(self, request, *args, **kwargs):
|
||||||
|
if settings.ALLOW_METRICS_FOR_ANONYMOUS_USERS:
|
||||||
|
self.permission_classes = (AllowAny,)
|
||||||
|
return super(APIView, self).initialize_request(request, *args, **kwargs)
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
'''Show Metrics Details'''
|
'''Show Metrics Details'''
|
||||||
if request.user.is_superuser or request.user.is_system_auditor:
|
if settings.ALLOW_METRICS_FOR_ANONYMOUS_USERS or request.user.is_superuser or request.user.is_system_auditor:
|
||||||
metrics_to_show = ''
|
metrics_to_show = ''
|
||||||
if not request.query_params.get('subsystemonly', "0") == "1":
|
if not request.query_params.get('subsystemonly', "0") == "1":
|
||||||
metrics_to_show += metrics().decode('UTF-8')
|
metrics_to_show += metrics().decode('UTF-8')
|
||||||
|
|||||||
@@ -418,6 +418,9 @@ AUTH_BASIC_ENABLED = True
|
|||||||
# when trying to access a UI page that requries authentication.
|
# when trying to access a UI page that requries authentication.
|
||||||
LOGIN_REDIRECT_OVERRIDE = ''
|
LOGIN_REDIRECT_OVERRIDE = ''
|
||||||
|
|
||||||
|
# Note: This setting may be overridden by database settings.
|
||||||
|
ALLOW_METRICS_FOR_ANONYMOUS_USERS = False
|
||||||
|
|
||||||
DEVSERVER_DEFAULT_ADDR = '0.0.0.0'
|
DEVSERVER_DEFAULT_ADDR = '0.0.0.0'
|
||||||
DEVSERVER_DEFAULT_PORT = '8013'
|
DEVSERVER_DEFAULT_PORT = '8013'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user