Skip to content
Open
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
3 changes: 2 additions & 1 deletion kubernetes/aio/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ async def get_api_key_with_prefix(self, identifier, alias=None):
await result
key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
if key:
prefix = self.api_key_prefix.get(identifier)
prefix = self.api_key_prefix.get(
identifier, self.api_key_prefix.get(alias) if alias is not None else None)
if prefix:
Comment on lines 389 to 393
return "%s %s" % (prefix, key)
else:
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def get_api_key_with_prefix(self, identifier, alias=None):
self.refresh_api_key_hook(self)
key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
if key:
prefix = self.api_key_prefix.get(identifier)
prefix = self.api_key_prefix.get(
identifier, self.api_key_prefix.get(alias) if alias is not None else None)
if prefix:
return "%s %s" % (prefix, key)
else:
Expand Down
11 changes: 11 additions & 0 deletions kubernetes/test/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ def test_auth_settings_with_no_token(self):
"""No api_key entry yields an empty auth dict."""
config = Configuration()
self.assertEqual(config.auth_settings(), {})

def test_auth_settings_with_authorization_key_and_prefix(self):
"""Legacy callers that split the token and prefix across
api_key['authorization'] and api_key_prefix['authorization'] (rather
than embedding "Bearer " in the token itself) must still get the
prefix applied. https://github.com/kubernetes-client/python/issues/2592
"""
config = Configuration()
config.api_key['authorization'] = 'abc123'
config.api_key_prefix['authorization'] = 'Bearer'
self.assertEqual(self._bearer_value(config), 'Bearer abc123')