From 22f0a4b79aeb8f6eca1bedb16febd2e3316a3afd Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 1 Oct 2015 13:59:45 -0400 Subject: [PATCH] allow token in get params at stdout endpoint --- awx/api/authentication.py | 11 +++++++++++ awx/api/views.py | 3 ++- awx/main/models/organization.py | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/awx/api/authentication.py b/awx/api/authentication.py index e916ee3831..a40d546b3a 100644 --- a/awx/api/authentication.py +++ b/awx/api/authentication.py @@ -90,6 +90,17 @@ class TokenAuthentication(authentication.TokenAuthentication): # Return the user object and the token. return (token.user, token) + +class TokenGetAuthentication(TokenAuthentication): + + def authenticate(self, request): + if request.method.lower() == 'get': + token = request.GET.get('token', None) + if token: + request.META['HTTP_X_AUTH_TOKEN'] = 'Token %s' % token + return super(TokenGetAuthentication, self).authenticate(request) + + class TaskAuthentication(authentication.BaseAuthentication): ''' Custom authentication used for views accessed by the inventory and callback diff --git a/awx/api/views.py b/awx/api/views.py index 79489c2454..71f25e0d94 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -52,7 +52,7 @@ from awx.main.task_engine import TaskSerializer, TASK_FILE, TEMPORARY_TASK_FILE from awx.main.tasks import mongodb_control from awx.main.access import get_user_queryset from awx.main.ha import is_ha_environment -from awx.api.authentication import TaskAuthentication +from awx.api.authentication import TaskAuthentication, TokenGetAuthentication from awx.api.utils.decorators import paginated from awx.api.filters import MongoFilterBackend from awx.api.generics import get_view_name @@ -2805,6 +2805,7 @@ class UnifiedJobList(ListAPIView): class UnifiedJobStdout(RetrieveAPIView): + authentication_classes = [TokenGetAuthentication] + api_settings.DEFAULT_AUTHENTICATION_CLASSES serializer_class = UnifiedJobStdoutSerializer renderer_classes = [BrowsableAPIRenderer, renderers.StaticHTMLRenderer, PlainTextRenderer, AnsiTextRenderer, diff --git a/awx/main/models/organization.py b/awx/main/models/organization.py index b72a1df45c..c68f2d8eba 100644 --- a/awx/main/models/organization.py +++ b/awx/main/models/organization.py @@ -209,7 +209,7 @@ class AuthToken(BaseModel): def reason_long(reason): for x in AuthToken.REASON_CHOICES: if x[0] == reason: - return x[1] + return unicode(x[1]) return None @classmethod