summaryrefslogtreecommitdiff
path: root/keystoneclient/discover.py
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@redhat.com>2014-04-28 12:20:46 +1000
committerJamie Lennox <jamielennox@redhat.com>2014-09-16 10:41:55 +1000
commitec57b35bc8edb933fe259db2b96c393874166dc0 (patch)
tree13d73119da90341a28ab2b340b0de3e95e3a1624 /keystoneclient/discover.py
parent3305c7be4b726de4dcc889006d0be30eb46d3ad9 (diff)
downloadpython-keystoneclient-ec57b35bc8edb933fe259db2b96c393874166dc0.tar.gz
Versioned Endpoint hack for Sessions
To maintain compatibility we must allow people to specify a versioned URL in the service catalog but allow the plugins to return a different URL to users. We need this to be a general approach as other services will likely have a similar problem with their catalog. The expectation here is that a client will register the catalog hack at import time rather than for every request. Closes-Bug: #1335726 Change-Id: I244f0ec3acca39fd1b2a2c5883abc06ec10eddc7
Diffstat (limited to 'keystoneclient/discover.py')
-rw-r--r--keystoneclient/discover.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/keystoneclient/discover.py b/keystoneclient/discover.py
index 07de97d..982683a 100644
--- a/keystoneclient/discover.py
+++ b/keystoneclient/discover.py
@@ -266,3 +266,34 @@ class Discover(_discover.Discover):
"""
version_data = self._calculate_version(version, unstable)
return self._create_client(version_data, **kwargs)
+
+
+def add_catalog_discover_hack(service_type, old, new):
+ """Adds a version removal rule for a particular service.
+
+ Originally deployments of OpenStack would contain a versioned endpoint in
+ the catalog for different services. E.g. an identity service might look
+ like ``http://localhost:5000/v2.0``. This is a problem when we want to use
+ a different version like v3.0 as there is no way to tell where it is
+ located. We cannot simply change all service catalogs either so there must
+ be a way to handle the older style of catalog.
+
+ This function adds a rule for a given service type that if part of the URL
+ matches a given regular expression in *old* then it will be replaced with
+ the *new* value. This will replace all instances of old with new. It should
+ therefore contain a regex anchor.
+
+ For example the included rule states::
+
+ add_catalog_version_hack('identity', re.compile('/v2.0/?$'), '/')
+
+ so if the catalog retrieves an *identity* URL that ends with /v2.0 or
+ /v2.0/ then it should replace it simply with / to fix the user's catalog.
+
+ :param str service_type: The service type as defined in the catalog that
+ the rule will apply to.
+ :param re.RegexObject old: The regular expression to search for and replace
+ if found.
+ :param str new: The new string to replace the pattern with.
+ """
+ _discover._VERSION_HACKS.add_discover_hack(service_type, old, new)