forked from dyninst/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding example upload with ddash results and log files
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
1,845 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ db.sqlite3 | |
test-db.sqlite | ||
dyninst_dashboard.egg-info/ | ||
migrations | ||
./data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from rest_framework.permissions import BasePermission, SAFE_METHODS | ||
from rest_framework.authtoken.models import Token | ||
|
||
|
||
class AllowAnyGet(BasePermission): | ||
"""Allows an anonymous user access for GET requests only.""" | ||
|
||
def has_permission(self, request, view): | ||
|
||
if request.user.is_anonymous and request.method == "GET": | ||
return (True,) | ||
|
||
if request.user.is_staff or request.user.is_superuser: | ||
return True | ||
|
||
return request.method in SAFE_METHODS | ||
|
||
|
||
def check_user_authentication(request): | ||
"""Given a request, check that the user is authenticated via a token in | ||
the header. | ||
""" | ||
token = get_token(request) | ||
|
||
# Case 1: no token and auth is required, prompt the user for it | ||
if not token: | ||
return None, 401 | ||
|
||
# Case 2: the token is not associated with a user | ||
try: | ||
token = Token.objects.get(key=token) | ||
except: | ||
return None, 403 | ||
|
||
return token.user, 200 | ||
|
||
|
||
def get_token(request): | ||
"""The same as validate_token, but return the token object to check the | ||
associated user. | ||
""" | ||
# Coming from HTTP, look for authorization as bearer token | ||
token = request.META.get("HTTP_AUTHORIZATION") | ||
|
||
if token: | ||
token = token.split(" ")[-1].strip() | ||
try: | ||
return Token.objects.get(key=token) | ||
except Token.DoesNotExist: | ||
pass | ||
|
||
# Next attempt - try to get token via user session | ||
elif request.user.is_authenticated and not request.user.is_anonymous: | ||
try: | ||
return Token.objects.get(user=request.user) | ||
except Token.DoesNotExist: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .auth import GetAuthToken | ||
from .base import ServiceInfo | ||
from .results import NewTestResult | ||
from .results import NewTestResult, upload_log | ||
from .tables import ResultsTable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.core.files.storage import FileSystemStorage | ||
from django.conf import settings | ||
import os | ||
|
||
|
||
class OverwriteStorage(FileSystemStorage): | ||
def get_available_name(self, name, max_length=None): | ||
# If the filename already exists, remove it as if it was a true file system | ||
if self.exists(name): | ||
os.remove(os.path.join(settings.MEDIA_ROOT, name)) | ||
return name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.