Adding filter to UserTopicAuth

Change-Id: I3ff383f6f461a22969aa490681d4b4964894d36b
Signed-off-by: Eduardo Sousa <eduardo.sousa@canonical.com>
diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py
index d894a09..9f2eb68 100644
--- a/osm_nbi/admin_topics.py
+++ b/osm_nbi/admin_topics.py
@@ -559,7 +559,10 @@
         :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):
         """
diff --git a/osm_nbi/authconn.py b/osm_nbi/authconn.py
index 0ffaad8..8f2f128 100644
--- a/osm_nbi/authconn.py
+++ b/osm_nbi/authconn.py
@@ -184,10 +184,11 @@
         """
         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.
         """
 
diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py
index 54442c8..e917306 100644
--- a/osm_nbi/authconn_keystone.py
+++ b/osm_nbi/authconn_keystone.py
@@ -247,10 +247,11 @@
             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 @@
                 "_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 = [{