]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Allow authentication to Nova with a Keystone token
authorZane Bitter <zbitter@redhat.com>
Tue, 9 Oct 2012 10:06:44 +0000 (12:06 +0200)
committerZane Bitter <zbitter@redhat.com>
Tue, 9 Oct 2012 10:36:37 +0000 (12:36 +0200)
Change-Id: I3ca90169559cc167ff51db5fe47ceec8c917f04b
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/auth.py

index 980ea04259b5a81ab4ec4d0126903a89fe2b6437..414769e47cc85612ee6c219edd105afc52562175 100644 (file)
@@ -69,29 +69,25 @@ def authenticate(con, service_type='orchestration', service_name='heat'):
         username in the context so we can use it to key in the database.
     """
 
-    if con.password is not None:
-        try:
-            # Workaround for issues with python-keyring, need no_cache=True
-            # ref https://bugs.launchpad.net/python-novaclient/+bug/1020238
-            # TODO(shardy): May be able to remove when the bug above is fixed
-            nova = client.Client(username=con.username,
-                                api_key=con.password,
-                                project_id=con.tenant,
-                                auth_url=con.auth_url,
-                                service_type=service_type,
-                                service_name=service_name,
-                                no_cache=True)
-        except TypeError:
-            # for compatibility with essex, which doesn't have no_cache=True
-            # TODO(shardy): remove when we no longer support essex
-            nova = client.Client(username=con.username,
-                                api_key=con.password,
-                                project_id=con.tenant,
-                                auth_url=con.auth_url,
-                                service_type=service_type,
-                                service_name=service_name)
-        nova.authenticate()
-        return nova
+    args = {
+        'project_id': con.tenant,
+        'auth_url': con.auth_url,
+        'service_type': service_type,
+        'service_name': service_name,
+    }
+
+    if con.auth_token is not None:
+        credentials = {
+            'username': con.service_user,
+            'api_key': con.service_password,
+            'proxy_token': con.auth_token,
+            'proxy_tenant_id': con.tenant_id,
+        }
+    elif con.password is not None:
+        credentials = {
+            'username': con.username,
+            'api_key': con.password,
+        }
     else:
         # We'll have to do AWS style auth which is more complex.
         # First step is to get a token from the AWS creds.
@@ -122,25 +118,23 @@ def authenticate(con, service_type='orchestration', service_name='heat'):
             logger.info("AWS authentication failure.")
             raise exception.AuthorizationFailure()
 
-        try:
-            # Workaround for issues with python-keyring, need no_cache=True
-            # ref https://bugs.launchpad.net/python-novaclient/+bug/1020238
-            # TODO(shardy): May be able to remove when the bug above is fixed
-            nova = client.Client(con.service_user, con.service_password,
-                                 con.tenant, con.auth_url,
-                                 proxy_token=token_id,
-                                 proxy_tenant_id=con.tenant_id,
-                                 service_type=service_type,
-                                 service_name=service_name,
-                                 no_cache=True)
-        except TypeError:
-            # for compatibility with essex, which doesn't have no_cache=True
-            # TODO(shardy): remove when we no longer support essex
-            nova = client.Client(con.service_user, con.service_password,
-                                 con.tenant, con.auth_url,
-                                 proxy_token=token_id,
-                                 proxy_tenant_id=con.tenant_id,
-                                 service_type=service_type,
-                                 service_name=service_name)
-        nova.authenticate()
-        return nova
+        credentials = {
+            'username': con.service_user,
+            'api_key': con.service_password,
+            'proxy_token': token_id,
+            'proxy_tenant_id': con.tenant_id,
+        }
+
+    args.update(credentials)
+    try:
+        # Workaround for issues with python-keyring, need no_cache=True
+        # ref https://bugs.launchpad.net/python-novaclient/+bug/1020238
+        # TODO(shardy): May be able to remove when the bug above is fixed
+        nova = client.Client(no_cache=True, **args)
+    except TypeError:
+        # for compatibility with essex, which doesn't have no_cache=True
+        # TODO(shardy): remove when we no longer support essex
+        nova = client.Client(**args)
+
+    nova.authenticate()
+    return nova