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

Centralize and Secure Server Configuration Using Environment Variables #1091

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .envs/.local/.django
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ LRM_QA_PASSWORD=''
#--------------------------------------------------------------------------------
LRM_DEV_TOKEN=''
XLI_TOKEN=''

#Server Base_URLs
#--------------------------------------------------------------------------------
BASE_URL_DEV=http://sde-renaissance.nasa-impact.net
BASE_URL_TEST=https://sciencediscoveryengine.test.nasa.gov
BASE_URL_PROD=https://sciencediscoveryengine.nasa.gov
BASE_URL_XLI=http://sde-xli.nasa-impact.net
BASE_URL_LRM_DEV=https://sde-lrm.nasa-impact.net
BASE_URL_LRM_QA=https://sde-qa.nasa-impact.net
BASE_URL_TEST_SERVER=http://10.51.14.135
BASE_URL_REN=http://sde-renaissance.nasa-impact.net
64 changes: 64 additions & 0 deletions config/server_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os

server_configs = {
"dev": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_DEV"),
"index": "sde_index",
},
"test": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_TEST"),
"index": "sde_index",
},
"production": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_PROD"),
"index": "sde_index",
},
"secret_test": {
"app_name": "nasa-sba-sde",
"query_name": "query-sde-primary",
"base_url": os.getenv("BASE_URL_TEST"),
"index": "sde_index",
},
"secret_production": {
"app_name": "nasa-sba-sde",
"query_name": "query-sde-primary",
"base_url": os.getenv("BASE_URL_PROD"),
"index": "sde_index",
},
"xli": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_XLI"),
"index": "sde_index",
},
"lrm_dev": {
"app_name": "sde-init-check",
"query_name": "query-init-check",
"base_url": os.getenv("BASE_URL_LRM_DEV"),
"index": "sde_init_check",
},
"lrm_qa": {
"app_name": "sde-init-check",
"query_name": "query-init-check",
"base_url": os.getenv("BASE_URL_LRM_QA"),
"index": "sde_init_check",
},
"ren_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_REN"),
"index": "sde_index",
},
"test_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": os.getenv("BASE_URL_TEST_SERVER"),
"index": "sde_index",
},
}
14 changes: 1 addition & 13 deletions config_generation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
import requests

from config import tokens

server_configs: dict[str, dict[str, str]] = {
"ren_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "http://sde-renaissance.nasa-impact.net",
},
"test_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "http://10.51.14.135",
},
}
from config.server_configs import server_configs


class Api:
Expand Down
13 changes: 1 addition & 12 deletions config_generation/minimum_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

import requests

server_configs: dict[str, dict[str, str]] = {
"test_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "https://sciencediscoveryengine.test.nasa.gov",
},
"production_server": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "https://sciencediscoveryengine.nasa.gov",
},
}
from config.server_configs import server_configs


class Api:
Expand Down
5 changes: 3 additions & 2 deletions functional_tests/check_collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import sys
import time
import urllib.parse
Expand All @@ -16,8 +17,8 @@

def server_url(config_folder, server="test", secret=True) -> str:
URLS = {
"test": "https://sciencediscoveryengine.test.nasa.gov",
"prod": "https://sciencediscoveryengine.nasa.gov",
"test": os.getenv("BASE_URL_TEST"),
"prod": os.getenv("BASE_URL_PROD"),
}
if secret:
query = "query-sde-primary"
Expand Down
4 changes: 3 additions & 1 deletion scripts/ej/cmr_to_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import json
import os
import urllib.parse

from environmental_justice.models import EnvironmentalJusticeRow
Expand All @@ -22,7 +23,8 @@ def concept_id_to_sinequa_id(concept_id: str) -> str:


def sinequa_id_to_url(sinequa_id: str) -> str:
base_url = "https://sciencediscoveryengine.nasa.gov/app/nasa-sba-smd/#/preview"
base_domain = os.getenv("BASE_URL_PROD")
base_url = f"{base_domain}/app/nasa-sba-smd/#/preview"
query = '{"name":"query-smd-primary","scope":"All","text":""}'

encoded_id = urllib.parse.quote(sinequa_id, safe="")
Expand Down
5 changes: 3 additions & 2 deletions sde_collections/models/collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import urllib.parse

import requests
Expand Down Expand Up @@ -129,7 +130,7 @@ def tree_root(self) -> str:

@property
def server_url_secret_prod(self) -> str:
base_url = "https://sciencediscoveryengine.nasa.gov" # noqa: E231
base_url = os.getenv("BASE_URL_SECRET_TEST") # noqa: E231
payload = {
"name": "secret-prod",
"scope": "All",
Expand All @@ -143,7 +144,7 @@ def server_url_secret_prod(self) -> str:

@property
def server_url_prod(self) -> str:
base_url = "https://sciencediscoveryengine.nasa.gov" # noqa: E231
base_url = os.getenv("BASE_URL_PROD") # noqa: E231
payload = {
"name": "query-smd-primary",
"scope": "All",
Expand Down
51 changes: 2 additions & 49 deletions sde_collections/sinequa_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,9 @@
import urllib3
from django.conf import settings

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from config.server_configs import server_configs

server_configs = {
"dev": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "http://sde-renaissance.nasa-impact.net",
},
"test": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "https://sciencediscoveryengine.test.nasa.gov",
"index": "sde_index",
},
"production": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "https://sciencediscoveryengine.nasa.gov",
"index": "sde_index",
},
"secret_test": {
"app_name": "nasa-sba-sde",
"query_name": "query-sde-primary",
"base_url": "https://sciencediscoveryengine.test.nasa.gov",
"index": "sde_index",
},
"secret_production": {
"app_name": "nasa-sba-sde",
"query_name": "query-sde-primary",
"base_url": "https://sciencediscoveryengine.nasa.gov",
"index": "sde_index",
},
"xli": {
"app_name": "nasa-sba-smd",
"query_name": "query-smd-primary",
"base_url": "http://sde-xli.nasa-impact.net",
"index": "sde_index",
},
"lrm_dev": {
"app_name": "sde-init-check",
"query_name": "query-init-check",
"base_url": "https://sde-lrm.nasa-impact.net",
"index": "sde_init_check",
},
"lrm_qa": {
"app_name": "sde-init-check",
"query_name": "query-init-check",
"base_url": "https://sde-qa.nasa-impact.net",
},
}
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


class Api:
Expand Down