Skip to content

Commit

Permalink
rewrote get_config function to match jupyter server extension
Browse files Browse the repository at this point in the history
  • Loading branch information
grallewellyn committed Nov 22, 2024
1 parent b01bb8b commit 3a36990
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
3 changes: 3 additions & 0 deletions api/endpoints/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADE_OPTIONS = ["ade.dit.maap-project.org", "ade.uat.maap-project.org", "ade.maap-project.org"]
DEFAULT_ADE = "ade.maap-project.org"
DEFAULT_API = "api.maap-project.org"
26 changes: 13 additions & 13 deletions api/endpoints/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from api import settings
import requests
import urllib.parse
import os
import api.endpoints.constants as constants

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -58,16 +60,14 @@ 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.')

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

api_host = os.getenv("MAAP_API_HOST", constants.DEFAULT_API)
print("graceal1 api host is ")
print(api_host)
maap_api_config_endpoint = os.getenv("MAAP_API_CONFIG_ENDPOINT", "api/environment/config")
print("graceal1 constants ADE options ")
print(constants.ADE_OPTIONS)
ade_host = ade_host if ade_host in constants.ADE_OPTIONS else os.getenv("MAAP_ADE_HOST", constants.DEFAULT_ADE)
environments_endpoint = "https://" + api_host + "/" + maap_api_config_endpoint + "/"+urllib.parse.quote(urllib.parse.quote("https://", safe=""))+ade_host
print("graceal1 environments endpoint is ")
print(environments_endpoint)
return requests.get(environments_endpoint).json()
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 3a36990

Please sign in to comment.