Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove need environmentsjson #147

Merged
merged 19 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
18 changes: 10 additions & 8 deletions api/endpoints/environment.py
marjo-luc marked this conversation as resolved.
Show resolved Hide resolved
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
Loading