Skip to content

Commit

Permalink
User bearer token for Rodimus
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwowen committed Jun 16, 2023
1 parent c8b8032 commit bfca0ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion deploy-board/deploy_board/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
RODIMUS_SERVICE_VERSION = os.getenv("RODIMUS_SERVICE_VERSION", None)
RODIMUS_SERVICE_PROXY_HTTP = os.getenv("RODIMUS_SERVICE_PROXY_HTTP", None)
RODIMUS_SERVICE_PROXY_HTTPS = os.getenv("RODIMUS_SERVICE_PROXY_HTTPS", None)
RODIMUS_SERVICE_USE_BEARER = os.getenv("RODIMUS_SERVICE_USE_BEARER", True)

if IS_PINTEREST:
# use knox if present
Expand Down Expand Up @@ -366,5 +367,5 @@

DEFAULT_CLUSTER_TYPE = "PRODUCTION"

#Auto AMI Update
#Auto AMI Update
ENABLE_AMI_AUTO_UPDATE = 1
10 changes: 6 additions & 4 deletions deploy-board/deploy_board/webapp/helpers/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@


class BaseClient(object):
def __init__(self, url_prefix, version, proxy_http=None, proxy_https=None):
def __init__(self, url_prefix, version, proxy_http=None, proxy_https=None, bearer=False):
self.url_prefix = url_prefix
self.url_version = version
self.proxies = dict()
self.bearer = bearer
if proxy_http:
self.proxies['http'] = proxy_http
if proxy_https:
Expand All @@ -38,8 +39,9 @@ def __call(self, method):
def api(path, token=None, params=None, data=None):
url = '%s/%s%s' % (self.url_prefix, self.url_version, path)
headers = {'Content-type': 'application/json'}

if token:
headers['Authorization'] = 'token %s' % token
headers['Authorization'] = 'bearer %s' % token if self.bearer else 'token %s' % token

response = getattr(requests, method)(url, proxies=self.proxies, headers=headers, params=params, json=data,
timeout=DEFAULT_TIMEOUT, verify=False)
Expand All @@ -61,11 +63,11 @@ def api(path, token=None, params=None, data=None):
raise NotAuthorizedException(
"Oops! You do not have the required permissions for this action. Contact an environment ADMIN for "
"assistance. " + response.content)

if response.status_code == 400:
raise IllegalArgumentException(
"Oops! It seems like Teletraan sent an illegal request. " + response.content)

if response.status_code == 404:
log.info("Resource %s Not found" % path)
return None
Expand Down
5 changes: 3 additions & 2 deletions deploy-board/deploy_board/webapp/helpers/rodimus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
import logging
from decorators import singleton
from deploy_board.settings import RODIMUS_SERVICE_URL, RODIMUS_SERVICE_VERSION, RODIMUS_SERVICE_PROXY_HTTP, RODIMUS_SERVICE_PROXY_HTTPS
from deploy_board.settings import RODIMUS_SERVICE_URL, RODIMUS_SERVICE_VERSION, RODIMUS_SERVICE_PROXY_HTTP, RODIMUS_SERVICE_PROXY_HTTPS, RODIMUS_SERVICE_USE_BEARER
from base_client import BaseClient


Expand All @@ -25,4 +25,5 @@
@singleton
class RodimusClient(BaseClient):
def __init__(self):
BaseClient.__init__(self, url_prefix=RODIMUS_SERVICE_URL, version=RODIMUS_SERVICE_VERSION, proxy_http=RODIMUS_SERVICE_PROXY_HTTP, proxy_https=RODIMUS_SERVICE_PROXY_HTTPS)
BaseClient.__init__(self, url_prefix=RODIMUS_SERVICE_URL, version=RODIMUS_SERVICE_VERSION,
proxy_http=RODIMUS_SERVICE_PROXY_HTTP, proxy_https=RODIMUS_SERVICE_PROXY_HTTPS, bearer=RODIMUS_SERVICE_USE_BEARER)

0 comments on commit bfca0ab

Please sign in to comment.