Adding filter to UserTopicAuth 77/7477/5
authorEduardo Sousa <eduardo.sousa@canonical.com>
Mon, 20 May 2019 14:41:54 +0000 (15:41 +0100)
committerEduardo Sousa <eduardo.sousa@canonical.com>
Mon, 20 May 2019 16:40:34 +0000 (17:40 +0100)
Change-Id: I3ff383f6f461a22969aa490681d4b4964894d36b
Signed-off-by: Eduardo Sousa <eduardo.sousa@canonical.com>
osm_nbi/admin_topics.py
osm_nbi/authconn.py
osm_nbi/authconn_keystone.py

index d894a09..9f2eb68 100644 (file)
@@ -559,7 +559,10 @@ class UserTopicAuth(UserTopic):
         :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_user_list()
+        if not filter_q:
+            filter_q = {}
+
+        return self.auth.get_user_list(filter_q)
 
     def delete(self, session, _id, dry_run=False):
         """
index 0ffaad8..8f2f128 100644 (file)
@@ -184,10 +184,11 @@ class Authconn:
         """
         raise AuthconnNotImplementedException("Should have implemented this")
 
-    def get_user_list(self):
+    def get_user_list(self, filter_q={}):
         """
         Get user list.
 
+        :param filter_q: dictionary to filter user list.
         :return: returns a list of users.
         """
 
index 54442c8..e917306 100644 (file)
@@ -247,10 +247,11 @@ class AuthconnKeystone(Authconn):
             self.logger.exception("Error during user deletion using keystone")
             raise AuthconnOperationException("Error during user deletion using Keystone")
 
-    def get_user_list(self):
+    def get_user_list(self, filter_q={}):
         """
         Get user list.
 
+        :param filter_q: dictionary to filter user list.
         :return: returns a list of users.
         """
         try:
@@ -260,6 +261,14 @@ class AuthconnKeystone(Authconn):
                 "_id": user.id
             } for user in users if user.name != self.admin_username]
 
+            allowed_fields = ["_id", "username"]
+            for key in filter_q.keys():
+                if key not in allowed_fields:
+                    continue
+
+                users = [user for user in users 
+                         if filter_q[key] == user[key]]
+
             for user in users:
                 projects = self.keystone.projects.list(user=user["_id"])
                 projects = [{