Skip to content

Commit 99fcfbc

Browse files
Qingping Houwing328
authored andcommitted
[Python] support api key refresh in configuration module (#3594)
1 parent a4811c7 commit 99fcfbc

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

modules/openapi-generator/src/main/resources/python/configuration.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
6161
self.api_key_prefix = api_key_prefix
6262
"""dict to store API prefix (e.g. Bearer)
6363
"""
64+
self.refresh_api_key_hook = None
65+
"""function hook to refresh API key if expired
66+
"""
6467
self.username = username
6568
"""Username for HTTP basic authentication
6669
"""
@@ -238,6 +241,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
238241
:param identifier: The identifier of apiKey.
239242
:return: The token for api key authentication.
240243
"""
244+
if self.refresh_api_key_hook is not None:
245+
self.refresh_api_key_hook(self)
241246
key = self.api_key.get(identifier)
242247
if key:
243248
prefix = self.api_key_prefix.get(identifier)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def __init__(self, host="http://petstore.swagger.io:80/v2",
6666
self.api_key_prefix = api_key_prefix
6767
"""dict to store API prefix (e.g. Bearer)
6868
"""
69+
self.refresh_api_key_hook = None
70+
"""function hook to refresh API key if expired
71+
"""
6972
self.username = username
7073
"""Username for HTTP basic authentication
7174
"""
@@ -223,6 +226,8 @@ def get_api_key_with_prefix(self, identifier):
223226
:param identifier: The identifier of apiKey.
224227
:return: The token for api key authentication.
225228
"""
229+
if self.refresh_api_key_hook is not None:
230+
self.refresh_api_key_hook(self)
226231
key = self.api_key.get(identifier)
227232
if key:
228233
prefix = self.api_key_prefix.get(identifier)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def __init__(self, host="http://petstore.swagger.io:80/v2",
6767
self.api_key_prefix = api_key_prefix
6868
"""dict to store API prefix (e.g. Bearer)
6969
"""
70+
self.refresh_api_key_hook = None
71+
"""function hook to refresh API key if expired
72+
"""
7073
self.username = username
7174
"""Username for HTTP basic authentication
7275
"""
@@ -227,6 +230,8 @@ def get_api_key_with_prefix(self, identifier):
227230
:param identifier: The identifier of apiKey.
228231
:return: The token for api key authentication.
229232
"""
233+
if self.refresh_api_key_hook is not None:
234+
self.refresh_api_key_hook(self)
230235
key = self.api_key.get(identifier)
231236
if key:
232237
prefix = self.api_key_prefix.get(identifier)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def __init__(self, host="http://petstore.swagger.io:80/v2",
6767
self.api_key_prefix = api_key_prefix
6868
"""dict to store API prefix (e.g. Bearer)
6969
"""
70+
self.refresh_api_key_hook = None
71+
"""function hook to refresh API key if expired
72+
"""
7073
self.username = username
7174
"""Username for HTTP basic authentication
7275
"""
@@ -227,6 +230,8 @@ def get_api_key_with_prefix(self, identifier):
227230
:param identifier: The identifier of apiKey.
228231
:return: The token for api key authentication.
229232
"""
233+
if self.refresh_api_key_hook is not None:
234+
self.refresh_api_key_hook(self)
230235
key = self.api_key.get(identifier)
231236
if key:
232237
prefix = self.api_key_prefix.get(identifier)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def __init__(self, host="http://petstore.swagger.io:80/v2",
6767
self.api_key_prefix = api_key_prefix
6868
"""dict to store API prefix (e.g. Bearer)
6969
"""
70+
self.refresh_api_key_hook = None
71+
"""function hook to refresh API key if expired
72+
"""
7073
self.username = username
7174
"""Username for HTTP basic authentication
7275
"""
@@ -227,6 +230,8 @@ def get_api_key_with_prefix(self, identifier):
227230
:param identifier: The identifier of apiKey.
228231
:return: The token for api key authentication.
229232
"""
233+
if self.refresh_api_key_hook is not None:
234+
self.refresh_api_key_hook(self)
230235
key = self.api_key.get(identifier)
231236
if key:
232237
prefix = self.api_key_prefix.get(identifier)

0 commit comments

Comments
 (0)