Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)]
Expand Down
12 changes: 7 additions & 5 deletions lib/umbrella_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'] = []

Expand Down
4 changes: 3 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)