Skip to content

Commit 747a624

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Change --os-auth-plugin to --os-auth-type"
2 parents 6a4b673 + f079b5b commit 747a624

4 files changed

Lines changed: 66 additions & 68 deletions

File tree

‎openstackclient/api/auth.py‎

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
invoke_on_load=False,
3737
propagate_map_exceptions=True,
3838
)
39-
# TODO(dtroyer): add some method to list the plugins for the
40-
# --os_auth_plugin option
4139

4240
# Get the command line options so the help action has them available
4341
OPTIONS_LIST = {}
@@ -56,50 +54,53 @@
5654

5755

5856
def select_auth_plugin(options):
59-
"""If no auth plugin was specified, pick one based on other options"""
57+
"""Pick an auth plugin based on --os-auth-type or other options"""
58+
59+
auth_plugin_name = None
60+
61+
if options.os_auth_type in [plugin.name for plugin in PLUGIN_LIST]:
62+
# A direct plugin name was given, use it
63+
return options.os_auth_type
6064

61-
auth_plugin = None
6265
if options.os_url and options.os_token:
6366
# service token authentication
64-
auth_plugin = 'token_endpoint'
67+
auth_plugin_name = 'token_endpoint'
6568
elif options.os_username:
6669
if options.os_identity_api_version == '3':
67-
auth_plugin = 'v3password'
70+
auth_plugin_name = 'v3password'
6871
elif options.os_identity_api_version == '2.0':
69-
auth_plugin = 'v2password'
72+
auth_plugin_name = 'v2password'
7073
else:
7174
# let keystoneclient figure it out itself
72-
auth_plugin = 'password'
75+
auth_plugin_name = 'password'
7376
elif options.os_token:
7477
if options.os_identity_api_version == '3':
75-
auth_plugin = 'v3token'
78+
auth_plugin_name = 'v3token'
7679
elif options.os_identity_api_version == '2.0':
77-
auth_plugin = 'v2token'
80+
auth_plugin_name = 'v2token'
7881
else:
7982
# let keystoneclient figure it out itself
80-
auth_plugin = 'token'
83+
auth_plugin_name = 'token'
8184
else:
8285
raise exc.CommandError(
83-
"Could not figure out which authentication method "
84-
"to use, please set --os-auth-plugin"
86+
"Authentication type must be selected with --os-auth-type"
8587
)
86-
LOG.debug("No auth plugin selected, picking %s from other "
87-
"options" % auth_plugin)
88-
return auth_plugin
88+
LOG.debug("Auth plugin %s selected" % auth_plugin_name)
89+
return auth_plugin_name
8990

9091

91-
def build_auth_params(cmd_options):
92+
def build_auth_params(auth_plugin_name, cmd_options):
9293
auth_params = {}
93-
if cmd_options.os_auth_plugin:
94-
LOG.debug('auth_plugin: %s', cmd_options.os_auth_plugin)
95-
auth_plugin = base.get_plugin_class(cmd_options.os_auth_plugin)
96-
plugin_options = auth_plugin.get_options()
94+
if auth_plugin_name:
95+
LOG.debug('auth_type: %s', auth_plugin_name)
96+
auth_plugin_class = base.get_plugin_class(auth_plugin_name)
97+
plugin_options = auth_plugin_class.get_options()
9798
for option in plugin_options:
9899
option_name = 'os_' + option.dest
99100
LOG.debug('fetching option %s' % option_name)
100101
auth_params[option.dest] = getattr(cmd_options, option_name, None)
101102
# grab tenant from project for v2.0 API compatibility
102-
if cmd_options.os_auth_plugin.startswith("v2"):
103+
if auth_plugin_name.startswith("v2"):
103104
auth_params['tenant_id'] = getattr(
104105
cmd_options,
105106
'os_project_id',
@@ -111,14 +112,14 @@ def build_auth_params(cmd_options):
111112
None,
112113
)
113114
else:
114-
LOG.debug('no auth_plugin')
115+
LOG.debug('no auth_type')
115116
# delay the plugin choice, grab every option
116117
plugin_options = set([o.replace('-', '_') for o in OPTIONS_LIST])
117118
for option in plugin_options:
118119
option_name = 'os_' + option
119120
LOG.debug('fetching option %s' % option_name)
120121
auth_params[option] = getattr(cmd_options, option_name, None)
121-
return auth_params
122+
return (auth_plugin_class, auth_params)
122123

