Skip to content

Commit 4785aa5

Browse files
rolf-mozPhroZenOne
authored andcommitted
Minor auth changes to support OpenAPI generator 7.x and above
1 parent 15170d4 commit 4785aa5

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

examples/remote_cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main():
4242
# ssl_ca_cert is the filepath to the file that contains the certificate.
4343
# configuration.ssl_ca_cert="certificate"
4444

45-
aConfiguration.api_key = {"authorization": "Bearer " + aToken}
45+
aConfiguration.api_key = {"BearerToken": "Bearer " + aToken}
4646

4747
# Create a ApiClient with our config
4848
aApiClient = client.ApiClient(aConfiguration)

kubernetes/base/config/kube_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _load_cluster_info(self):
574574

575575
def _set_config(self, client_configuration):
576576
if 'token' in self.__dict__:
577-
client_configuration.api_key['authorization'] = self.token
577+
client_configuration.api_key['BearerToken'] = self.token
578578

579579
def _refresh_api_key(client_configuration):
580580
if ('expiry' in self.__dict__ and _is_expired(self.expiry)):

kubernetes/base/config/kube_config_test.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ def test_user_exec_auth(self, mock):
14681468
"token": token
14691469
}
14701470
expected = FakeConfig(host=TEST_HOST, api_key={
1471-
"authorization": BEARER_TOKEN_FORMAT % token})
1471+
"BearerToken": BEARER_TOKEN_FORMAT % token})
14721472
actual = FakeConfig()
14731473
KubeConfigLoader(
14741474
config_dict=self.TEST_KUBE_CONFIG,
@@ -1498,13 +1498,13 @@ def test_user_exec_auth_with_expiry(self, mock):
14981498
active_context="exec_cred_user").load_and_set(fake_config)
14991499
# The kube config should use the first token returned from the
15001500
# exec provider.
1501-
self.assertEqual(fake_config.api_key["authorization"],
1501+
self.assertEqual(fake_config.api_key["BearerToken"],
15021502
BEARER_TOKEN_FORMAT % expired_token)
15031503
# Should now be populated with a method to refresh expired tokens.
15041504
self.assertIsNotNone(fake_config.refresh_api_key_hook)
15051505
# Refresh the token; the kube config should be updated.
15061506
fake_config.refresh_api_key_hook(fake_config)
1507-
self.assertEqual(fake_config.api_key["authorization"],
1507+
self.assertEqual(fake_config.api_key["BearerToken"],
15081508
BEARER_TOKEN_FORMAT % current_token)
15091509

15101510
@mock.patch('kubernetes.config.kube_config.ExecProvider.run')
@@ -1546,7 +1546,7 @@ def test_user_cmd_path(self):
15461546
return_value = A(token, parse_rfc3339(datetime.datetime.now()))
15471547
CommandTokenSource.token = mock.Mock(return_value=return_value)
15481548
expected = FakeConfig(api_key={
1549-
"authorization": BEARER_TOKEN_FORMAT % token})
1549+
"BearerToken": BEARER_TOKEN_FORMAT % token})
15501550
actual = FakeConfig()
15511551
KubeConfigLoader(
15521552
config_dict=self.TEST_KUBE_CONFIG,
@@ -1559,7 +1559,7 @@ def test_user_cmd_path_empty(self):
15591559
return_value = A(token, parse_rfc3339(datetime.datetime.now()))
15601560
CommandTokenSource.token = mock.Mock(return_value=return_value)
15611561
expected = FakeConfig(api_key={
1562-
"authorization": BEARER_TOKEN_FORMAT % token})
1562+
"BearerToken": BEARER_TOKEN_FORMAT % token})
15631563
actual = FakeConfig()
15641564
self.expect_exception(lambda: KubeConfigLoader(
15651565
config_dict=self.TEST_KUBE_CONFIG,
@@ -1573,7 +1573,7 @@ def test_user_cmd_path_with_scope(self):
15731573
return_value = A(token, parse_rfc3339(datetime.datetime.now()))
15741574
CommandTokenSource.token = mock.Mock(return_value=return_value)
15751575
expected = FakeConfig(api_key={
1576-
"authorization": BEARER_TOKEN_FORMAT % token})
1576+
"BearerToken": BEARER_TOKEN_FORMAT % token})
15771577
actual = FakeConfig()
15781578
self.expect_exception(lambda: KubeConfigLoader(
15791579
config_dict=self.TEST_KUBE_CONFIG,

0 commit comments

Comments
 (0)