Skip to content

Commit 6a9830b

Browse files
authored
Merge pull request #9624 from houqp/refresh
[Python] support api key refresh in configuration module
2 parents bdbc1f5 + fb07602 commit 6a9830b

File tree

7 files changed

+23
-3
lines changed

7 files changed

+23
-3
lines changed

modules/swagger-codegen/src/main/resources/python/configuration.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Configuration(object):
4040
self.api_key = {}
4141
# dict to store API prefix (e.g. Bearer)
4242
self.api_key_prefix = {}
43+
# function to refresh API key if expired
44+
self.refresh_api_key_hook = None
4345
# Username for HTTP basic authentication
4446
self.username = ""
4547
# Password for HTTP basic authentication
@@ -194,6 +196,9 @@ class Configuration(object):
194196
:param identifier: The identifier of apiKey.
195197
:return: The token for api key authentication.
196198
"""
199+
if self.refresh_api_key_hook:
200+
self.refresh_api_key_hook(self)
201+
197202
if (self.api_key.get(identifier) and
198203
self.api_key_prefix.get(identifier)):
199204
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.9-SNAPSHOT

samples/client/petstore/python-asyncio/petstore_api/configuration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(self):
4949
self.api_key = {}
5050
# dict to store API prefix (e.g. Bearer)
5151
self.api_key_prefix = {}
52+
# function to refresh API key if expired
53+
self.refresh_api_key_hook = None
5254
# Username for HTTP basic authentication
5355
self.username = ""
5456
# Password for HTTP basic authentication
@@ -203,6 +205,9 @@ def get_api_key_with_prefix(self, identifier):
203205
:param identifier: The identifier of apiKey.
204206
:return: The token for api key authentication.
205207
"""
208+
if self.refresh_api_key_hook:
209+
self.refresh_api_key_hook(self)
210+
206211
if (self.api_key.get(identifier) and
207212
self.api_key_prefix.get(identifier)):
208213
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.9-SNAPSHOT

samples/client/petstore/python-tornado/petstore_api/configuration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(self):
4949
self.api_key = {}
5050
# dict to store API prefix (e.g. Bearer)
5151
self.api_key_prefix = {}
52+
# function to refresh API key if expired
53+
self.refresh_api_key_hook = None
5254
# Username for HTTP basic authentication
5355
self.username = ""
5456
# Password for HTTP basic authentication
@@ -203,6 +205,9 @@ def get_api_key_with_prefix(self, identifier):
203205
:param identifier: The identifier of apiKey.
204206
:return: The token for api key authentication.
205207
"""
208+
if self.refresh_api_key_hook:
209+
self.refresh_api_key_hook(self)
210+
206211
if (self.api_key.get(identifier) and
207212
self.api_key_prefix.get(identifier)):
208213
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.9-SNAPSHOT

samples/client/petstore/python/petstore_api/configuration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(self):
4949
self.api_key = {}
5050
# dict to store API prefix (e.g. Bearer)
5151
self.api_key_prefix = {}
52+
# function to refresh API key if expired
53+
self.refresh_api_key_hook = None
5254
# Username for HTTP basic authentication
5355
self.username = ""
5456
# Password for HTTP basic authentication
@@ -203,6 +205,9 @@ def get_api_key_with_prefix(self, identifier):
203205
:param identifier: The identifier of apiKey.
204206
:return: The token for api key authentication.
205207
"""
208+
if self.refresh_api_key_hook:
209+
self.refresh_api_key_hook(self)
210+
206211
if (self.api_key.get(identifier) and
207212
self.api_key_prefix.get(identifier)):
208213
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501

0 commit comments

Comments
 (0)