Skip to content

Commit

Permalink
Bugfix for the client
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Jun 5, 2020
1 parent 9cd88b1 commit 5c6b2e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os

# must be here for adsmutils to override it using env vars
# but if left empty (resolving to False) it won't be used
SERVICE_TOKEN = None

LOG_STDOUT = True

VIS_SERVICE_BIGQUERY_PATH = 'http://ecs-staging-elb-2044121877.us-east-1.elb.amazonaws.com/v1/search/bigquery'
Expand Down
9 changes: 5 additions & 4 deletions vis_services/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ def __init__(self, config):

self.session = requests.Session()

def _sanitize(self, *args, **kwargs):
def _sanitize(self, args, kwargs):
headers = kwargs.get('headers', {})
if 'Authorization' not in headers:
headers['Authorization'] = current_app.config.get('SERVICE_TOKEN', request.headers.get('X-Forwarded-Authorization', request.headers.get('Authorization', None)))
headers['Authorization'] = current_app.config.get('SERVICE_TOKEN', None) or request.headers.get('X-Forwarded-Authorization', request.headers.get('Authorization', None))
kwargs['headers'] = headers
return (args, kwargs)

def get(self, *args, **kwargs):
self._sanitize(*args, **kwargs)
args, kwargs = self._sanitize(args, kwargs)
return self.session.get(*args, **kwargs)

def post(self, *args, **kwargs):
self._sanitize(*args, **kwargs)
args, kwargs = self._sanitize(args, kwargs)
return self.session.post(*args, **kwargs)

0 comments on commit 5c6b2e4

Please sign in to comment.