Skip to content

Commit 5fb6900

Browse files
committed
Adding a setting to disable auth for POSTing to the tresults resources
1 parent 10aed85 commit 5fb6900

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

codespeed/auth.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@
22
from functools import wraps
33
from django.contrib.auth import authenticate
44
from django.http import HttpResponse, HttpResponseForbidden
5+
from django.conf import settings
56
from base64 import b64decode
67

78

89
def basic_auth_required(realm='default'):
910
def _helper(func):
1011
@wraps(func)
1112
def _decorator(request, *args, **kwargs):
12-
if 'HTTP_AUTHORIZATION' in request.META:
13+
allowed = False
14+
if settings.ALLOW_ANONYMOUS_POST:
15+
allowed = True
16+
elif 'HTTP_AUTHORIZATION' in request.META:
1317
http_auth = request.META['HTTP_AUTHORIZATION']
1418
authmeth, auth = http_auth.split(' ', 1)
1519
if authmeth.lower() == 'basic':
1620
authb = b64decode(auth.strip())
1721
auth = authb.decode()
1822
username, password = auth.split(':', 1)
1923
user = authenticate(username=username, password=password)
20-
if user is not None:
24+
if user is None:
2125
logging.info(
2226
'Authentication succeeded for {}'.format(username))
23-
return func(request, *args, **kwargs)
27+
allowed = True
2428
else:
2529
return HttpResponseForbidden()
30+
if allowed:
31+
return func(request, *args, **kwargs)
2632
res = HttpResponse()
2733
res.status_code = 401
2834
res.reason_phrase = 'Unauthorized'

codespeed/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@
6868
# ('myexe', 'L'),]
6969

7070
USE_MEDIAN_BANDS = True # True to enable median bands on Timeline view
71+
72+
73+
ALLOW_ANONYMOUS_POST = False # Whether anonymous users be allowed to post results

0 commit comments

Comments
 (0)