From 8bc41a5a60ce4756bba3950786eb59459c8f9501 Mon Sep 17 00:00:00 2001 From: ilarimikkonen Date: Mon, 17 Aug 2020 16:44:05 +0300 Subject: [PATCH 1/3] new config item to identify broker API by name --- controller.py | 2 +- lib/umbrella_client.py | 12 +++++++----- settings.py | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/controller.py b/controller.py index 9761554..d29ecdc 100644 --- a/controller.py +++ b/controller.py @@ -284,7 +284,7 @@ def delete_tenant(user_info, tenant_id): # Delete policies in API Umbrella umbrella_client = UmbrellaClient(UMBRELLA_URL, UMBRELLA_TOKEN, UMBRELLA_KEY) - broker_api = umbrella_client.get_api_from_app_id(BROKER_APP_ID) + broker_api = umbrella_client.get_api_from_app_id(BROKER_APP_ID, BROKER_NAME)#include the broker name sub_settings = [setting for setting in broker_api['sub_settings'] if not is_tenant_setting(setting, tenant_id)] diff --git a/lib/umbrella_client.py b/lib/umbrella_client.py index 29c6276..83af797 100644 --- a/lib/umbrella_client.py +++ b/lib/umbrella_client.py @@ -45,9 +45,11 @@ def __init__(self, host, admin_token, api_key): self._admin_token = admin_token self._api_key = api_key - def get_api_from_app_id(self, app_id): + def get_api_from_app_id(self, app_id, broker_name): """ Searches in API Umbrella for an API which is configured with a particular IDM app ID + and broker name to get the correct API. There may be several APIs + which have the same IDM app ID. """ # To limit the number of results, include a search by expected app_id url = urljoin(self._host, '/api-umbrella/v1/apis.json') @@ -76,7 +78,7 @@ def get_api_from_app_id(self, app_id): for api in apis['data']: - if api['settings']['idp_app_id'] == app_id: + if api['settings']['idp_app_id'] == app_id and api['name'] == broker_name: processed = True api_elem = api break @@ -105,13 +107,13 @@ def update_api(self, api_elem): self.publish() - def add_sub_url_setting_app_id(self, app_id, sub_settings): + def add_sub_url_setting_app_id(self, app_id, sub_settings, broker_name): """ Appends a new sub URL setting into an API Umbrella API - identified by IDM app ID + identified by IDM app ID and Broker name """ - api_elem = self.get_api_from_app_id(app_id) + api_elem = self.get_api_from_app_id(app_id, broker_name) if not 'sub_settings' in api_elem or api_elem['sub_settings'] is None: api_elem['sub_settings'] = [] diff --git a/settings.py b/settings.py index 5b80a2b..0b4b538 100644 --- a/settings.py +++ b/settings.py @@ -57,3 +57,5 @@ IDM_USER_ID = data.get('idm', {}).get('user_id', IDM_USER_ID) UMBRELLA_TOKEN = data.get('umbrella', {}).get('token', UMBRELLA_TOKEN) UMBRELLA_KEY = data.get('umbrella', {}).get('key', UMBRELLA_KEY) + #String used to identify Context Broker when listing APIs from Umbrella + BROKER_NAME = data.get('broker',{}).get('name', BROKER_NAME) From ff66eefa8d074db294bc16f557f20c190c50c542 Mon Sep 17 00:00:00 2001 From: ilarimikkonen Date: Wed, 19 Aug 2020 11:07:41 +0300 Subject: [PATCH 2/3] adding read from env variable/default name for broker --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 0b4b538..9180552 100644 --- a/settings.py +++ b/settings.py @@ -44,7 +44,7 @@ BAE_SELLER_ROLE = os.environ.get('BAE_SELLER_ROLE', 'seller') BAE_CUSTOMER_ROLE = os.environ.get('BAE_CUSTOMER_ROLE', 'customer') BAE_ADMIN_ROLE = os.environ.get('BAE_ADMIN_ROLE', 'orgAdmin') - +BROKER_NAME = os.environ.get('BROKER_NAME', 'Orion Context Broker') secrets_file = "/run/secrets/{}".format(os.environ.get("CREDENTIALS_FILE", "credentials.json")) if os.path.isfile(secrets_file): From 8ef63cc90cfcec80280491b8d9af4747fcdde0b2 Mon Sep 17 00:00:00 2001 From: ilarimikkonen Date: Wed, 19 Aug 2020 11:50:38 +0300 Subject: [PATCH 3/3] forgot few things, adding --- controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller.py b/controller.py index d29ecdc..024e693 100644 --- a/controller.py +++ b/controller.py @@ -32,7 +32,7 @@ from settings import (IDM_URL, IDM_PASSWD, IDM_USER, IDM_USER_ID, BROKER_APP_ID, BAE_APP_ID, BROKER_ADMIN_ROLE, BROKER_CONSUMER_ROLE, BAE_SELLER_ROLE, BAE_CUSTOMER_ROLE, BAE_ADMIN_ROLE, UMBRELLA_URL, UMBRELLA_TOKEN, UMBRELLA_KEY, - MONGO_HOST, MONGO_PORT) + MONGO_HOST, MONGO_PORT, BROKER_NAME) app = Flask(__name__) @@ -66,7 +66,7 @@ def _create_access_policies(tenant, org_id, user_info): # Add new policies to existing API sub settings umbrella_client = UmbrellaClient(UMBRELLA_URL, UMBRELLA_TOKEN, UMBRELLA_KEY) - umbrella_client.add_sub_url_setting_app_id(BROKER_APP_ID, [read_policy, admin_policy]) + umbrella_client.add_sub_url_setting_app_id(BROKER_APP_ID, [read_policy, admin_policy], BROKER_NAME) def _map_roles(member):