123124

124125
def build_auth_plugins_option_parser(parser):
@@ -130,15 +131,12 @@ def build_auth_plugins_option_parser(parser):
130131
"""
131132
available_plugins = [plugin.name for plugin in PLUGIN_LIST]
132133
parser.add_argument(
133-
'--os-auth-plugin',
134-
metavar='<OS_AUTH_PLUGIN>',
135-
default=utils.env('OS_AUTH_PLUGIN'),
136-
help='The authentication method to use. If this option is not set, '
137-
'openstackclient will attempt to guess the authentication method '
138-
'to use based on the other options. If this option is set, '
139-
'the --os-identity-api-version argument must be consistent '
140-
'with the version of the method.\nAvailable methods are ' +
141-
', '.join(available_plugins),
134+
'--os-auth-type',
135+
metavar='<auth-type>',
136+
default=utils.env('OS_AUTH_TYPE'),
137+
help='Select an auhentication type. Available types: ' +
138+
', '.join(available_plugins) +
139+
'. Default: selected based on --os-username/--os-token',
142140
choices=available_plugins
143141
)
144142
# make sur we catch old v2.0 env values

‎openstackclient/common/clientmanager.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pkg_resources
2020
import sys
2121

22-
from keystoneclient.auth import base
2322
from keystoneclient import session
2423
import requests
2524

@@ -78,20 +77,22 @@ def __init__(
7877
returns a string containig the password
7978
"""
8079

81-
# If no plugin is named by the user, select one based on
80+
# If no auth type is named by the user, select one based on
8281
# the supplied options
83-
if not auth_options.os_auth_plugin:
84-
auth_options.os_auth_plugin = auth.select_auth_plugin(auth_options)
85-
self._auth_plugin = auth_options.os_auth_plugin
82+
self.auth_plugin_name = auth.select_auth_plugin(auth_options)
8683

