diff --git a/api/endpoints/environment.py b/api/endpoints/environment.py index dcb6563..5298a54 100755 --- a/api/endpoints/environment.py +++ b/api/endpoints/environment.py @@ -6,12 +6,13 @@ from api import settings import requests import urllib.parse +import json +import os log = logging.getLogger(__name__) ns = api.namespace('environment', description='Operations related to the MAAP environment') - @ns.route('/config') class Config(Resource): def get(self): @@ -58,16 +59,17 @@ def get(self, ade_host): def get_config(ade_host): - req = requests.get(settings.MAAP_ENVIRONMENT_FILE) - if req.status_code == requests.codes.ok: - data = req.json() - else: - print('Content was not found.') + try: + ROOT = os.path.dirname(os.path.abspath(__file__)) + with open(os.path.join(ROOT, "environments.json")) as f: + data = json.load(f) + except FileNotFoundError: + msg = "environments.json file could not be found" + logging.exception(msg) + raise FileNotFoundError(msg) base_url = "{0.netloc}".format(urlsplit(urllib.parse.unquote(ade_host))) match = next((x for x in data if base_url in x['ade_server']), None) maap_config = next((x for x in data if x['default_host'] == True), None) if match is None else match - return maap_config - diff --git a/api/endpoints/environments.json b/api/endpoints/environments.json new file mode 100644 index 0000000..f4047ed --- /dev/null +++ b/api/endpoints/environments.json @@ -0,0 +1,33 @@ +[ + { + "environment": "dit", + "ade_server": "ade.dit.maap-project.org", + "api_server": "api.dit.maap-project.org", + "auth_server": "auth.dit.maap-project.org", + "mas_server": "repo.dit.maap-project.org", + "edsc_server": "ade.dit.maap-project.org:30052", + "workspace_bucket": "maap-dit-workspace", + "kibana_url": "https://35.88.169.231/metrics/goto/4f1115df1b6563782292fb1f75676f95", + "default_host": true + }, + { + "environment": "uat", + "ade_server": "ade.uat.maap-project.org", + "api_server": "api.uat.maap-project.org", + "auth_server": "auth.uat.maap-project.org", + "mas_server": "repo.uat.maap-project.org", + "edsc_server": "ade.uat.maap-project.org:30052", + "workspace_bucket": "maap-uat-workspace", + "default_host": false + }, + { + "environment": "ops", + "ade_server": "ade.maap-project.org", + "api_server": "api.maap-project.org", + "auth_server": "auth.maap-project.org", + "mas_server": "mas.maap-project.org", + "edsc_server": "ade.maap-project.org:30052", + "workspace_bucket": "maap-ops-workspace", + "default_host": false + } +] diff --git a/api/settings.py b/api/settings.py index 94dae86..708df75 100755 --- a/api/settings.py +++ b/api/settings.py @@ -43,8 +43,6 @@ def str2bool(v): GITLAB_TOKEN = os.getenv('GITLAB_TOKEN', 'foobar') GITLAB_API_TOKEN = os.getenv('GITLAB_API_TOKEN','') # New setting inherited from sister, remove comment after API is stable -MAAP_ENVIRONMENT_FILE = os.getenv('MAAP_ENVIRONMENT_FILE', 'https://raw.githubusercontent.com/MAAP-Project/maap-jupyter-ide/develop/maap_environments.json') - REPO_NAME = os.getenv('REPO_NAME', 'register-job') REPO_PATH = os.getenv('REPO_PATH', '/home/ubuntu/repo') VERSION = os.getenv('VERSION', 'master')