Skip to content

Commit c184309

Browse files
committed
Minor auth changes to support OpenAPI generator 7.x and above
1 parent 71bb5fa commit c184309

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
@@ -1469,7 +1469,7 @@ def test_user_exec_auth(self, mock):
14691469
"token": token
14701470
}
14711471
expected = FakeConfig(host=TEST_HOST, api_key={
1472-
"authorization": BEARER_TOKEN_FORMAT % token})
1472+
"BearerToken": BEARER_TOKEN_FORMAT % token})
14731473
actual = FakeConfig()
14741474
KubeConfigLoader(
14751475
config_dict=self.TEST_KUBE_CONFIG,
@@ -1499,13 +1499,13 @@ def test_user_exec_auth_with_expiry(self, mock):
14991499
active_context="exec_cred_user").load_and_set(fake_config)
15001500
# The kube config should use the first token returned from the
15011501
# exec provider.
1502-
self.assertEqual(fake_config.api_key["authorization"],
1502+
self.assertEqual(fake_config.api_key["BearerToken"],
15031503
BEARER_TOKEN_FORMAT % expired_token)
15041504
# Should now be populated with a method to refresh expired tokens.
15051505
self.assertIsNotNone(fake_config.refresh_api_key_hook)
15061506
# Refresh the token; the kube config should be updated.
15071507
fake_config.refresh_api_key_hook(fake_config)
1508-
self.assertEqual(fake_config.api_key["authorization"],
1508+
self.assertEqual(fake_config.api_key["BearerToken"],
15091509
BEARER_TOKEN_FORMAT % current_token)
15101510

15111511
@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)