@@ -60,18 +60,12 @@ def api_call_with_auth(self, *args, **kwargs):
60
60
def api_call_no_auth (self , method , path , payload = None , ** kwargs ):
61
61
return self .__api_request (method , path , payload = payload , add_auth = False , ** kwargs )
62
62
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 ()
66
66
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 ):
73
67
if add_auth :
74
- headers = self .add_auth ( headers )
68
+ headers [ 'Authorization' ] = f'Bearer { self .session_token } '
75
69
76
70
api_path = path
77
71
if version is not None :
@@ -109,7 +103,6 @@ def auth_renew_session(self):
109
103
110
104
def auth_create_session (self ):
111
105
self .__logger .debug ('Creating session token' )
112
- # Bypass api_call_with_auth to avoid getting in a 401 loop
113
106
r = self .api_call_no_auth ('POST' , 'auth' , payload = json .dumps ({'token' : self .api_token }))
114
107
115
108
if r .status_code != 200 :
@@ -123,6 +116,7 @@ def auth_create_session(self):
123
116
124
117
def auth_invalidate_session (self ):
125
118
self .__logger .debug ('Invalidating session token {}' .format (self .session_token ))
119
+ # Bypass api_call_with_auth to avoid getting in a 401 loop
126
120
r = self .__api_request ('DELETE' , 'auth' )
127
121
128
122
if r .status_code != 204 :
0 commit comments