From 72ef5641daa3c778b68919922c46a5433bc01aeb Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Mon, 20 Nov 2023 11:35:03 +0000 Subject: [PATCH] fix: use S3_DOWNLOAD_ROOT for s3 downloads --- src/backend/app/config.py | 24 ++++++++++++++++++++++-- src/backend/app/main.py | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/backend/app/config.py b/src/backend/app/config.py index 6872e26566..bc549accf7 100644 --- a/src/backend/app/config.py +++ b/src/backend/app/config.py @@ -110,9 +110,29 @@ def assemble_db_connection(cls, v: Optional[str], info: ValidationInfo) -> Any: OSM_LOGIN_REDIRECT_URI: str = "http://127.0.0.1:7051/osmauth/" S3_ENDPOINT: str = "http://s3:9000" - S3_ACCESS_KEY: str - S3_SECRET_KEY: str + S3_ACCESS_KEY: Optional[str] = "" + S3_SECRET_KEY: Optional[str] = "" S3_BUCKET_NAME: str = "fmtm-data" + S3_DOWNLOAD_ROOT: Optional[str] = None + + @field_validator("S3_DOWNLOAD_ROOT", mode="before") + @classmethod + def configure_s3_download_root(cls, v: Optional[str], info: ValidationInfo) -> str: + """Set S3_DOWNLOAD_ROOT for dev setup. + + This is required, as normally S3_DOWNLOAD_ROOT is the same + as S3_ENDPOINT, but for development we use the docker compose + service name for S3_ENDPOINT instead. + """ + # If set manually, pass through + if isinstance(v, str): + return v + # For dev setup + dev_port = info.data.get("FMTM_DEV_PORT") + if s3_endpoint := info.data.get("S3_ENDPOINT") == "http://s3:9000": + return f"http://s3.fmtm.localhost:{dev_port}" + # Else set to value of S3_ENDPOINT + return s3_endpoint UNDERPASS_API_URL: str = "https://raw-data-api0.hotosm.org/v1" SENTRY_DSN: Optional[str] = None diff --git a/src/backend/app/main.py b/src/backend/app/main.py index e1c6dda664..d2ed050929 100644 --- a/src/backend/app/main.py +++ b/src/backend/app/main.py @@ -19,7 +19,7 @@ import logging import sys -from typing import Union +from typing import Optional import sentry_sdk from fastapi import FastAPI, Request @@ -191,7 +191,7 @@ def home(): @api.get("/items/{item_id}") -def read_item(item_id: int, q: Union[str, None] = None): +def read_item(item_id: int, q: Optional[str] = None): """Get item IDs.""" return {"item_id": item_id, "q": q}