Merge "Refactor names in catalog backends"
This commit is contained in:
commit
b5ab92e33a
|
@ -240,9 +240,8 @@ class Catalog(catalog.Driver):
|
|||
return ref.to_dict()
|
||||
|
||||
def get_catalog(self, user_id, tenant_id, metadata=None):
|
||||
d = dict(six.iteritems(CONF))
|
||||
d.update({'tenant_id': tenant_id,
|
||||
'user_id': user_id})
|
||||
substitutions = dict(six.iteritems(CONF))
|
||||
substitutions.update({'tenant_id': tenant_id, 'user_id': user_id})
|
||||
|
||||
session = sql.get_session()
|
||||
t = True # variable for singleton for PEP8, E712.
|
||||
|
@ -256,7 +255,7 @@ class Catalog(catalog.Driver):
|
|||
if not endpoint.service['enabled']:
|
||||
continue
|
||||
try:
|
||||
url = core.format_url(endpoint['url'], d)
|
||||
url = core.format_url(endpoint['url'], substitutions)
|
||||
except exception.MalformedEndpoint:
|
||||
continue # this failure is already logged in format_url()
|
||||
|
||||
|
|
|
@ -107,23 +107,22 @@ class Catalog(kvs.Catalog):
|
|||
raise
|
||||
|
||||
def get_catalog(self, user_id, tenant_id, metadata=None):
|
||||
d = dict(six.iteritems(CONF))
|
||||
d.update({'tenant_id': tenant_id,
|
||||
'user_id': user_id})
|
||||
substitutions = dict(six.iteritems(CONF))
|
||||
substitutions.update({'tenant_id': tenant_id, 'user_id': user_id})
|
||||
|
||||
o = {}
|
||||
catalog = {}
|
||||
for region, region_ref in six.iteritems(self.templates):
|
||||
o[region] = {}
|
||||
catalog[region] = {}
|
||||
for service, service_ref in six.iteritems(region_ref):
|
||||
service_data = {}
|
||||
try:
|
||||
for k, v in six.iteritems(service_ref):
|
||||
service_data[k] = core.format_url(v, d)
|
||||
service_data[k] = core.format_url(v, substitutions)
|
||||
except exception.MalformedEndpoint:
|
||||
continue # this failure is already logged in format_url()
|
||||
o[region][service] = service_data
|
||||
catalog[region][service] = service_data
|
||||
|
||||
return o
|
||||
return catalog
|
||||
|
||||
|
||||
@versionutils.deprecated(
|
||||
|
|
|
@ -37,10 +37,16 @@ SHOULD_CACHE = cache.should_cache_fn('catalog')
|
|||
EXPIRATION_TIME = lambda: CONF.catalog.cache_time
|
||||
|
||||
|
||||
def format_url(url, data):
|
||||
"""Safely string formats a user-defined URL with the given data."""
|
||||
def format_url(url, substitutions):
|
||||
"""Formats a user-defined URL with the given substitutions.
|
||||
|
||||
:param string url: the URL to be formatted
|
||||
:param dict substitutions: the dictionary used for substitution
|
||||
:returns: a formatted URL
|
||||
|
||||
"""
|
||||
try:
|
||||
result = url.replace('$(', '%(') % data
|
||||
result = url.replace('$(', '%(') % substitutions
|
||||
except AttributeError:
|
||||
LOG.error(_('Malformed endpoint - %(url)r is not a string'),
|
||||
{"url": url})
|
||||
|
|
|
@ -26,8 +26,8 @@ CONF = config.CONF
|
|||
@dependency.requires('endpoint_filter_api')
|
||||
class EndpointFilterCatalog(sql.Catalog):
|
||||
def get_v3_catalog(self, user_id, project_id, metadata=None):
|
||||
d = dict(six.iteritems(CONF))
|
||||
d.update({'tenant_id': project_id, 'user_id': user_id})
|
||||
substitutions = dict(six.iteritems(CONF))
|
||||
substitutions.update({'tenant_id': project_id, 'user_id': user_id})
|
||||
|
||||
services = {}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class EndpointFilterCatalog(sql.Catalog):
|
|||
del endpoint['enabled']
|
||||
del endpoint['legacy_endpoint_id']
|
||||
endpoint['url'] = catalog_core.format_url(
|
||||
endpoint['url'], d)
|
||||
endpoint['url'], substitutions)
|
||||
# populate filtered endpoints
|
||||
if 'endpoints' in services[service_id]:
|
||||
service['endpoints'].append(endpoint)
|
||||
|
|
Loading…
Reference in New Issue