8784
# Horrible hack alert...must handle prompt for null password if
8885
# password auth is requested.
89-
if (self._auth_plugin.endswith('password') and
86+
if (self.auth_plugin_name.endswith('password') and
9087
not auth_options.os_password):
9188
auth_options.os_password = pw_func()
9289

90+
(auth_plugin, self._auth_params) = auth.build_auth_params(
91+
self.auth_plugin_name,
92+
auth_options,
93+
)
94+
9395
self._url = auth_options.os_url
94-
self._auth_params = auth.build_auth_params(auth_options)
9596
self._region_name = auth_options.os_region_name
9697
self._api_version = api_version
9798
self._auth_ref = None
@@ -117,8 +118,7 @@ def __init__(
117118
root_logger = logging.getLogger('')
118119
LOG.setLevel(root_logger.getEffectiveLevel())
119120

120-
LOG.debug('Using auth plugin: %s' % self._auth_plugin)
121-
auth_plugin = base.get_plugin_class(self._auth_plugin)
121+
LOG.debug('Using auth plugin: %s' % self.auth_plugin_name)
122122
self.auth = auth_plugin.load_from_options(**self._auth_params)
123123
# needed by SAML authentication
124124
request_session = requests.session()

‎openstackclient/tests/common/test_clientmanager.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FakeOptions(object):
4444
def __init__(self, **kwargs):
4545
for option in auth.OPTIONS_LIST:
4646
setattr(self, 'os_' + option.replace('-', '_'), None)
47-
self.os_auth_plugin = None
47+
self.os_auth_type = None
4848
self.os_identity_api_version = '2.0'
4949
self.timing = None
5050
self.os_region_name = None
@@ -81,7 +81,7 @@ def test_client_manager_token_endpoint(self):
8181
client_manager = clientmanager.ClientManager(
8282
auth_options=FakeOptions(os_token=fakes.AUTH_TOKEN,
8383
os_url=fakes.AUTH_URL,
84-
os_auth_plugin='token_endpoint'),
84+
os_auth_type='token_endpoint'),
8585
api_version=API_VERSION,
8686
verify=True
8787
)
@@ -105,7 +105,7 @@ def test_client_manager_token(self):
105105
client_manager = clientmanager.ClientManager(
106106
auth_options=FakeOptions(os_token=fakes.AUTH_TOKEN,
107107
os_auth_url=fakes.AUTH_URL,
108-
os_auth_plugin='v2token'),
108+
os_auth_type='v2token'),
109109
api_version=API_VERSION,
110110
verify=True
111111
)
@@ -183,7 +183,7 @@ def test_client_manager_password_verify_ca(self):
183183
auth_options=FakeOptions(os_auth_url=fakes.AUTH_URL,
184184
os_username=fakes.USERNAME,
185185
os_password=fakes.PASSWORD,
186-
os_auth_plugin='v2password'),
186+
os_auth_type='v2password'),
187187
api_version=API_VERSION,
188188
verify='cafile',
189189
)
@@ -192,17 +192,17 @@ def test_client_manager_password_verify_ca(self):
192192
self.assertTrue(client_manager._verify)
193193
self.assertEqual('cafile', client_manager._cacert)
194194

195-
def _select_auth_plugin(self, auth_params, api_version, auth_plugin):
196-
auth_params['os_auth_plugin'] = auth_plugin
195+
def _select_auth_plugin(self, auth_params, api_version, auth_plugin_name):
196+
auth_params['os_auth_type'] = auth_plugin_name
197197
auth_params['os_identity_api_version'] = api_version
198198
client_manager = clientmanager.ClientManager(
199199
auth_options=FakeOptions(**auth_params),
200200
api_version=API_VERSION,
201201
verify=True
202202
)
203203
self.assertEqual(
204-
auth_plugin,
205-
client_manager._auth_plugin,
204+
auth_plugin_name,
205+
client_manager.auth_plugin_name,
206206
)
207207

208208
def test_client_manager_select_auth_plugin(self):

‎openstackclient/tests/test_shell.py‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def _assert_password_auth(self, cmd_options, default_args):
108108
default_args["region_name"])
109109
self.assertEqual(_shell.options.os_trust_id,
110110
default_args["trust_id"])
111-
self.assertEqual(_shell.options.os_auth_plugin,
112-
default_args['auth_plugin'])
111+
self.assertEqual(_shell.options.os_auth_type,
112+
default_args['auth_type'])
113113

114114
def _assert_token_auth(self, cmd_options, default_args):
115115
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
@@ -190,7 +190,7 @@ def test_only_url_flow(self):
190190
"password": "",
191191
"region_name": "",
192192
"trust_id": "",
193-
"auth_plugin": "",
193+
"auth_type": "",
194194
}
195195
self._assert_password_auth(flag, kwargs)
196196

@@ -210,7 +210,7 @@ def test_only_project_id_flow(self):
210210
"password": "",
211211
"region_name": "",
212212
"trust_id": "",
213-
"auth_plugin": "",
213+
"auth_type": "",
214214
}
215215
self._assert_password_auth(flag, kwargs)
216216

@@ -230,7 +230,7 @@ def test_only_project_name_flow(self):
230230
"password": "",
231231
"region_name": "",
232232
"trust_id": "",
233-
"auth_plugin": "",
233+
"auth_type": "",
234234
}
235235
self._assert_password_auth(flag, kwargs)
236236

