diff --git a/otc_metadata/data/services/testservice.yaml b/otc_metadata/data/services/testservice.yaml index 3a3e14b..6f41a2e 100644 --- a/otc_metadata/data/services/testservice.yaml +++ b/otc_metadata/data/services/testservice.yaml @@ -7,6 +7,7 @@ service_type: testservice service_uri: testservice cloud_environments: - name: eu_de + visibility: internal teams: - name: docs-security-services-rw permission: write diff --git a/otc_metadata/services.py b/otc_metadata/services.py index 3364f73..d80e767 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -98,13 +98,21 @@ class Services(object): res.append(copy.deepcopy(cat)) return res - def services_by_category(self, category, environment=None): + def services_by_category(self, category, environment=None, cloud_environment=None): """List services matching category""" res = [] for srv in self.all_services: - if environment: - if "environment" in srv and srv["environment"] != environment: - continue + if environment and cloud_environment: + cloud_environment_check = False + if srv["is_global"] is not True: + for srv_cloud_environment in srv["cloud_environments"]: + if srv_cloud_environment["name"] == cloud_environment: + if srv_cloud_environment["visibility"] == environment: + cloud_environment_check = True + else: + continue + if cloud_environment_check is False: + continue if srv["service_category"] == category: for repositories in self.all_repositories: if repositories["service_type"] == srv["service_type"]: @@ -112,7 +120,7 @@ class Services(object): res.append(copy.deepcopy(srv)) return res - def services_with_docs_by_category(self, category, environment=None): + def services_with_docs_by_category(self, category, environment=None, cloud_environment=None): """Retrieve service category docs data :param str category: Optional Category filter @@ -131,8 +139,15 @@ class Services(object): continue res.setdefault(cat, service) res_doc = copy.deepcopy(doc) - if environment: - if "environment" in doc and doc["environment"] != environment: + if environment and cloud_environment: + cloud_environment_check = False + for doc_cloud_environment in doc["cloud_environments"]: + if doc_cloud_environment["name"] == cloud_environment: + if doc_cloud_environment["visibility"] == environment: + cloud_environment_check = True + else: + continue + if cloud_environment_check is False: continue for repositories in self.all_repositories: if repositories["service_type"] == service["service_type"]: @@ -151,15 +166,19 @@ class Services(object): docs = [] for service in self.all_services: - if "environment" in service: - if service["environment"] != environment: - continue cloud_environment_service_check = False - for cloud_environment_service in service["cloud_environments"]: - if cloud_environment_service["name"] == cloud_environment: - cloud_environment_service_check = True - break - if cloud_environment_service_check is False: + cloud_visibility_check = False + if service["is_global"] is not True: + for cloud_environment_service in service["cloud_environments"]: + if cloud_environment_service["name"] == cloud_environment: + cloud_environment_service_check = True + if environment: + if cloud_environment_service["visibility"] == environment: + cloud_visibility_check = True + else: + cloud_visibility_check = True + break + if cloud_environment_service_check is False or cloud_visibility_check is False: continue if not service["service_title"]: continue @@ -168,15 +187,18 @@ class Services(object): doc_list = [] for doc in self.all_docs: - if "environment" in doc: - if doc["environment"] != environment: - continue cloud_environment_doc_check = False + cloud_doc_visibility_check = False for cloud_environment_doc in doc["cloud_environments"]: if cloud_environment_doc["name"] == cloud_environment: cloud_environment_doc_check = True + if environment: + if cloud_environment_service["visibility"] == environment: + cloud_doc_visibility_check = True + else: + cloud_doc_visibility_check = True break - if cloud_environment_doc_check is False: + if cloud_environment_doc_check is False or cloud_doc_visibility_check is False: continue if doc["service_type"] == service["service_type"]: doc_list.append({