diff options
author | Ivan Kolodyazhny <e0ne@e0ne.info> | 2020-04-23 19:01:47 +0300 |
---|---|---|
committer | Pavlo Shchelokovskyy <pshchelokovskyy@mirantis.com> | 2020-04-29 08:13:25 +0000 |
commit | e1c05cffbe980807f170731028ca1a007fcc6f10 (patch) | |
tree | 301a96afb778a4bfc832c02e184e64e28d6919f6 /swiftclient/client.py | |
parent | 78386f552f13214d792e005879aaf16d57d43dc1 (diff) | |
download | python-swiftclient-e1c05cffbe980807f170731028ca1a007fcc6f10.tar.gz |
Fixed capability discovery endpoint hardcode
It fixes get_capabilities() method to process
correctly endpoints like: 'https://<ip>:<port>/v1',
'https://<ip>:<port>/swift/v1'.
Co-Authored-By: Daniel Cech <dcech@mirantis.com>
Change-Id: Ib4037d0b49da1bce959947100629370805f510d5
Closes-bug: #1712358
(cherry picked from commit 947c09f30c6b603e3f4da060bc913407b158a0ca)
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r-- | swiftclient/client.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index 448bb46..21cd7c4 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -45,6 +45,8 @@ AUTH_VERSIONS_V2 = ('2.0', '2', 2) AUTH_VERSIONS_V3 = ('3.0', '3', 3) USER_METADATA_TYPE = tuple('x-%s-meta-' % type_ for type_ in ('container', 'account', 'object')) +URI_PATTERN_INFO = re.compile(r'/info') +URI_PATTERN_VERSION = re.compile(r'\/v\d+\.?\d*(\/.*)?') try: from logging import NullHandler @@ -1927,11 +1929,22 @@ class Connection(object): response_dict=response_dict, headers=headers) - def get_capabilities(self, url=None): + def _map_url(self, url): url = url or self.url if not url: url, _ = self.get_auth() - parsed = urlparse(urljoin(url, '/info')) + scheme, netloc, path, params, query, fragment = urlparse(url) + if URI_PATTERN_VERSION.search(path): + path = URI_PATTERN_VERSION.sub('/info', path) + elif not URI_PATTERN_INFO.search(path): + if path.endswith('/'): + path += 'info' + else: + path += '/info' + return urlunparse((scheme, netloc, path, params, query, fragment)) + + def get_capabilities(self, url=None): + parsed = urlparse(self._map_url(url)) if not self.http_conn: self.http_conn = self.http_connection(url) return get_capabilities((parsed, self.http_conn[1])) |