Parcourir la source

Add user/project domain params to RequestContext.

Add an individual parameter for both the name and ID of the domain
for both the user and project when using Keystone v3.
Nashwan Azhari il y a 8 ans
Parent
commit
ffc54cd351
3 fichiers modifiés avec 48 ajouts et 13 suppressions
  1. 2 2
      coriolis/api/middleware/auth.py
  2. 18 6
      coriolis/context.py
  3. 28 5
      coriolis/keystone.py

+ 2 - 2
coriolis/api/middleware/auth.py

@@ -58,8 +58,8 @@ class CoriolisKeystoneContext(wsgi.Middleware):
         ctx = context.RequestContext(user,
         ctx = context.RequestContext(user,
                                      tenant,
                                      tenant,
                                      project_name=project_name,
                                      project_name=project_name,
-                                     project_domain=project_domain_name,
-                                     user_domain=user_domain_name,
+                                     project_domain_name=project_domain_name,
+                                     user_domain_name=user_domain_name,
                                      roles=roles,
                                      roles=roles,
                                      auth_token=auth_token,
                                      auth_token=auth_token,
                                      remote_address=remote_address,
                                      remote_address=remote_address,

+ 18 - 6
coriolis/context.py

@@ -11,16 +11,23 @@ class RequestContext(context.RequestContext):
     def __init__(self, user, tenant, is_admin=None,
     def __init__(self, user, tenant, is_admin=None,
                  roles=None, project_name=None, remote_address=None,
                  roles=None, project_name=None, remote_address=None,
                  timestamp=None, request_id=None, auth_token=None,
                  timestamp=None, request_id=None, auth_token=None,
-                 overwrite=True, domain=None, user_domain=None,
-                 project_domain=None, show_deleted=None, trust_id=None,
+                 overwrite=True, domain_name=None, domain_id=None,
+                 user_domain_name=None, user_domain_id=None,
+                 project_domain_name=None, project_domain_id=None,
+                 show_deleted=None, trust_id=None,
                  delete_trust_id=False, **kwargs):
                  delete_trust_id=False, **kwargs):
 
 
         super(RequestContext, self).__init__(auth_token=auth_token,
         super(RequestContext, self).__init__(auth_token=auth_token,
                                              user=user,
                                              user=user,
                                              tenant=tenant,
                                              tenant=tenant,
-                                             domain=domain,
-                                             user_domain=user_domain,
-                                             project_domain=project_domain,
+                                             domain_name=domain_name,
+                                             domain_id=domain_id,
+                                             user_domain_name=user_domain_name,
+                                             user_domain_id=user_domain_id,
+                                             project_domain_name=(
+                                                 project_domain_name),
+                                             project_domain_id=(
+                                                 project_domain_id),
                                              is_admin=is_admin,
                                              is_admin=is_admin,
                                              show_deleted=show_deleted,
                                              show_deleted=show_deleted,
                                              request_id=request_id,
                                              request_id=request_id,
@@ -41,7 +48,12 @@ class RequestContext(context.RequestContext):
         result['user'] = self.user
         result['user'] = self.user
         result['tenant'] = self.tenant
         result['tenant'] = self.tenant
         result['project_name'] = self.project_name
         result['project_name'] = self.project_name
-        result['domain'] = self.domain
+        result['domain_id'] = self.domain_id
+        result['domain_name'] = self.domain_name
+        result['user_domain_id'] = self.user_domain_id
+        result['user_domain_name'] = self.user_domain_name
+        result['project_domain_id'] = self.project_domain_id
+        result['project_domain_name'] = self.project_domain_name
         result['roles'] = self.roles
         result['roles'] = self.roles
         result['remote_address'] = self.remote_address
         result['remote_address'] = self.remote_address
         result['timestamp'] = self.timestamp.isoformat()
         result['timestamp'] = self.timestamp.isoformat()

+ 28 - 5
coriolis/keystone.py

@@ -50,7 +50,7 @@ def create_trust(ctxt):
         auth_url=trusts_auth_plugin.auth_url,
         auth_url=trusts_auth_plugin.auth_url,
         token=ctxt.auth_token,
         token=ctxt.auth_token,
         project_name=ctxt.project_name,
         project_name=ctxt.project_name,
-        project_domain_name=ctxt.project_domain)
+        project_domain_name=ctxt.project_domain_name)
     session = ks_session.Session(
     session = ks_session.Session(
         auth=auth, verify=not CONF.keystone.allow_untrusted)
         auth=auth, verify=not CONF.keystone.allow_untrusted)
 
 
@@ -148,12 +148,35 @@ def create_keystone_session(ctxt, connection_info={}):
             plugin_name = "v3" + plugin_name
             plugin_name = "v3" + plugin_name
 
 
             project_domain_name = connection_info.get(
             project_domain_name = connection_info.get(
-                "project_domain_name", ctxt.project_domain)
-            plugin_args["project_domain_name"] = project_domain_name
+                "project_domain_name", ctxt.project_domain_name)
+            # NOTE: only set the kwarg if proper argument is provided:
+            if project_domain_name:
+                plugin_args["project_domain_name"] = project_domain_name
+
+            project_domain_id = connection_info.get(
+                "project_domain_id", ctxt.project_domain_id)
+            if project_domain_id:
+                plugin_args["project_domain_id"] = project_domain_id
+
+            if not project_domain_name and not project_domain_id:
+                raise exception.CoriolisException(
+                    "Either 'project_domain_name' or 'project_domain_id' is "
+                    "required for Keystone v3 Auth.")
 
 
             user_domain_name = connection_info.get(
             user_domain_name = connection_info.get(
-                "user_domain_name", ctxt.user_domain)
-            plugin_args["user_domain_name"] = user_domain_name
+                "user_domain_name", ctxt.user_domain_name)
+            if user_domain_name:
+                plugin_args["user_domain_name"] = user_domain_name
+
+            user_domain_id = connection_info.get(
+                "user_domain_id", ctxt.user_domain_id)
+            if user_domain_id:
+                plugin_args["user_domain_id"] = user_domain_id
+
+            if not user_domain_name and not user_domain_id:
+                raise exception.CoriolisException(
+                    "Either 'user_domain_name' or 'user_domain_id' is "
+                    "required for Keystone v3 Auth.")
 
 
         loader = loading.get_plugin_loader(plugin_name)
         loader = loading.get_plugin_loader(plugin_name)
         auth = loader.load_from_options(**plugin_args)
         auth = loader.load_from_options(**plugin_args)