From fa54cd99ee561e02ef95128cd3d25074aa1dbe54 Mon Sep 17 00:00:00 2001 From: Eduardo Sousa Date: Mon, 20 May 2019 15:58:41 +0100 Subject: [PATCH] Adding filter to ProjectTopicAuth Change-Id: I0bf340085f703540f810a969db368431d8b4774d Signed-off-by: Eduardo Sousa --- osm_nbi/admin_topics.py | 5 ++++- osm_nbi/authconn.py | 3 ++- osm_nbi/authconn_keystone.py | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index 9f2eb68..2bca416 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -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): """ diff --git a/osm_nbi/authconn.py b/osm_nbi/authconn.py index 8f2f128..df5c700 100644 --- a/osm_nbi/authconn.py +++ b/osm_nbi/authconn.py @@ -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") diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index e917306..b0cab0c 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -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") -- 2.25.1