Pass all options when doing keystone discovery
When trying to discover Keystone URI in get_auth_uri, pass all the related options. This refactors some code to have one place in common.config to retrieve options for clients, instead of 3. Change-Id: Ic78d47f69db33fc312ed2684976df90b75881eec Closes-Bug: #1547495
This commit is contained in:
parent
536c8580a0
commit
49a9a10e97
|
@ -16,9 +16,9 @@
|
|||
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
from keystoneclient import session
|
||||
from oslo_config import cfg
|
||||
from webob import exc
|
||||
|
||||
from heat.common import config
|
||||
from heat.common import context
|
||||
|
||||
|
||||
|
@ -106,24 +106,12 @@ class KeystonePasswordAuthProtocol(object):
|
|||
return headers
|
||||
|
||||
def _ssl_options(self):
|
||||
opts = {'cacert': self._get_client_option('ca_file'),
|
||||
'insecure': self._get_client_option('insecure'),
|
||||
'cert': self._get_client_option('cert_file'),
|
||||
'key': self._get_client_option('key_file')}
|
||||
opts = {'cacert': config.get_client_option('keystone', 'ca_file'),
|
||||
'insecure': config.get_client_option('keystone', 'insecure'),
|
||||
'cert': config.get_client_option('keystone', 'cert_file'),
|
||||
'key': config.get_client_option('keystone', 'key_file')}
|
||||
return opts
|
||||
|
||||
def _get_client_option(self, option):
|
||||
# look for the option in the [clients_keystone] section
|
||||
# unknown options raise cfg.NoSuchOptError
|
||||
cfg.CONF.import_opt(option, 'heat.common.config',
|
||||
group='clients_keystone')
|
||||
v = getattr(cfg.CONF.clients_keystone, option)
|
||||
if v is not None:
|
||||
return v
|
||||
# look for the option in the generic [clients] section
|
||||
cfg.CONF.import_opt(option, 'heat.common.config', group='clients')
|
||||
return getattr(cfg.CONF.clients, option)
|
||||
|
||||
|
||||
def filter_factory(global_conf, **local_conf):
|
||||
"""Returns a WSGI filter app for use with paste.deploy."""
|
||||
|
|
|
@ -446,3 +446,20 @@ def load_paste_app(app_name=None):
|
|||
"\nGot: %(e)r") % {'app_name': app_name,
|
||||
'conf_file': conf_file,
|
||||
'e': e})
|
||||
|
||||
|
||||
def get_client_option(client, option):
|
||||
# look for the option in the [clients_${client}] section
|
||||
# unknown options raise cfg.NoSuchOptError
|
||||
try:
|
||||
group_name = 'clients_' + client
|
||||
cfg.CONF.import_opt(option, 'heat.common.config',
|
||||
group=group_name)
|
||||
v = getattr(getattr(cfg.CONF, group_name), option)
|
||||
if v is not None:
|
||||
return v
|
||||
except cfg.NoSuchGroupError:
|
||||
pass # do not error if the client is unknown
|
||||
# look for the option in the generic [clients] section
|
||||
cfg.CONF.import_opt(option, 'heat.common.config', group='clients')
|
||||
return getattr(cfg.CONF.clients, option)
|
||||
|
|
|
@ -17,6 +17,8 @@ from keystoneclient import discover as ks_discover
|
|||
from oslo_config import cfg
|
||||
from oslo_utils import importutils
|
||||
|
||||
from heat.common import config
|
||||
|
||||
|
||||
def get_auth_uri(v3=True):
|
||||
# Look for the keystone auth_uri in the configuration. First we
|
||||
|
@ -24,7 +26,11 @@ def get_auth_uri(v3=True):
|
|||
# look in [keystone_authtoken]
|
||||
if cfg.CONF.clients_keystone.auth_uri:
|
||||
discover = ks_discover.Discover(
|
||||
auth_url=cfg.CONF.clients_keystone.auth_uri)
|
||||
auth_url=cfg.CONF.clients_keystone.auth_uri,
|
||||
cacert=config.get_client_option('keystone', 'ca_file'),
|
||||
insecure=config.get_client_option('keystone', 'insecure'),
|
||||
cert=config.get_client_option('keystone', 'cert_file'),
|
||||
key=config.get_client_option('keystone', 'key_file'))
|
||||
return discover.url_for('3.0')
|
||||
else:
|
||||
# Import auth_token to have keystone_authtoken settings setup.
|
||||
|
|
|
@ -25,6 +25,7 @@ from oslo_log import log as logging
|
|||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import importutils
|
||||
|
||||
from heat.common import config
|
||||
from heat.common import context
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
|
@ -169,24 +170,12 @@ class KeystoneClientV3(object):
|
|||
return client
|
||||
|
||||
def _ssl_options(self):
|
||||
opts = {'cacert': self._get_client_option('ca_file'),
|
||||
'insecure': self._get_client_option('insecure'),
|
||||
'cert': self._get_client_option('cert_file'),
|
||||
'key': self._get_client_option('key_file')}
|
||||
opts = {'cacert': config.get_client_option('keystone', 'ca_file'),
|
||||
'insecure': config.get_client_option('keystone', 'insecure'),
|
||||
'cert': config.get_client_option('keystone', 'cert_file'),
|
||||
'key': config.get_client_option('keystone', 'key_file')}
|
||||
return opts
|
||||
|
||||
def _get_client_option(self, option):
|
||||
# look for the option in the [clients_keystone] section
|
||||
# unknown options raise cfg.NoSuchOptError
|
||||
cfg.CONF.import_opt(option, 'heat.common.config',
|
||||
group='clients_keystone')
|
||||
v = getattr(cfg.CONF.clients_keystone, option)
|
||||
if v is not None:
|
||||
return v
|
||||
# look for the option in the generic [clients] section
|
||||
cfg.CONF.import_opt(option, 'heat.common.config', group='clients')
|
||||
return getattr(cfg.CONF.clients, option)
|
||||
|
||||
def create_trust_context(self):
|
||||
"""Create a trust using the trustor identity in the current context.
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from keystoneclient import session
|
|||
from oslo_config import cfg
|
||||
import six
|
||||
|
||||
from heat.common import config
|
||||
from heat.common.i18n import _
|
||||
|
||||
|
||||
|
@ -111,6 +112,8 @@ class ClientPlugin(object):
|
|||
def clients(self):
|
||||
return self._clients()
|
||||
|
||||
_get_client_option = staticmethod(config.get_client_option)
|
||||
|
||||
@property
|
||||
def _keystone_session(self):
|
||||
# FIXME(jamielennox): This session object is essentially static as the
|
||||
|
@ -210,22 +213,6 @@ class ClientPlugin(object):
|
|||
|
||||
return url
|
||||
|
||||
def _get_client_option(self, client, option):
|
||||
# look for the option in the [clients_${client}] section
|
||||
# unknown options raise cfg.NoSuchOptError
|
||||
try:
|
||||
group_name = 'clients_' + client
|
||||
cfg.CONF.import_opt(option, 'heat.common.config',
|
||||
group=group_name)
|
||||
v = getattr(getattr(cfg.CONF, group_name), option)
|
||||
if v is not None:
|
||||
return v
|
||||
except cfg.NoSuchGroupError:
|
||||
pass # do not error if the client is unknown
|
||||
# look for the option in the generic [clients] section
|
||||
cfg.CONF.import_opt(option, 'heat.common.config', group='clients')
|
||||
return getattr(cfg.CONF.clients, option)
|
||||
|
||||
def is_client_exception(self, ex):
|
||||
"""Returns True if the current exception comes from the client."""
|
||||
if self.exceptions_module:
|
||||
|
|
Loading…
Reference in New Issue