Skip to content

Commit f0ba19b

Browse files
committed
more feedback more changes
1 parent 7e69a1f commit f0ba19b

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

evasdk/eva_http_client.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,12 @@ def api_call_with_auth(self, *args, **kwargs):
6060
def api_call_no_auth(self, method, path, payload=None, **kwargs):
6161
return self.__api_request(method, path, payload=payload, add_auth=False, **kwargs)
6262

63-
def add_auth(self, headers):
64-
if not headers:
65-
headers = {'Authorization': 'Bearer {}'.format(self.session_token)}
63+
def __api_request(self, method, path, payload=None, headers={}, timeout=None, version='v1', add_auth=True):
64+
if headers:
65+
headers = headers.copy()
6666

67-
if 'Authorization' not in headers.keys():
68-
headers.update({'Authorization': 'Bearer {}'.format(self.session_token)})
69-
70-
return headers
71-
72-
def __api_request(self, method, path, payload=None, headers=None, timeout=None, version='v1', add_auth=True):
7367
if add_auth:
74-
headers = self.add_auth(headers)
68+
headers['Authorization'] = f'Bearer {self.session_token}'
7569

7670
api_path = path
7771
if version is not None:
@@ -109,7 +103,6 @@ def auth_renew_session(self):
109103

110104
def auth_create_session(self):
111105
self.__logger.debug('Creating session token')
112-
# Bypass api_call_with_auth to avoid getting in a 401 loop
113106
r = self.api_call_no_auth('POST', 'auth', payload=json.dumps({'token': self.api_token}))
114107

115108
if r.status_code != 200:
@@ -123,6 +116,7 @@ def auth_create_session(self):
123116

124117
def auth_invalidate_session(self):
125118
self.__logger.debug('Invalidating session token {}'.format(self.session_token))
119+
# Bypass api_call_with_auth to avoid getting in a 401 loop
126120
r = self.__api_request('DELETE', 'auth')
127121

128122
if r.status_code != 204:

0 commit comments

Comments
 (0)