@@ -32,7 +32,8 @@ def __init__(self, access_token=None, auth_base_url=None, cache_token=True,
32
32
client_id = None , client_secret = None , instance_id = None ,
33
33
profile = None , redirect_uri = None , region = None ,
34
34
refresh_token = None , scope = None , storage_adapter = None ,
35
- token_url = None , token_revoke_url = None , ** kwargs ):
35
+ storage_params = None , token_url = None , token_revoke_url = None ,
36
+ ** kwargs ):
36
37
"""Persist Session() and credentials attributes.
37
38
38
39
Built on top of the ``Requests`` library, ``Credentials``
@@ -59,6 +60,7 @@ def __init__(self, access_token=None, auth_base_url=None, cache_token=True,
59
60
region (str): Region. Defaults to ``None``.
60
61
refresh_token (str): OAuth2 refresh token. Defaults to ``None``.
61
62
scope (str): OAuth2 scope. Defaults to ``None``.
63
+ storage_params (dict) = Storage adapter parameters. Defaults to ``None``.
62
64
token_url (str): Refresh URL. Defaults to ``None``.
63
65
token_revoke_url (str): Revoke URL. Defaults to ``None``.
64
66
**kwargs: Supported :class:`~requests.Session` parameters.
@@ -78,7 +80,7 @@ def __init__(self, access_token=None, auth_base_url=None, cache_token=True,
78
80
self .state = uuid .uuid4 ()
79
81
self .adapter = storage_adapter or \
80
82
'pancloud.adapters.tinydb_adapter.TinyDBStore'
81
- self .storage = self ._init_adapter ()
83
+ self .storage = self ._init_adapter (storage_params )
82
84
self .token_lock = Lock ()
83
85
self .token_url = token_url or TOKEN_URL
84
86
self .token_revoke_url = token_revoke_url or REVOKE_URL
@@ -149,7 +151,7 @@ def _credentials_found_in_envars():
149
151
os .getenv ('PAN_CLIENT_SECRET' ),
150
152
os .getenv ('PAN_REFRESH_TOKEN' )])
151
153
152
- def _init_adapter (self ):
154
+ def _init_adapter (self , storage_params = None ):
153
155
module_path = self .adapter .rsplit ('.' , 1 )[0 ]
154
156
adapter = self .adapter .split ('.' )[- 1 ]
155
157
try :
@@ -163,7 +165,7 @@ def _init_adapter(self):
163
165
except AttributeError :
164
166
raise PanCloudError ('Class not found: %s' % adapter )
165
167
166
- return class_ # Returns 'TinyDBStore' as class
168
+ return class_ ( storage_params = storage_params )
167
169
168
170
def _resolve_credential (self , credential ):
169
171
"""Resolve credential from envars or credentials store.
@@ -180,7 +182,7 @@ def _resolve_credential(self, credential):
180
182
elif self ._credentials_found_in_envars ():
181
183
return os .getenv ('PAN_' + credential .upper ())
182
184
else :
183
- return self .storage () .fetch_credential (
185
+ return self .storage .fetch_credential (
184
186
credential = credential , profile = self .profile )
185
187
186
188
def fetch_tokens (self , client_id = None , client_secret = None , code = None ,
@@ -289,7 +291,7 @@ def remove_profile(self, profile):
289
291
int: Result of operation.
290
292
291
293
"""
292
- return self .storage () .remove_profile (profile = profile )
294
+ return self .storage .remove_profile (profile = profile )
293
295
294
296
def refresh (self , timeout = None , access_token = None ):
295
297
"""Refresh access and refresh tokens.
@@ -391,7 +393,7 @@ def write_credentials(self):
391
393
392
394
"""
393
395
c = self .get_credentials ()
394
- return self .storage () .write_credentials (
396
+ return self .storage .write_credentials (
395
397
credentials = c , profile = self .profile ,
396
398
cache_token = self .cache_token_
397
399
)
0 commit comments