Skip to content

Commit

Permalink
Remove need environmentsjson (#147)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
grallewellyn authored Dec 5, 2024
1 parent dcdd1d8 commit a261684
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
18 changes: 10 additions & 8 deletions api/endpoints/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

33 changes: 33 additions & 0 deletions api/endpoints/environments.json
Original file line number Diff line number Diff line change
@@ -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
}
]
2 changes: 0 additions & 2 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a261684

Please sign in to comment.