Skip to content

Commit

Permalink
Merge pull request #6 from gremlin/kh_api_key_fix
Browse files Browse the repository at this point in the history
Kh api key fix
  • Loading branch information
khultman authored Mar 20, 2020
2 parents b0e74be + 19ba6db commit bbba8b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN python3 -m ensurepip && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache

RUN pip --no-cache-dir install --upgrade awscli boto3
RUN pip --no-cache-dir install --upgrade awscli boto3 requests

RUN curl -s -L $AWS_IAMAUTH_DOWNLOAD -o /usr/local/bin/aws-iam-authenticator && chmod 755 /usr/local/bin/aws-iam-authenticator

Expand Down
16 changes: 15 additions & 1 deletion gremlinapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@


class GremlinAPIConfig(object):

def __init__(self):
self._api_key = None
self._base_uri = None
self._bearer_timestamp = None
self._bearer_token = None
self._company_name = None
self._max_bearer_interval = None
self._password = None
self._team_guid = None
self._user = None
self._user_mfa_token_value = None

@property
def api_key(self):
"""API Key for API authorization"""
if not self._api_key:
return None
return self._api_key

@api_key.setter
Expand Down
18 changes: 13 additions & 5 deletions gremlinapi/http_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ def api_call(cls, method, uri, *args, **kwargs):

@classmethod
def header(cls, *args, **kwargs):
api_key = kwargs.get('api_key', GremlinAPIConfig.api_key)
bearer_token = kwargs.get('bearer_token', GremlinAPIConfig.bearer_token)
api_key = kwargs.get('api_key', None)
bearer_token = kwargs.get('bearer_token', None)
header = dict()
if not (api_key and bearer_token):
if GremlinAPIConfig.bearer_token:
bearer_token = GremlinAPIConfig.bearer_token
if GremlinAPIConfig.api_key:
api_key = GremlinAPIConfig.api_key
if api_key and not bearer_token:
header['Authorization'] = 'Key {api_key}'
if bearer_token:
if "Key" in api_key:
header['Authorization'] = api_key
else:
header['Authorization'] = f'Key {api_key}'
elif bearer_token:
if "Bearer" in bearer_token:
header['Authorization'] = bearer_token
else:
Expand Down Expand Up @@ -100,7 +108,7 @@ def api_call(cls, method, endpoint, *args, **kwargs):
class GremlinAPIurllibClient(GremlinAPIHttpClient):
@classmethod
def api_call(cls, method, uri, *args, **kwargs):
error_message = f'This function is not yet implemented'
error_message = f'URLlib client not yet implemented, please install requests library'
log.fatal(error_message)
raise NotImplementedError(error_message)

Expand Down

0 comments on commit bbba8b1

Please sign in to comment.