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
7c75397
Merge branch 'develop' of github.com:MAAP-Project/maap-api-nasa into …
grallewellyn Jun 12, 2024
9391562
Merge branch 'develop' of github.com:MAAP-Project/maap-api-nasa into …
grallewellyn Jun 12, 2024
a1ca96b
Merge branch 'develop' of github.com:MAAP-Project/maap-api-nasa into …
grallewellyn Aug 22, 2024
b01bb8b
Merge branch 'develop' of github.com:MAAP-Project/maap-api-nasa into …
grallewellyn Oct 30, 2024
3a36990
rewrote get_config function to match jupyter server extension
grallewellyn Nov 22, 2024
3726a70
added additional print statements
grallewellyn Nov 26, 2024
5d822b8
added more print statements
grallewellyn Nov 26, 2024
0aa26be
printing all environment variables
grallewellyn Dec 2, 2024
8f28db4
reverted to the correct function and added back environment to settin…
grallewellyn Dec 4, 2024
51739b1
added more print statements
grallewellyn Dec 4, 2024
2e0f12f
changed the backup environments.json filepath
grallewellyn Dec 4, 2024
154e28e
now reading from environments.json in MAAP API
grallewellyn Dec 4, 2024
860dc6a
updated import for environments.json
grallewellyn Dec 4, 2024
baeca71
corrected to json.load
grallewellyn Dec 4, 2024
cd65253
removed print statements
grallewellyn Dec 4, 2024
a0521be
added error handling
grallewellyn Dec 5, 2024
5149745
purposely added error
grallewellyn Dec 5, 2024
924b0c7
corrected mistake
grallewellyn Dec 5, 2024
390bc7f
changed to FileNotFoundError to be more descriptive to pass test
grallewellyn Dec 5, 2024
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