Merge "Fixed capability discovery endpoint hardcode"
This commit is contained in:
commit
eecdcdefbc
@ -45,6 +45,8 @@ AUTH_VERSIONS_V2 = ('2.0', '2', 2)
|
|||||||
AUTH_VERSIONS_V3 = ('3.0', '3', 3)
|
AUTH_VERSIONS_V3 = ('3.0', '3', 3)
|
||||||
USER_METADATA_TYPE = tuple('x-%s-meta-' % type_ for type_ in
|
USER_METADATA_TYPE = tuple('x-%s-meta-' % type_ for type_ in
|
||||||
('container', 'account', 'object'))
|
('container', 'account', 'object'))
|
||||||
|
URI_PATTERN_INFO = re.compile(r'/info')
|
||||||
|
URI_PATTERN_VERSION = re.compile(r'\/v\d+\.?\d*(\/.*)?')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from logging import NullHandler
|
from logging import NullHandler
|
||||||
@ -1935,11 +1937,22 @@ class Connection(object):
|
|||||||
response_dict=response_dict,
|
response_dict=response_dict,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
def get_capabilities(self, url=None):
|
def _map_url(self, url):
|
||||||
url = url or self.url
|
url = url or self.url
|
||||||
if not url:
|
if not url:
|
||||||
url, _ = self.get_auth()
|
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:
|
if not self.http_conn:
|
||||||
self.http_conn = self.http_connection(url)
|
self.http_conn = self.http_connection(url)
|
||||||
return get_capabilities((parsed, self.http_conn[1]))
|
return get_capabilities((parsed, self.http_conn[1]))
|
||||||
|
@ -2035,6 +2035,38 @@ class TestConnection(MockHttpTest):
|
|||||||
self.assertEqual(request['headers']['x-auth-token'],
|
self.assertEqual(request['headers']['x-auth-token'],
|
||||||
'tToken')
|
'tToken')
|
||||||
|
|
||||||
|
def test_url_mapping(self):
|
||||||
|
conn = c.Connection()
|
||||||
|
uri_versions = {
|
||||||
|
'http://storage.test.com':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/v1':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/v1/':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/swift':
|
||||||
|
'http://storage.test.com/swift/info',
|
||||||
|
'http://storage.test.com/swift/':
|
||||||
|
'http://storage.test.com/swift/info',
|
||||||
|
'http://storage.test.com/v1.0':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/swift/v1.0':
|
||||||
|
'http://storage.test.com/swift/info',
|
||||||
|
'http://storage.test.com/v111':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/v111/test':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/v1/test':
|
||||||
|
'http://storage.test.com/info',
|
||||||
|
'http://storage.test.com/swift/v1.0/test':
|
||||||
|
'http://storage.test.com/swift/info',
|
||||||
|
'http://storage.test.com/v1.0/test':
|
||||||
|
'http://storage.test.com/info'}
|
||||||
|
for uri_k, uri_v in uri_versions.items():
|
||||||
|
self.assertEqual(conn._map_url(uri_k), uri_v)
|
||||||
|
|
||||||
def test_get_capabilities(self):
|
def test_get_capabilities(self):
|
||||||
conn = c.Connection()
|
conn = c.Connection()
|
||||||
with mock.patch('swiftclient.client.get_capabilities') as get_cap:
|
with mock.patch('swiftclient.client.get_capabilities') as get_cap:
|
||||||
|
Loading…
Reference in New Issue
Block a user