summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--os_client_config/config.py80
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():