Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

added support for api key refresh in configuration module #567

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/resources/handlebars/python/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.api_key = {}
# dict to store API prefix (e.g. Bearer)
self.api_key_prefix = {}
# function to refresh API key if expired
self.refresh_api_key_hook = None
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
Expand Down Expand Up @@ -197,11 +199,16 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
:param identifier: The identifier of apiKey.
:return: The token for api key authentication.
"""
if (self.api_key.get(identifier) and
self.api_key_prefix.get(identifier)):
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
elif self.api_key.get(identifier):
return self.api_key[identifier]
if self.refresh_api_key_hook:
self.refresh_api_key_hook(self)

key = self.api_key.get(identifier)
if key:
prefix = self.api_key_prefix.get(identifier)
if prefix:
return "%s %s" % (prefix, key)
else:
return key

def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).
Expand Down
17 changes: 12 additions & 5 deletions src/main/resources/mustache/python/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.api_key = {}
# dict to store API prefix (e.g. Bearer)
self.api_key_prefix = {}
# function to refresh API key if expired
self.refresh_api_key_hook = None
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
Expand Down Expand Up @@ -197,11 +199,16 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
:param identifier: The identifier of apiKey.
:return: The token for api key authentication.
"""
if (self.api_key.get(identifier) and
self.api_key_prefix.get(identifier)):
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
elif self.api_key.get(identifier):
return self.api_key[identifier]
if self.refresh_api_key_hook:
self.refresh_api_key_hook(self)

key = self.api_key.get(identifier)
if key:
prefix = self.api_key_prefix.get(identifier)
if prefix:
return "%s %s" % (prefix, key)
else:
return key

def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).
Expand Down