X Tutup
Skip to content

Commit bfc0c8f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add OpenID Connect Token Auth for k8s"
2 parents 21f60be + 0fcb9a5 commit bfc0c8f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

tackerclient/tacker/v1_0/nfvo/vim_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,25 @@ def args2body_vim(config_param, vim):
6363
message='Project name must be specified in Kubernetes VIM,'
6464
'it is namespace in Kubernetes environment',
6565
status_code=404)
66-
if ('username' in config_param) and ('password' in config_param):
66+
if 'oidc_token_url' in config_param:
67+
if ('username' not in config_param or
68+
'password' not in config_param or
69+
'client_id' not in config_param):
70+
# the username, password, client_id are required.
71+
# client_secret is not required when client type is public.
72+
raise exceptions.TackerClientException(
73+
message='oidc_token_url must be specified with username,'
74+
' password, client_id, client_secret(optional).',
75+
status_code=404)
76+
vim['auth_cred'] = {
77+
'oidc_token_url': config_param.pop('oidc_token_url'),
78+
'username': config_param.pop('username'),
79+
'password': config_param.pop('password'),
80+
'client_id': config_param.pop('client_id')}
81+
if 'client_secret' in config_param:
82+
vim['auth_cred']['client_secret'] = config_param.pop(
83+
'client_secret')
84+
elif ('username' in config_param) and ('password' in config_param):
6785
vim['auth_cred'] = {
6886
'username': config_param.pop('username', ''),
6987
'password': config_param.pop('password', '')}

tackerclient/tests/unit/vm/test_vim_utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ def test_args2body_kubernetes_vim_bearer(self):
7676
vim_utils.args2body_vim(config_param.copy(), vim)
7777
self.assertEqual(expected_vim, vim)
7878

79+
def test_args2body_kubernetes_vim_oidc(self):
80+
config_param = {'oidc_token_url': sentinel.oidc_token_url,
81+
'username': sentinel.username,
82+
'password': sentinel.password,
83+
'client_id': sentinel.client_id,
84+
'client_secret': sentinel.client_secret,
85+
'ssl_ca_cert': "None",
86+
'project_name': sentinel.prj_name,
87+
'type': 'kubernetes'}
88+
vim = {}
89+
auth_cred = config_param.copy()
90+
auth_cred.pop('project_name')
91+
auth_cred.pop('type')
92+
expected_vim = {'auth_cred': auth_cred,
93+
'vim_project':
94+
{'name': sentinel.prj_name},
95+
'type': 'kubernetes'}
96+
vim_utils.args2body_vim(config_param.copy(), vim)
97+
self.assertEqual(expected_vim, vim)
98+
99+
def test_args2body_kubernetes_vim_oidc_no_username(self):
100+
config_param = {'oidc_token_url': sentinel.oidc_token_url,
101+
'password': sentinel.password,
102+
'client_id': sentinel.client_id,
103+
'client_secret': sentinel.client_secret,
104+
'ssl_ca_cert': "None",
105+
'project_name': sentinel.prj_name,
106+
'type': 'kubernetes'}
107+
vim = {}
108+
self.assertRaises(exceptions.TackerClientException,
109+
vim_utils.args2body_vim,
110+
config_param, vim)
111+
79112
def test_args2body_vim_no_project(self):
80113
config_param = {'username': sentinel.usrname1,
81114
'password': sentinel.password1,

0 commit comments

Comments
 (0)
X Tutup