summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-07-10 07:06:08 +0000
committerGerrit Code Review <review@openstack.org>2013-07-10 07:06:08 +0000
commitc460ebff0a6ab284d47e215f7f9156e73e7a40a9 (patch)
tree5010974e45df6b1fd601847791dc2308a49042fd
parent94d7c2318100bfdcaf42ecb2fb7ecd82ebfbef69 (diff)
parent1d4d51b218ed14b85d1e46d3e7142fb52ea179d5 (diff)
downloadpython-swiftclient-c460ebff0a6ab284d47e215f7f9156e73e7a40a9.tar.gz
Merge "Allow storage url override for both auth vers."
-rwxr-xr-xbin/swift9
-rw-r--r--doc/manpages/swift.11
-rw-r--r--doc/source/index.rst2
-rw-r--r--swiftclient/client.py40
-rw-r--r--test-requirements.txt1
-rw-r--r--tests/test_swiftclient.py32
-rw-r--r--tests/utils.py2
7 files changed, 62 insertions, 25 deletions
diff --git a/bin/swift b/bin/swift
index 8224b4d..4b3c068 100755
--- a/bin/swift
+++ b/bin/swift
@@ -1278,10 +1278,10 @@ Commands:
%(st_delete_help)s
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 \\
- --os-usernameuser --os-password password list
+ --os-username user --os-password password list
%%prog --os-auth-token 6ee5eb33efad4e45ab46806eac010566 \\
--os-storage-url https://10.1.5.2:8080/v1/AUTH_ced809b6a4baea7aeab61a \\
@@ -1358,8 +1358,9 @@ Examples:
default=environ.get('OS_STORAGE_URL'),
help='Openstack storage URL. '
'Defaults to env[OS_STORAGE_URL]. '
- 'Used with --os-auth-token to bypass the '
- 'usual username/password authentication.')
+ 'Overrides the storage url returned during auth. '
+ 'Will bypass authentication when used with '
+ '--os-auth-token.')
parser.add_option('--os_storage_url',
help=SUPPRESS_HELP)
parser.add_option('--os-region-name',
diff --git a/doc/manpages/swift.1 b/doc/manpages/swift.1
index 0fafbe7..8775eff 100644
--- a/doc/manpages/swift.1
+++ b/doc/manpages/swift.1
@@ -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 "-V 1|2 Authentication protocol version"
.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
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 9370236..55ec112 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1,7 +1,7 @@
SwiftClient Web
***************
- Copyright 2012 OpenStack, LLC.
+ Copyright 2013 OpenStack, LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/swiftclient/client.py b/swiftclient/client.py
index e95819f..03dad31 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -290,20 +290,19 @@ def get_auth(auth_url, user, key, **kwargs):
auth_version = kwargs.get('auth_version', '1')
os_options = kwargs.get('os_options', {})
+ storage_url, token = None, None
if auth_version in ['1.0', '1', 1]:
- return get_auth_1_0(auth_url,
- user,
- key,
- kwargs.get('snet'))
-
- if auth_version in ['2.0', '2', 2]:
-
+ storage_url, token = get_auth_1_0(auth_url,
+ user,
+ key,
+ kwargs.get('snet'))
+ elif auth_version in ['2.0', '2', 2]:
# We are allowing to specify a token/storage-url to re-use
# without having to re-authenticate.
if (os_options.get('object_storage_url') and
os_options.get('auth_token')):
- return(os_options.get('object_storage_url'),
- os_options.get('auth_token'))
+ return (os_options.get('object_storage_url'),
+ os_options.get('auth_token'))
# We are handling a special use case here when we were
# 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)
cacert = kwargs.get('cacert', None)
- (auth_url, token) = get_keystoneclient_2_0(auth_url, user,
- key, os_options,
- cacert=cacert,
- insecure=insecure)
- return (auth_url, token)
+ storage_url, token = get_keystoneclient_2_0(auth_url, user,
+ key, os_options,
+ cacert=cacert,
+ insecure=insecure)
+ else:
+ raise ClientException('Unknown auth_version %s specified.'
+ % auth_version)
- raise ClientException('Unknown auth_version %s specified.'
- % auth_version)
+ # Override storage url, if necessary
+ 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):
@@ -1086,9 +1090,7 @@ class Connection(object):
self.ssl_compression = ssl_compression
def get_auth(self):
- return get_auth(self.authurl,
- self.user,
- self.key,
+ return get_auth(self.authurl, self.user, self.key,
snet=self.snet,
auth_version=self.auth_version,
os_options=self.os_options,
diff --git a/test-requirements.txt b/test-requirements.txt
index 8534996..223dcf4 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -5,6 +5,7 @@ flake8==2.0
coverage
discover
+mock>=0.8.0
python-keystoneclient
sphinx>=1.1.2
testrepository>=0.0.13
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index 84d165b..e0fa400 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -14,6 +14,7 @@
# limitations under the License.
# TODO: More tests
+import mock
import httplib
import socket
import StringIO
@@ -123,8 +124,12 @@ class MockHttpTest(testtools.TestCase):
_orig_http_connection = c.http_connection
return_read = kwargs.get('return_read')
query_string = kwargs.get('query_string')
+ storage_url = kwargs.get('storage_url')
def wrapper(url, proxy=None, ssl_compression=True):
+ if storage_url:
+ self.assertEqual(storage_url, url)
+
parsed, _conn = _orig_http_connection(url, proxy=proxy)
conn = fake_http_connect(*args, **kwargs)()
@@ -649,6 +654,33 @@ class TestConnection(MockHttpTest):
conn = c.Connection(**args)
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):
c.http_connection = self.fake_http_connection(500)
diff --git a/tests/utils.py b/tests/utils.py
index 8b5fbb2..07776b1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -38,7 +38,7 @@ def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs):
from swiftclient import client as c
raise c.ClientException("unverified-certificate")
- return ("http://url/", "token")
+ return "http://url/", "token"
return fake_get_keystoneclient_2_0