Factor Adapter conf-processing logic into a helper
Subclasses of keystoneauth1.adapter.Adapter, such as openstacksdk's
openstack.proxy.Proxy [1], would like to be able to obtain configuration
from oslo_config conf options.
This commit splits the conf processing logic out of
keystoneauth1.loading.adapter.Adapter.load_from_conf_options (aka
keystoneauth1.loading.load_adapter_from_conf_options) into a helper
method, keystoneauth1.loading.adapter.process_conf_options.
This is a straight refactor, so no test changes are necessary.
[1] 16f2dbe3b0/openstack/proxy.py (L113)
Change-Id: I250c431ccf3883901f7dce151bc5011ac305f829
This commit is contained in:
parent
bde07bc95b
commit
f83f3fb750
|
@ -216,36 +216,48 @@ class Adapter(base.BaseLoader):
|
|||
:rtype: :py:class:`.Adapter`
|
||||
"""
|
||||
c = conf[group]
|
||||
|
||||
if c.valid_interfaces and hasattr(c, 'interface') and c.interface:
|
||||
raise TypeError("interface and valid_interfaces are mutually"
|
||||
" exclusive. Please use valid_interfaces.")
|
||||
if c.valid_interfaces:
|
||||
for iface in c.valid_interfaces:
|
||||
if iface not in ('public', 'internal', 'admin'):
|
||||
raise TypeError("'{iface}' is not a valid value for"
|
||||
" valid_interfaces. Valid valies are"
|
||||
" public, internal or admin".format(
|
||||
iface=iface))
|
||||
kwargs.setdefault('interface', c.valid_interfaces)
|
||||
elif hasattr(c, 'interface'):
|
||||
kwargs.setdefault('interface', c.interface)
|
||||
kwargs.setdefault('service_type', c.service_type)
|
||||
kwargs.setdefault('service_name', c.service_name)
|
||||
kwargs.setdefault('region_name', c.region_name)
|
||||
kwargs.setdefault('endpoint_override', c.endpoint_override)
|
||||
kwargs.setdefault('version', c.version)
|
||||
kwargs.setdefault('min_version', c.min_version)
|
||||
kwargs.setdefault('max_version', c.max_version)
|
||||
if kwargs['version'] and (
|
||||
kwargs['max_version'] or kwargs['min_version']):
|
||||
raise TypeError(
|
||||
"version is mutually exclusive with min_version and"
|
||||
" max_version")
|
||||
|
||||
process_conf_options(c, kwargs)
|
||||
return self.load_from_options(**kwargs)
|
||||
|
||||
|
||||
def process_conf_options(confgrp, kwargs):
|
||||
"""Set Adapter constructor kwargs based on conf options.
|
||||
|
||||
:param oslo_config.cfg.GroupAttr confgrp: Config object group containing
|
||||
options to inspect.
|
||||
:param dict kwargs: Keyword arguments suitable for the constructor of
|
||||
keystoneauth1.adapter.Adapter. Will be modified by this method.
|
||||
Values already set remain unaffected.
|
||||
:raise TypeError: If invalid conf option values or combinations are found.
|
||||
"""
|
||||
if confgrp.valid_interfaces and getattr(confgrp, 'interface', None):
|
||||
raise TypeError("interface and valid_interfaces are mutually"
|
||||
" exclusive. Please use valid_interfaces.")
|
||||
if confgrp.valid_interfaces:
|
||||
for iface in confgrp.valid_interfaces:
|
||||
if iface not in ('public', 'internal', 'admin'):
|
||||
# TODO(efried): s/valies/values/ - are we allowed to fix this?
|
||||
raise TypeError("'{iface}' is not a valid value for"
|
||||
" valid_interfaces. Valid valies are"
|
||||
" public, internal or admin".format(
|
||||
iface=iface))
|
||||
kwargs.setdefault('interface', confgrp.valid_interfaces)
|
||||
elif hasattr(confgrp, 'interface'):
|
||||
kwargs.setdefault('interface', confgrp.interface)
|
||||
kwargs.setdefault('service_type', confgrp.service_type)
|
||||
kwargs.setdefault('service_name', confgrp.service_name)
|
||||
kwargs.setdefault('region_name', confgrp.region_name)
|
||||
kwargs.setdefault('endpoint_override', confgrp.endpoint_override)
|
||||
kwargs.setdefault('version', confgrp.version)
|
||||
kwargs.setdefault('min_version', confgrp.min_version)
|
||||
kwargs.setdefault('max_version', confgrp.max_version)
|
||||
if kwargs['version'] and (
|
||||
kwargs['max_version'] or kwargs['min_version']):
|
||||
raise TypeError(
|
||||
"version is mutually exclusive with min_version and"
|
||||
" max_version")
|
||||
|
||||
|
||||
def register_argparse_arguments(*args, **kwargs):
|
||||
return adapter.register_adapter_argparse_arguments(*args, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue