diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-12-12 10:53:53 -0500 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-12-18 09:46:45 -0500 |
commit | 22d740b7007e1182c99370cb2629322384b17a14 (patch) | |
tree | 2a0e77ccb208a7d3120ec7b6ae678b7befb7cfe9 | |
parent | 837ca712288ceffea5b54ceaeb349d6577f38360 (diff) | |
download | os-client-config-22d740b7007e1182c99370cb2629322384b17a14.tar.gz |
Add backwards compat mapping for auth-token
novaclient accepted an auth-token argument, which also triggered a token
not password based workflow. That's fine - let's map that to token, and
if we find it, change auth_type's default from password to token.
Change-Id: Ie9acece5cb3c68560ae975bfb0fb2393381b6fba
-rw-r--r-- | os_client_config/config.py | 15 | ||||
-rw-r--r-- | os_client_config/tests/test_config.py | 30 |
2 files changed, 45 insertions, 0 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py index ab3a003..48bcb0f 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -467,6 +467,7 @@ class OpenStackConfig(object): 'project_domain_id': ('project_domain_id', 'project-domain-id'), 'project_domain_name': ( 'project_domain_name', 'project-domain-name'), + 'token': ('auth-token', 'auth_token', 'token'), } for target_key, possible_values in mappings.items(): target = None @@ -535,6 +536,13 @@ class OpenStackConfig(object): # for from the user passing it explicitly. We'll stash it for later local_parser.add_argument('--timeout', metavar='<timeout>') + # We need for get_one_cloud to be able to peek at whether a token + # was passed so that we can swap the default from password to + # token if it was. And we need to also peek for --os-auth-token + # for novaclient backwards compat + local_parser.add_argument('--os-token') + local_parser.add_argument('--os-auth-token') + # Peek into the future and see if we have an auth-type set in # config AND a cloud set, so that we know which command line # arguments to register and show to the user (the user may want @@ -832,6 +840,13 @@ class OpenStackConfig(object): else: config[key] = val + # Infer token plugin if a token was given + if (('auth' in config and 'token' in config['auth']) or + ('auth_token' in config and config['auth_token']) or + ('token' in config and config['token'])): + config['auth_type'] = 'token' + config.setdefault('token', config.pop('auth_token', None)) + # These backwards compat values are only set via argparse. If it's # there, it's because it was passed in explicitly, and should win config = self._fix_backwards_api_timeout(config) diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index 98aaf79..bb45693 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -243,7 +243,9 @@ class TestConfigArgparse(base.TestCase): project_name='project', region_name='region2', snack_type='cookie', + os_auth_token='no-good-things', ) + self.options = argparse.Namespace(**self.args) def test_get_one_cloud_bad_region_argparse(self): @@ -401,6 +403,34 @@ class TestConfigArgparse(base.TestCase): opts, _remain = parser.parse_known_args(['--os-cloud', 'foo']) self.assertEqual(opts.os_cloud, 'foo') + def test_argparse_default_no_token(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + + parser = argparse.ArgumentParser() + c.register_argparse_arguments(parser, []) + # novaclient will add this + parser.add_argument('--os-auth-token') + opts, _remain = parser.parse_known_args() + cc = c.get_one_cloud( + cloud='_test_cloud_regions', argparse=opts) + self.assertEqual(cc.config['auth_type'], 'password') + self.assertNotIn('token', cc.config['auth']) + + def test_argparse_token(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + + parser = argparse.ArgumentParser() + c.register_argparse_arguments(parser, []) + # novaclient will add this + parser.add_argument('--os-auth-token') + opts, _remain = parser.parse_known_args( + ['--os-auth-token', 'very-bad-things']) + cc = c.get_one_cloud(argparse=opts) + self.assertEqual(cc.config['auth_type'], 'token') + self.assertEqual(cc.config['auth']['token'], 'very-bad-things') + def test_register_argparse_bad_plugin(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) |