From 081828719be3ef4ccf224c6ff0362098df21daed Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 23 Mar 2022 00:07:04 +0100 Subject: [PATCH] [fix] passing Bearer token in authorization header (#190) --- kubernetes_asyncio/config/incluster_config.py | 2 +- kubernetes_asyncio/config/kube_config.py | 4 ++-- kubernetes_asyncio/config/kube_config_test.py | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/kubernetes_asyncio/config/incluster_config.py b/kubernetes_asyncio/config/incluster_config.py index 83d8f860a..0542257ff 100644 --- a/kubernetes_asyncio/config/incluster_config.py +++ b/kubernetes_asyncio/config/incluster_config.py @@ -80,7 +80,7 @@ def _set_config(self): configuration = Configuration() configuration.host = self.host configuration.ssl_ca_cert = self.ssl_ca_cert - configuration.api_key['authorization'] = "bearer " + self.token + configuration.api_key['BearerToken'] = "Bearer " + self.token Configuration.set_default(configuration) diff --git a/kubernetes_asyncio/config/kube_config.py b/kubernetes_asyncio/config/kube_config.py index 8942b297b..b3e735fdc 100644 --- a/kubernetes_asyncio/config/kube_config.py +++ b/kubernetes_asyncio/config/kube_config.py @@ -367,7 +367,7 @@ def _load_cluster_info(self): def _set_config(self, client_configuration): if 'token' in self.__dict__: - client_configuration.api_key['authorization'] = self.token + client_configuration.api_key['BearerToken'] = self.token # copy these keys directly from self to configuration object keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl'] @@ -626,7 +626,7 @@ async def refresh_token(loader, client_configuration=None, interval=60): while 1: await asyncio.sleep(interval) await loader.load_gcp_token() - client_configuration.api_key['authorization'] = loader.token + client_configuration.api_key['BearerToken'] = loader.token async def new_client_from_config(config_file=None, context=None, persist_config=True, diff --git a/kubernetes_asyncio/config/kube_config_test.py b/kubernetes_asyncio/config/kube_config_test.py index 10f0aab1c..1f18386b8 100644 --- a/kubernetes_asyncio/config/kube_config_test.py +++ b/kubernetes_asyncio/config/kube_config_test.py @@ -284,7 +284,7 @@ class FakeConfig: def __init__(self, token=None, **kwargs): self.api_key = {} if token: - self.api_key['authorization'] = token + self.api_key['BearerToken'] = token self.__dict__.update(kwargs) @@ -735,7 +735,7 @@ async def test_user_exec_auth(self, mock): "token": token } expected = FakeConfig(host=TEST_HOST, api_key={ - "authorization": BEARER_TOKEN_FORMAT % token}) + "BearerToken": BEARER_TOKEN_FORMAT % token}) actual = FakeConfig() await KubeConfigLoader( config_dict=self.TEST_KUBE_CONFIG, @@ -904,14 +904,14 @@ async def test_new_client_from_config(self): config_file=config_file, context="simple_token") self.assertEqual(TEST_HOST, client.configuration.host) self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64, - client.configuration.api_key['authorization']) + client.configuration.api_key['BearerToken']) async def test_new_client_from_config_dict(self): client = await new_client_from_config_dict( config_dict=self.TEST_KUBE_CONFIG, context="simple_token") self.assertEqual(TEST_HOST, client.configuration.host) self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64, - client.configuration.api_key['authorization']) + client.configuration.api_key['BearerToken']) async def test_no_users_section(self): expected = FakeConfig(host=TEST_HOST) @@ -1091,7 +1091,7 @@ async def test_new_client_from_config(self): config_file=kubeconfigs, context="simple_token") self.assertEqual(TEST_HOST, client.configuration.host) self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64, - client.configuration.api_key['authorization']) + client.configuration.api_key['BearerToken']) def test_save_changes(self): kubeconfigs = self._create_multi_config()