[Python] support api key refresh in configuration module (#3594)

This commit is contained in:
Qingping Hou
2019-08-15 07:06:36 -07:00
committed by William Cheng
parent a4811c7850
commit 99fcfbc802
5 changed files with 25 additions and 0 deletions

View File

@@ -67,6 +67,9 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.api_key_prefix = api_key_prefix
"""dict to store API prefix (e.g. Bearer)
"""
self.refresh_api_key_hook = None
"""function hook to refresh API key if expired
"""
self.username = username
"""Username for HTTP basic authentication
"""
@@ -227,6 +230,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
:param identifier: The identifier of apiKey.
:return: The token for api key authentication.
"""
if self.refresh_api_key_hook is not None:
self.refresh_api_key_hook(self)
key = self.api_key.get(identifier)
if key:
prefix = self.api_key_prefix.get(identifier)