diff options
| author | Brian Waldon <bcwaldon@gmail.com> | 2012-07-26 16:10:42 -0700 |
|---|---|---|
| committer | Brian Waldon <bcwaldon@gmail.com> | 2012-08-01 20:41:41 -0700 |
| commit | 2541f3ce840492555160f8f31d775f443628fe9a (patch) | |
| tree | 3bfad9a7f6a34f411d58361267557e863d0fc3e6 /glanceclient/shell.py | |
| parent | ba83562b24f735c1ae9b9e5edefe8f2f1466b233 (diff) | |
| download | python-glanceclient-2541f3ce840492555160f8f31d775f443628fe9a.tar.gz | |
Allow CLI opts to override auth token and endpoint
Previously, both --os-auth-token and --os-image-url had to be
provided in order for either of them to be used in any API requests.
This breaks the tie between them and allows a user to override
either the auth token or the endpoint returned by Keystone independently
of one another.
Fixes bug 1029586
Change-Id: I8b81be723286c546d9cbd97c8b7d7aa89c03b2d4
Diffstat (limited to 'glanceclient/shell.py')
| -rw-r--r-- | glanceclient/shell.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 043d501..bee3700 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -193,7 +193,7 @@ class OpenStackImagesShell(object): endpoint = '/'.join(url_bits[:-1]) return endpoint - def _authenticate(self, **kwargs): + def _get_ksclient(self, **kwargs): """Get an endpoint and auth token from Keystone. :param username: name of user @@ -202,19 +202,19 @@ class OpenStackImagesShell(object): :param tenant_name: name of tenant :param auth_url: endpoint to authenticate against """ - _ksclient = ksclient.Client(username=kwargs.get('username'), - password=kwargs.get('password'), - tenant_id=kwargs.get('tenant_id'), - tenant_name=kwargs.get('tenant_name'), - auth_url=kwargs.get('auth_url'), - insecure=kwargs.get('insecure')) - service_type = kwargs.get('service_type') or 'image' - endpoint_type = kwargs.get('endpoint_type') or 'publicURL' - endpoint = _ksclient.service_catalog.url_for( - service_type=service_type, - endpoint_type=endpoint_type) - endpoint = self._strip_version(endpoint) - return (endpoint, _ksclient.auth_token) + return ksclient.Client(username=kwargs.get('username'), + password=kwargs.get('password'), + tenant_id=kwargs.get('tenant_id'), + tenant_name=kwargs.get('tenant_name'), + auth_url=kwargs.get('auth_url'), + insecure=kwargs.get('insecure')) + + def _get_endpoint(self, client, **kwargs): + """Get an endpoint using the provided keystone client.""" + endpoint = client.service_catalog.url_for( + service_type=kwargs.get('service_type') or 'image', + endpoint_type=kwargs.get('endpoint_type') or 'publicURL') + return self._strip_version(endpoint) def main(self, argv): # Parse args once to find version @@ -276,7 +276,11 @@ class OpenStackImagesShell(object): 'endpoint_type': args.os_endpoint_type, 'insecure': args.insecure } - endpoint, token = self._authenticate(**kwargs) + _ksclient = self._get_ksclient(**kwargs) + token = args.os_auth_token or _ksclient.auth_token + + endpoint = args.os_image_url or \ + self._get_endpoint(_ksclient, **kwargs) client = glanceclient.Client(api_version, endpoint, |
