Skip to content

Commit a261684

Browse files
authored
Remove need environmentsjson (#147)
* rewrote get_config function to match jupyter server extension * added additional print statements * added more print statements * printing all environment variables * reverted to the correct function and added back environment to settings.py * added more print statements * changed the backup environments.json filepath * now reading from environments.json in MAAP API * updated import for environments.json * corrected to json.load * removed print statements * added error handling * purposely added error * corrected mistake * changed to FileNotFoundError to be more descriptive to pass test
1 parent dcdd1d8 commit a261684

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

api/endpoints/environment.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from api import settings
77
import requests
88
import urllib.parse
9+
import json
10+
import os
911

1012
log = logging.getLogger(__name__)
1113

1214
ns = api.namespace('environment', description='Operations related to the MAAP environment')
1315

14-
1516
@ns.route('/config')
1617
class Config(Resource):
1718
def get(self):
@@ -58,16 +59,17 @@ def get(self, ade_host):
5859

5960

6061
def get_config(ade_host):
61-
req = requests.get(settings.MAAP_ENVIRONMENT_FILE)
62-
if req.status_code == requests.codes.ok:
63-
data = req.json()
64-
else:
65-
print('Content was not found.')
62+
try:
63+
ROOT = os.path.dirname(os.path.abspath(__file__))
64+
with open(os.path.join(ROOT, "environments.json")) as f:
65+
data = json.load(f)
66+
except FileNotFoundError:
67+
msg = "environments.json file could not be found"
68+
logging.exception(msg)
69+
raise FileNotFoundError(msg)
6670

6771
base_url = "{0.netloc}".format(urlsplit(urllib.parse.unquote(ade_host)))
6872

6973
match = next((x for x in data if base_url in x['ade_server']), None)
7074
maap_config = next((x for x in data if x['default_host'] == True), None) if match is None else match
71-
7275
return maap_config
73-

api/endpoints/environments.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"environment": "dit",
4+
"ade_server": "ade.dit.maap-project.org",
5+
"api_server": "api.dit.maap-project.org",
6+
"auth_server": "auth.dit.maap-project.org",
7+
"mas_server": "repo.dit.maap-project.org",
8+
"edsc_server": "ade.dit.maap-project.org:30052",
9+
"workspace_bucket": "maap-dit-workspace",
10+
"kibana_url": "https://35.88.169.231/metrics/goto/4f1115df1b6563782292fb1f75676f95",
11+
"default_host": true
12+
},
13+
{
14+
"environment": "uat",
15+
"ade_server": "ade.uat.maap-project.org",
16+
"api_server": "api.uat.maap-project.org",
17+
"auth_server": "auth.uat.maap-project.org",
18+
"mas_server": "repo.uat.maap-project.org",
19+
"edsc_server": "ade.uat.maap-project.org:30052",
20+
"workspace_bucket": "maap-uat-workspace",
21+
"default_host": false
22+
},
23+
{
24+
"environment": "ops",
25+
"ade_server": "ade.maap-project.org",
26+
"api_server": "api.maap-project.org",
27+
"auth_server": "auth.maap-project.org",
28+
"mas_server": "mas.maap-project.org",
29+
"edsc_server": "ade.maap-project.org:30052",
30+
"workspace_bucket": "maap-ops-workspace",
31+
"default_host": false
32+
}
33+
]

api/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def str2bool(v):
4343
GITLAB_TOKEN = os.getenv('GITLAB_TOKEN', 'foobar')
4444
GITLAB_API_TOKEN = os.getenv('GITLAB_API_TOKEN','') # New setting inherited from sister, remove comment after API is stable
4545

46-
MAAP_ENVIRONMENT_FILE = os.getenv('MAAP_ENVIRONMENT_FILE', 'https://raw.githubusercontent.com/MAAP-Project/maap-jupyter-ide/develop/maap_environments.json')
47-
4846
REPO_NAME = os.getenv('REPO_NAME', 'register-job')
4947
REPO_PATH = os.getenv('REPO_PATH', '/home/ubuntu/repo')
5048
VERSION = os.getenv('VERSION', 'master')

0 commit comments

Comments
 (0)