diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-09-18 16:54:46 -0400 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-09-18 17:10:54 -0400 |
commit | aa41f9bfb10b6f75e1a3f7c599c8c06e7a03d389 (patch) | |
tree | a3e327ac7fdf32cbb4711bd1b0b2fbaa42826eb9 | |
parent | 21bb2f347d0d52defa98726b7102c1853b558072 (diff) | |
download | os-client-config-aa41f9bfb10b6f75e1a3f7c599c8c06e7a03d389.tar.gz |
Fall back to keystoneclient arg processing
For things not on keystoneauth yet, we need to move things into
the auth dict using keystoneclient.
Change-Id: Ia4500cc270b775f189048ccf667d5bfdc5dfcd14
-rw-r--r-- | os_client_config/config.py | 80 |
1 files changed, 74 insertions, 6 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py index 5dbe8db..96d5fa7 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -17,7 +17,10 @@ import os import warnings import appdirs -from keystoneauth1 import loading +try: + from keystoneauth1 import loading +except ImportError: + loading = None import yaml from os_client_config import cloud_config @@ -400,7 +403,9 @@ class OpenStackConfig(object): if opt_name in config: return config[opt_name] else: - for d_opt in opt.deprecated: + deprecated = getattr(opt, 'deprecated', getattr( + opt, 'deprecated_opts')) + for d_opt in deprecated: d_opt_name = d_opt.name.replace('-', '_') if d_opt_name in config: return config[d_opt_name] @@ -417,6 +422,54 @@ class OpenStackConfig(object): config['auth']['token'] = None return loading.get_plugin_loader(config['auth_type']) + def _validate_auth_ksc(self, config): + try: + import keystoneclient.auth as ksc_auth + except ImportError: + return config + + # May throw a keystoneclient.exceptions.NoMatchingPlugin + plugin_options = ksc_auth.get_plugin_class( + config['auth_type']).get_options() + + for p_opt in plugin_options: + # if it's in config.auth, win, kill it from config dict + # if it's in config and not in config.auth, move it + # deprecated loses to current + # provided beats default, deprecated or not + winning_value = self._find_winning_auth_value( + p_opt, config['auth']) + if not winning_value: + winning_value = self._find_winning_auth_value(p_opt, config) + + # if the plugin tells us that this value is required + # then error if it's doesn't exist now + if not winning_value and p_opt.required: + raise exceptions.OpenStackConfigException( + 'Unable to find auth information for cloud' + ' {cloud} in config files {files}' + ' or environment variables. Missing value {auth_key}' + ' required for auth plugin {plugin}'.format( + cloud=cloud, files=','.join(self._config_files), + auth_key=p_opt.name, plugin=config.get('auth_type'))) + + # Clean up after ourselves + for opt in [p_opt.name] + [o.name for o in p_opt.deprecated_opts]: + opt = opt.replace('-', '_') + config.pop(opt, None) + config['auth'].pop(opt, None) + + if winning_value: + # Prefer the plugin configuration dest value if the value's key + # is marked as depreciated. + if p_opt.dest is None: + config['auth'][p_opt.name.replace('-', '_')] = ( + winning_value) + else: + config['auth'][p_opt.dest] = winning_value + + return config + def _validate_auth(self, config, loader): # May throw a keystoneauth1.exceptions.NoMatchingPlugin @@ -495,12 +548,27 @@ class OpenStackConfig(object): if type(config[key]) is not bool: config[key] = get_boolean(config[key]) - if validate: - loader = self._get_auth_loader(config) - config = self._validate_auth(config, loader) - auth_plugin = loader.load_from_options(**config['auth']) + if loading: + if validate: + try: + loader = self._get_auth_loader(config) + config = self._validate_auth(config, loader) + auth_plugin = loader.load_from_options(**config['auth']) + except Exception as e: + # We WANT the ksa exception normally + # but OSC can't handle it right now, so we try deferring + # to ksc. If that ALSO fails, it means there is likely + # a deeper issue, so we assume the ksa error was correct + auth_plugin = None + try: + config = self._validate_auth_ksc(config) + except Exception: + raise e + else: + auth_plugin = None else: auth_plugin = None + config = self._validate_auth_ksc(config) # If any of the defaults reference other values, we need to expand for (key, value) in config.items(): |