Merge "Allow storage url override for both auth vers."
This commit is contained in:
commit
c460ebff0a
@ -1278,10 +1278,10 @@ Commands:
|
|||||||
%(st_delete_help)s
|
%(st_delete_help)s
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
%%prog -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat
|
%%prog -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat -v
|
||||||
|
|
||||||
%%prog --os-auth-url https://api.example.com/v2.0 --os-tenant-name tenant \\
|
%%prog --os-auth-url https://api.example.com/v2.0 --os-tenant-name tenant \\
|
||||||
--os-usernameuser --os-password password list
|
--os-username user --os-password password list
|
||||||
|
|
||||||
%%prog --os-auth-token 6ee5eb33efad4e45ab46806eac010566 \\
|
%%prog --os-auth-token 6ee5eb33efad4e45ab46806eac010566 \\
|
||||||
--os-storage-url https://10.1.5.2:8080/v1/AUTH_ced809b6a4baea7aeab61a \\
|
--os-storage-url https://10.1.5.2:8080/v1/AUTH_ced809b6a4baea7aeab61a \\
|
||||||
@ -1358,8 +1358,9 @@ Examples:
|
|||||||
default=environ.get('OS_STORAGE_URL'),
|
default=environ.get('OS_STORAGE_URL'),
|
||||||
help='Openstack storage URL. '
|
help='Openstack storage URL. '
|
||||||
'Defaults to env[OS_STORAGE_URL]. '
|
'Defaults to env[OS_STORAGE_URL]. '
|
||||||
'Used with --os-auth-token to bypass the '
|
'Overrides the storage url returned during auth. '
|
||||||
'usual username/password authentication.')
|
'Will bypass authentication when used with '
|
||||||
|
'--os-auth-token.')
|
||||||
parser.add_option('--os_storage_url',
|
parser.add_option('--os_storage_url',
|
||||||
help=SUPPRESS_HELP)
|
help=SUPPRESS_HELP)
|
||||||
parser.add_option('--os-region-name',
|
parser.add_option('--os-region-name',
|
||||||
|
@ -105,6 +105,7 @@ will be deleted as well, unless you specify the --leave-segments option.
|
|||||||
.IP "-U USER, --user=USER User name for obtaining an auth token"
|
.IP "-U USER, --user=USER User name for obtaining an auth token"
|
||||||
.IP "-V 1|2 Authentication protocol version"
|
.IP "-V 1|2 Authentication protocol version"
|
||||||
.IP "-K KEY, --key=KEY Key for obtaining an auth token"
|
.IP "-K KEY, --key=KEY Key for obtaining an auth token"
|
||||||
|
.IP "--os-storage-url=URL Use this instead of URL returned from auth"
|
||||||
|
|
||||||
.PD
|
.PD
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
SwiftClient Web
|
SwiftClient Web
|
||||||
***************
|
***************
|
||||||
|
|
||||||
Copyright 2012 OpenStack, LLC.
|
Copyright 2013 OpenStack, LLC.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -290,20 +290,19 @@ def get_auth(auth_url, user, key, **kwargs):
|
|||||||
auth_version = kwargs.get('auth_version', '1')
|
auth_version = kwargs.get('auth_version', '1')
|
||||||
os_options = kwargs.get('os_options', {})
|
os_options = kwargs.get('os_options', {})
|
||||||
|
|
||||||
|
storage_url, token = None, None
|
||||||
if auth_version in ['1.0', '1', 1]:
|
if auth_version in ['1.0', '1', 1]:
|
||||||
return get_auth_1_0(auth_url,
|
storage_url, token = get_auth_1_0(auth_url,
|
||||||
user,
|
user,
|
||||||
key,
|
key,
|
||||||
kwargs.get('snet'))
|
kwargs.get('snet'))
|
||||||
|
elif auth_version in ['2.0', '2', 2]:
|
||||||
if auth_version in ['2.0', '2', 2]:
|
|
||||||
|
|
||||||
# We are allowing to specify a token/storage-url to re-use
|
# We are allowing to specify a token/storage-url to re-use
|
||||||
# without having to re-authenticate.
|
# without having to re-authenticate.
|
||||||
if (os_options.get('object_storage_url') and
|
if (os_options.get('object_storage_url') and
|
||||||
os_options.get('auth_token')):
|
os_options.get('auth_token')):
|
||||||
return(os_options.get('object_storage_url'),
|
return (os_options.get('object_storage_url'),
|
||||||
os_options.get('auth_token'))
|
os_options.get('auth_token'))
|
||||||
|
|
||||||
# We are handling a special use case here when we were
|
# We are handling a special use case here when we were
|
||||||
# allowing specifying the account/tenant_name with the -U
|
# allowing specifying the account/tenant_name with the -U
|
||||||
@ -322,14 +321,19 @@ def get_auth(auth_url, user, key, **kwargs):
|
|||||||
|
|
||||||
insecure = kwargs.get('insecure', False)
|
insecure = kwargs.get('insecure', False)
|
||||||
cacert = kwargs.get('cacert', None)
|
cacert = kwargs.get('cacert', None)
|
||||||
(auth_url, token) = get_keystoneclient_2_0(auth_url, user,
|
storage_url, token = get_keystoneclient_2_0(auth_url, user,
|
||||||
key, os_options,
|
key, os_options,
|
||||||
cacert=cacert,
|
cacert=cacert,
|
||||||
insecure=insecure)
|
insecure=insecure)
|
||||||
return (auth_url, token)
|
else:
|
||||||
|
raise ClientException('Unknown auth_version %s specified.'
|
||||||
|
% auth_version)
|
||||||
|
|
||||||
raise ClientException('Unknown auth_version %s specified.'
|
# Override storage url, if necessary
|
||||||
% auth_version)
|
if os_options.get('object_storage_url'):
|
||||||
|
return os_options['object_storage_url'], token
|
||||||
|
else:
|
||||||
|
return storage_url, token
|
||||||
|
|
||||||
|
|
||||||
def store_response(resp, response_dict):
|
def store_response(resp, response_dict):
|
||||||
@ -1086,9 +1090,7 @@ class Connection(object):
|
|||||||
self.ssl_compression = ssl_compression
|
self.ssl_compression = ssl_compression
|
||||||
|
|
||||||
def get_auth(self):
|
def get_auth(self):
|
||||||
return get_auth(self.authurl,
|
return get_auth(self.authurl, self.user, self.key,
|
||||||
self.user,
|
|
||||||
self.key,
|
|
||||||
snet=self.snet,
|
snet=self.snet,
|
||||||
auth_version=self.auth_version,
|
auth_version=self.auth_version,
|
||||||
os_options=self.os_options,
|
os_options=self.os_options,
|
||||||
|
@ -5,6 +5,7 @@ flake8==2.0
|
|||||||
|
|
||||||
coverage
|
coverage
|
||||||
discover
|
discover
|
||||||
|
mock>=0.8.0
|
||||||
python-keystoneclient
|
python-keystoneclient
|
||||||
sphinx>=1.1.2
|
sphinx>=1.1.2
|
||||||
testrepository>=0.0.13
|
testrepository>=0.0.13
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# TODO: More tests
|
# TODO: More tests
|
||||||
|
import mock
|
||||||
import httplib
|
import httplib
|
||||||
import socket
|
import socket
|
||||||
import StringIO
|
import StringIO
|
||||||
@ -123,8 +124,12 @@ class MockHttpTest(testtools.TestCase):
|
|||||||
_orig_http_connection = c.http_connection
|
_orig_http_connection = c.http_connection
|
||||||
return_read = kwargs.get('return_read')
|
return_read = kwargs.get('return_read')
|
||||||
query_string = kwargs.get('query_string')
|
query_string = kwargs.get('query_string')
|
||||||
|
storage_url = kwargs.get('storage_url')
|
||||||
|
|
||||||
def wrapper(url, proxy=None, ssl_compression=True):
|
def wrapper(url, proxy=None, ssl_compression=True):
|
||||||
|
if storage_url:
|
||||||
|
self.assertEqual(storage_url, url)
|
||||||
|
|
||||||
parsed, _conn = _orig_http_connection(url, proxy=proxy)
|
parsed, _conn = _orig_http_connection(url, proxy=proxy)
|
||||||
conn = fake_http_connect(*args, **kwargs)()
|
conn = fake_http_connect(*args, **kwargs)()
|
||||||
|
|
||||||
@ -649,6 +654,33 @@ class TestConnection(MockHttpTest):
|
|||||||
conn = c.Connection(**args)
|
conn = c.Connection(**args)
|
||||||
self.assertEquals(type(conn), c.Connection)
|
self.assertEquals(type(conn), c.Connection)
|
||||||
|
|
||||||
|
def test_storage_url_override(self):
|
||||||
|
static_url = 'http://overridden.storage.url'
|
||||||
|
c.http_connection = self.fake_http_connection(
|
||||||
|
200, body='[]', storage_url=static_url)
|
||||||
|
conn = c.Connection('http://auth.url/', 'some_user', 'some_key',
|
||||||
|
os_options={
|
||||||
|
'object_storage_url': static_url})
|
||||||
|
method_signatures = (
|
||||||
|
(conn.head_account, []),
|
||||||
|
(conn.get_account, []),
|
||||||
|
(conn.head_container, ('asdf',)),
|
||||||
|
(conn.get_container, ('asdf',)),
|
||||||
|
(conn.put_container, ('asdf',)),
|
||||||
|
(conn.delete_container, ('asdf',)),
|
||||||
|
(conn.head_object, ('asdf', 'asdf')),
|
||||||
|
(conn.get_object, ('asdf', 'asdf')),
|
||||||
|
(conn.put_object, ('asdf', 'asdf', 'asdf')),
|
||||||
|
(conn.post_object, ('asdf', 'asdf', {})),
|
||||||
|
(conn.delete_object, ('asdf', 'asdf')),
|
||||||
|
)
|
||||||
|
|
||||||
|
with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth:
|
||||||
|
mock_get_auth.return_value = ('http://auth.storage.url', 'tToken')
|
||||||
|
|
||||||
|
for method, args in method_signatures:
|
||||||
|
method(*args)
|
||||||
|
|
||||||
def test_retry(self):
|
def test_retry(self):
|
||||||
c.http_connection = self.fake_http_connection(500)
|
c.http_connection = self.fake_http_connection(500)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs):
|
|||||||
from swiftclient import client as c
|
from swiftclient import client as c
|
||||||
raise c.ClientException("unverified-certificate")
|
raise c.ClientException("unverified-certificate")
|
||||||
|
|
||||||
return ("http://url/", "token")
|
return "http://url/", "token"
|
||||||
return fake_get_keystoneclient_2_0
|
return fake_get_keystoneclient_2_0
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user