diff options
author | Darrell Bishop <darrell@swiftstack.com> | 2013-06-28 21:26:54 -0700 |
---|---|---|
committer | Darrell Bishop <darrell@swiftstack.com> | 2013-07-05 14:12:59 -0500 |
commit | 1d4d51b218ed14b85d1e46d3e7142fb52ea179d5 (patch) | |
tree | 1fdbf15ee1f10c10a72fc4d49d6e27addc19de89 /swiftclient/client.py | |
parent | 6f7458a2903f6be2bf3271825e837d30b4e9f737 (diff) | |
download | python-swiftclient-1d4d51b218ed14b85d1e46d3e7142fb52ea179d5.tar.gz |
Allow storage url override for both auth vers.
When --os-storage-url is specified on the command-line to bin/swift, it
will override the used storage URL regardless of authentication for both
authentication version 1 and version 2. This can be used to bypass a
load-balancer to hit a specific proxy server for testing/debugging
purposes.
Within the client library, this feature is accessed by passing the
desired storage URL into swiftclient.client.Conection.__init__() via the
os_options keyword argument. For example:
conn = Connection(auth_url, user, key, os_options={
'object_storage_url': 'http://overridden.storage.url/AUTH_foo'})
This patch also adds a dependency on mock>=0.8.0, which is the same as
openstack/swift.
Change-Id: Id2a36ed6abffd65e7762b6beea5bbfc6c036e848
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r-- | swiftclient/client.py | 40 |
1 files changed, 21 insertions, 19 deletions
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, |