Skip to content

Commit b956bfd

Browse files
committed
chore(prometheus): add username to prometheus url
1 parent fd2b96a commit b956bfd

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

rootfs/api/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@
249249
r'^nodes/(?P<node>[a-zA-Z0-9-]+)/proxy/metrics(?:/(?P<metrics>[^/]+))?/?$',
250250
views.ProxyMetricsView.as_view()),
251251
# prometheus
252-
re_path(r'^prometheus/(?P<path>.+)/?$', views.PrometheusProxy.as_view()),
252+
re_path(
253+
r'^prometheus/(?P<username>[\w.@+-]+)/(?P<path>.+)/?$', views.PrometheusProxy.as_view()),
253254
# tokens
254255
re_path(r'^tokens/?$', views.TokenViewSet.as_view({'get': 'list'})),
255256
re_path(r"^tokens/(?P<pk>[-_\w]+)/?$", views.TokenViewSet.as_view({'delete': 'destroy'})),

rootfs/api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,9 @@ class PrometheusProxy(View):
13361336
timeout = aiohttp.ClientTimeout(total=30, connect=10, sock_read=15)
13371337
authentication = authentication.DryccAuthentication()
13381338

1339-
async def proxy(self, request, path):
1339+
async def proxy(self, request, username, path):
13401340
auth = await database_sync_to_async(self.authentication.authenticate)(request)
1341-
if not auth or len(auth) != 2 or not isinstance(auth[0], User):
1341+
if not auth or len(auth) != 2 or not auth[0].username != username:
13421342
return JsonResponse({'error': 'access denied'}, status=403)
13431343
if auth[0].is_superuser or auth[0].is_staff:
13441344
path = f"/select/0/prometheus/{path}"

0 commit comments

Comments
 (0)