@@ -250,7 +250,7 @@ def test_only_domain_id_flow(self):
250250
"password": "",
251251
"region_name": "",
252252
"trust_id": "",
253-
"auth_plugin": "",
253+
"auth_type": "",
254254
}
255255
self._assert_password_auth(flag, kwargs)
256256

@@ -270,7 +270,7 @@ def test_only_domain_name_flow(self):
270270
"password": "",
271271
"region_name": "",
272272
"trust_id": "",
273-
"auth_plugin": "",
273+
"auth_type": "",
274274
}
275275
self._assert_password_auth(flag, kwargs)
276276

@@ -290,7 +290,7 @@ def test_only_user_domain_id_flow(self):
290290
"password": "",
291291
"region_name": "",
292292
"trust_id": "",
293-
"auth_plugin": "",
293+
"auth_type": "",
294294
}
295295
self._assert_password_auth(flag, kwargs)
296296

@@ -310,7 +310,7 @@ def test_only_user_domain_name_flow(self):
310310
"password": "",
311311
"region_name": "",
312312
"trust_id": "",
313-
"auth_plugin": "",
313+
"auth_type": "",
314314
}
315315
self._assert_password_auth(flag, kwargs)
316316

@@ -330,7 +330,7 @@ def test_only_project_domain_id_flow(self):
330330
"password": "",
331331
"region_name": "",
332332
"trust_id": "",
333-
"auth_plugin": "",
333+
"auth_type": "",
334334
}
335335
self._assert_password_auth(flag, kwargs)
336336

@@ -350,7 +350,7 @@ def test_only_project_domain_name_flow(self):
350350
"password": "",
351351
"region_name": "",
352352
"trust_id": "",
353-
"auth_plugin": "",
353+
"auth_type": "",
354354
}
355355
self._assert_password_auth(flag, kwargs)
356356

@@ -370,7 +370,7 @@ def test_only_username_flow(self):
370370
"password": "",
371371
"region_name": "",
372372
"trust_id": "",
373-
"auth_plugin": "",
373+
"auth_type": "",
374374
}
375375
self._assert_password_auth(flag, kwargs)
376376

@@ -390,7 +390,7 @@ def test_only_password_flow(self):
390390
"password": DEFAULT_PASSWORD,
391391
"region_name": "",
392392
"trust_id": "",
393-
"auth_plugin": "",
393+
"auth_type": "",
394394
}
395395
self._assert_password_auth(flag, kwargs)
396396

@@ -410,7 +410,7 @@ def test_only_region_name_flow(self):
410410
"password": "",
411411
"region_name": DEFAULT_REGION_NAME,
412412
"trust_id": "",
413-
"auth_plugin": "",
413+
"auth_type": "",
414414
}
415415
self._assert_password_auth(flag, kwargs)
416416

@@ -430,12 +430,12 @@ def test_only_trust_id_flow(self):
430430
"password": "",
431431
"region_name": "",
432432
"trust_id": "1234",
433-
"auth_plugin": "",
433+
"auth_type": "",
434434
}
435435
self._assert_password_auth(flag, kwargs)
436436

437-
def test_only_auth_plugin_flow(self):
438-
flag = "--os-auth-plugin " + "v2password"
437+
def test_only_auth_type_flow(self):
438+
flag = "--os-auth-type " + "v2password"
439439
kwargs = {
440440
"auth_url": "",
441441
"project_id": "",
@@ -450,7 +450,7 @@ def test_only_auth_plugin_flow(self):
450450
"password": "",
451451
"region_name": "",
452452
"trust_id": "",
453-
"auth_plugin": DEFAULT_AUTH_PLUGIN
453+
"auth_type": DEFAULT_AUTH_PLUGIN
454454
}
455455
self._assert_password_auth(flag, kwargs)
456456

0 commit comments

Comments
 (0)