Skip to content

Commit

Permalink
[fix] passing Bearer token in authorization header (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomplus authored Mar 22, 2022
1 parent f5771e0 commit 0818287
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kubernetes_asyncio/config/incluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions kubernetes_asyncio/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions kubernetes_asyncio/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0818287

Please sign in to comment.