Skip to content

Commit bbba8b1

Browse files
authored
Merge pull request #6 from gremlin/kh_api_key_fix
Kh api key fix
2 parents b0e74be + 19ba6db commit bbba8b1

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN python3 -m ensurepip && \
2323
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
2424
rm -r /root/.cache
2525

26-
RUN pip --no-cache-dir install --upgrade awscli boto3
26+
RUN pip --no-cache-dir install --upgrade awscli boto3 requests
2727

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

gremlinapi/config.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@
99

1010

1111
class GremlinAPIConfig(object):
12+
13+
def __init__(self):
14+
self._api_key = None
15+
self._base_uri = None
16+
self._bearer_timestamp = None
17+
self._bearer_token = None
18+
self._company_name = None
19+
self._max_bearer_interval = None
20+
self._password = None
21+
self._team_guid = None
22+
self._user = None
23+
self._user_mfa_token_value = None
24+
1225
@property
1326
def api_key(self):
14-
"""API Key for API authorization"""
27+
if not self._api_key:
28+
return None
1529
return self._api_key
1630

1731
@api_key.setter

gremlinapi/http_clients.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ def api_call(cls, method, uri, *args, **kwargs):
3333

3434
@classmethod
3535
def header(cls, *args, **kwargs):
36-
api_key = kwargs.get('api_key', GremlinAPIConfig.api_key)
37-
bearer_token = kwargs.get('bearer_token', GremlinAPIConfig.bearer_token)
36+
api_key = kwargs.get('api_key', None)
37+
bearer_token = kwargs.get('bearer_token', None)
3838
header = dict()
39+
if not (api_key and bearer_token):
40+
if GremlinAPIConfig.bearer_token:
41+
bearer_token = GremlinAPIConfig.bearer_token
42+
if GremlinAPIConfig.api_key:
43+
api_key = GremlinAPIConfig.api_key
3944
if api_key and not bearer_token:
40-
header['Authorization'] = 'Key {api_key}'
41-
if bearer_token:
45+
if "Key" in api_key:
46+
header['Authorization'] = api_key
47+
else:
48+
header['Authorization'] = f'Key {api_key}'
49+
elif bearer_token:
4250
if "Bearer" in bearer_token:
4351
header['Authorization'] = bearer_token
4452
else:
@@ -100,7 +108,7 @@ def api_call(cls, method, endpoint, *args, **kwargs):
100108
class GremlinAPIurllibClient(GremlinAPIHttpClient):
101109
@classmethod
102110
def api_call(cls, method, uri, *args, **kwargs):
103-
error_message = f'This function is not yet implemented'
111+
error_message = f'URLlib client not yet implemented, please install requests library'
104112
log.fatal(error_message)
105113
raise NotImplementedError(error_message)
106114

0 commit comments

Comments
 (0)