Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gabriel Silva Vinha
codespeed
Commits
10aed851
Commit
10aed851
authored
Feb 26, 2017
by
Mark Watts
Browse files
Added http basic authentication to results resources
parent
ad9ede13
Changes
2
Hide whitespace changes
Inline
Side-by-side
codespeed/auth.py
0 → 100644
View file @
10aed851
import
logging
from
functools
import
wraps
from
django.contrib.auth
import
authenticate
from
django.http
import
HttpResponse
,
HttpResponseForbidden
from
base64
import
b64decode
def
basic_auth_required
(
realm
=
'default'
):
def
_helper
(
func
):
@
wraps
(
func
)
def
_decorator
(
request
,
*
args
,
**
kwargs
):
if
'HTTP_AUTHORIZATION'
in
request
.
META
:
http_auth
=
request
.
META
[
'HTTP_AUTHORIZATION'
]
authmeth
,
auth
=
http_auth
.
split
(
' '
,
1
)
if
authmeth
.
lower
()
==
'basic'
:
authb
=
b64decode
(
auth
.
strip
())
auth
=
authb
.
decode
()
username
,
password
=
auth
.
split
(
':'
,
1
)
user
=
authenticate
(
username
=
username
,
password
=
password
)
if
user
is
not
None
:
logging
.
info
(
'Authentication succeeded for {}'
.
format
(
username
))
return
func
(
request
,
*
args
,
**
kwargs
)
else
:
return
HttpResponseForbidden
()
res
=
HttpResponse
()
res
.
status_code
=
401
res
.
reason_phrase
=
'Unauthorized'
res
[
'WWW-Authenticate'
]
=
'Basic realm="{}"'
.
format
(
realm
)
return
res
return
_decorator
return
_helper
codespeed/views.py
View file @
10aed851
...
...
@@ -14,6 +14,7 @@ from django.views.decorators.http import require_GET, require_POST
from
django.views.decorators.csrf
import
csrf_exempt
from
django.template
import
RequestContext
from
django.conf
import
settings
from
.auth
import
basic_auth_required
from
.models
import
(
Environment
,
Report
,
Project
,
Revision
,
Result
,
Executable
,
Benchmark
,
Branch
)
...
...
@@ -697,6 +698,7 @@ def displaylogs(request):
@
csrf_exempt
@
require_POST
@
basic_auth_required
(
'results'
)
def
add_result
(
request
):
response
,
error
=
save_result
(
request
.
POST
)
if
error
:
...
...
@@ -710,6 +712,7 @@ def add_result(request):
@
csrf_exempt
@
require_POST
@
basic_auth_required
(
'results'
)
def
add_json_results
(
request
):
if
not
request
.
POST
.
get
(
'json'
):
return
HttpResponseBadRequest
(
"No key 'json' in POST payload"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment