Adding filter to ProjectTopicAuth 78/7478/4
authorEduardo Sousa <eduardo.sousa@canonical.com>
Mon, 20 May 2019 14:58:41 +0000 (15:58 +0100)
committerEduardo Sousa <eduardo.sousa@canonical.com>
Tue, 21 May 2019 13:35:54 +0000 (14:35 +0100)
Change-Id: I0bf340085f703540f810a969db368431d8b4774d
Signed-off-by: Eduardo Sousa <eduardo.sousa@canonical.com>
osm_nbi/admin_topics.py
osm_nbi/authconn.py
osm_nbi/authconn_keystone.py

index 9f2eb68..2bca416 100644 (file)
@@ -673,7 +673,10 @@ class ProjectTopicAuth(ProjectTopic):
         :param filter_q: filter of data to be applied
         :return: The list, it can be empty if no one match the filter.
         """
-        return self.auth.get_project_list()
+        if not filter_q:
+            filter_q = {}
+
+        return self.auth.get_project_list(filter_q)
 
     def delete(self, session, _id, dry_run=False):
         """
index 8f2f128..df5c700 100644 (file)
@@ -236,10 +236,11 @@ class Authconn:
         """
         raise AuthconnNotImplementedException("Should have implemented this")
 
-    def get_project_list(self):
+    def get_project_list(self, filter_q={}):
         """
         Get all the projects.
 
+        :param filter_q: dictionary to filter project list.
         :return: list of projects
         """
         raise AuthconnNotImplementedException("Should have implemented this")
index e917306..b0cab0c 100644 (file)
@@ -347,10 +347,11 @@ class AuthconnKeystone(Authconn):
             self.logger.exception("Error during role deletion using keystone")
             raise AuthconnOperationException("Error during role deletion using Keystone")
 
-    def get_project_list(self):
+    def get_project_list(self, filter_q={}):
         """
         Get all the projects.
 
+        :param filter_q: dictionary to filter project list.
         :return: list of projects
         """
         try:
@@ -360,6 +361,14 @@ class AuthconnKeystone(Authconn):
                 "_id": project.id
             } for project in projects if project.name != self.admin_project]
 
+            allowed_fields = ["_id", "name"]
+            for key in filter_q.keys():
+                if key not in allowed_fields:
+                    continue
+
+                projects = [project for project in projects
+                            if filter_q[key] == project[key]]
+
             return projects
         except ClientException:
             self.logger.exception("Error during user project listing using keystone")