Skip to content

Commit

Permalink
Fix slug and sub_id regex for stats, metrics and single domain and in…
Browse files Browse the repository at this point in the history
… routine.
  • Loading branch information
PhilippKilian authored and liske committed Apr 12, 2022
1 parent 536d095 commit ece5b30
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions b3lb/loadbalancer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
path('b3lb/stats', stats),
path('b3lb/metrics', metrics),
path('b3lb/ping', ping),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10}(-(?P<sub_id>\d{3}))?)/bbb/api/(?P<endpoint>[0-9.a-zA-Z]*)$', api_pass_through),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10}(-(?P<sub_id>\d{3}))?)/stats', stats),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10}(-(?P<sub_id>\d{3}))?)/metrics', metrics),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})(-(?P<sub_id>\d{3}))?/bbb/api/(?P<endpoint>[0-9.a-zA-Z]*)$', api_pass_through),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})(-(?P<sub_id>\d{3}))?/stats', stats),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})(-(?P<sub_id>\d{3}))?/metrics', metrics),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})/logo', logo),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})/slide', slide),
url(r'^b3lb/t/(?P<slug>[a-z]{2,10})/css', custom_css),
Expand Down
12 changes: 6 additions & 6 deletions b3lb/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Django==3.2.12
Django==3.2.13
django-extensions==3.1.5
requests==2.27.1
celery==5.2.3
celery==5.2.6
celery-singleton==0.3.1
django-cacheops==6.0
django-db-file-storage==0.5.5
django-celery-admin==0.1
django-celery-beat==2.2.1
django-celery-results==2.2.0
django-celery-results==2.3.0
django-environ==0.8.1
django-redis==5.2.0
django-split-settings==1.1.0
psycopg2cffi==2.9.0
uvicorn[standard]==0.17.5
uvicorn[standard]==0.17.6
aiohttp==3.8.1
jinja2==3.0.3
Pillow==9.0.1
jinja2==3.1.1
Pillow==9.1.0
6 changes: 3 additions & 3 deletions b3lb/rest/b3lb/lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ def get_slug(request, slug, sub_id):
else:
return None, None
else:
return slug, int(sub_id)
return slug.upper(), int(sub_id)


def get_request_tenant(request, slug, sub_id):
(slug, sub_id) = get_slug(request, slug, sub_id)
slug, sub_id = get_slug(request, slug, sub_id)
if not slug:
return None

Expand All @@ -204,7 +204,7 @@ def get_request_tenant(request, slug, sub_id):


def get_request_secret(request, slug, sub_id):
(slug, sub_id) = get_slug(request, slug, sub_id)
slug, sub_id = get_slug(request, slug, sub_id)
if not slug:
return None

Expand Down
4 changes: 2 additions & 2 deletions b3lb/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def stats(request, slug=None, sub_id=0):
auth_token = request.headers.get('Authorization')
tenant = lb.get_request_tenant(request, slug, sub_id)

if auth_token and tenant and auth_token == tenant.stats_token:
if auth_token and tenant and auth_token == str(tenant.stats_token):
return HttpResponse(ep.tenant_stats(tenant), content_type='application/json')
else:
return HttpResponse("Unauthorized", status=401)
Expand All @@ -107,7 +107,7 @@ def metrics(request, slug=None, sub_id=0):

if forwarded_host == settings.B3LB_API_BASE_DOMAIN and slug is None:
return HttpResponse(SecretMetricsList.objects.get(secret=None).metrics, content_type='text/plain')
elif auth_token and secret and auth_token == secret.tenant.stats_token:
elif auth_token and secret and auth_token == str(secret.tenant.stats_token):
return HttpResponse(SecretMetricsList.objects.get(secret=secret).metrics, content_type='text/plain')
else:
return HttpResponse("Unauthorized", status=401)
Expand Down

0 comments on commit ece5b30

Please sign in to comment.