diff --git a/sbn_survey_image_service/config/env.py b/sbn_survey_image_service/config/env.py index 2cec193..c7fe4e1 100644 --- a/sbn_survey_image_service/config/env.py +++ b/sbn_survey_image_service/config/env.py @@ -4,7 +4,7 @@ import os import inspect import multiprocessing -from typing import List, Union +from typing import List from dotenv import load_dotenv, find_dotenv load_dotenv(find_dotenv(), override=True, verbose=True) @@ -40,11 +40,13 @@ class SBNSISEnvironment: API_HOST: str = "127.0.0.1" API_PORT: int = 5000 BASE_HREF: str = "/" + PUBLIC_URL: str = "https://sbnsurveys.astro.umd.edu/api" IS_DAEMON: str = "TRUE" + IS_PRODUCTION: str = "FALSE" def __init__(self): key: str - value: Union[str, int, None] + value: str | int | None for key, value in inspect.getmembers(SBNSISEnvironment): if key.startswith("_"): continue @@ -101,6 +103,9 @@ def __init__(self): API_PORT={SBNSISEnvironment.API_PORT} BASE_HREF={SBNSISEnvironment.BASE_HREF} +# URL used in production +PUBLIC_URL=https://sbnsurveys.astro.umd.edu/api + # QUERY CONFIG # none @@ -119,20 +124,3 @@ def __init__(self): SBNSIS_LOG_FILE={SBNSISEnvironment.SBNSIS_LOG_FILE} """.strip() ) - - -# Debugging block -# print("=========================") -# print(ENV.LIVE_GUNICORN_INSTANCES) -# print(ENV.LIVE_WORKER_INSTANCES) -# print(ENV.DEPLOYMENT_TIER) -# print(ENV.DB_DATABASE) -# print(ENV.DB_PASSWORD) -# print(ENV.DB_USERNAME) -# print() -# print(ENV.CATCH_LOG) -# print(ENV.CATCH_ARCHIVE_PATH) -# print(ENV.CATCH_CUTOUT_PATH) -# print(ENV.CATCH_THUMBNAIL_PATH) -# print(ENV.IS_DAEMON) -# print("=========================") diff --git a/sbn_survey_image_service/scripts/sbnsis.py b/sbn_survey_image_service/scripts/sbnsis.py index fbadcbe..96f1ac4 100644 --- a/sbn_survey_image_service/scripts/sbnsis.py +++ b/sbn_survey_image_service/scripts/sbnsis.py @@ -105,8 +105,10 @@ def start_dev(self) -> None: "sbn_survey_image_service.app", ] + env: Dict[str, str] = os.environ.copy() + env["IS_PRODUCTION"] = "FALSE" try: - subprocess.check_call(cmd) + subprocess.check_call(cmd, env=env) except KeyboardInterrupt: pass @@ -127,6 +129,7 @@ def start_production(self) -> None: ] env: Dict[str, str] = os.environ.copy() + env["IS_PRODUCTION"] = "TRUE" if self.args.daemon: env["IS_DAEMON"] = "TRUE" cmd += ["--daemon"] diff --git a/sbn_survey_image_service/services/metadata.py b/sbn_survey_image_service/services/metadata.py index 6018d75..f0ec85d 100644 --- a/sbn_survey_image_service/services/metadata.py +++ b/sbn_survey_image_service/services/metadata.py @@ -3,9 +3,11 @@ __all__ = ["metadata_query", "metadata_summary"] +from urllib.parse import quote from typing import Any, List, Tuple from .database_provider import data_provider_session, Session from ..models.image import Image +from ..config.env import ENV def metadata_query( @@ -53,6 +55,12 @@ def metadata_query( images: List[Image] = query.all() + url_base: str = ENV.PUBLIC_URL + if ENV.IS_PRODUCTION.upper() != "TRUE": + url_base = f"http://{ENV.API_HOST}:{ENV.API_PORT}/{ENV.BASE_HREF.lstrip('/')}".rstrip( + "/" + ) + for im in images: matches.append( { @@ -64,7 +72,7 @@ def metadata_query( "calibration_level": im.calibration_level, "target": im.target, "pixel_scale": im.pixel_scale, - "access_url": f"https://sbnsurveys.astro.umd.edu/images/{im.obs_id}?format={format}", + "access_url": f"{url_base}/images/{quote(im.obs_id)}?format={format}", } )