Skip to content

Commit

Permalink
fix: setting S3_DOWNLOAD_ROOT if not debug
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 27, 2023
1 parent 02731cb commit 95fdbc4
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,32 @@ def assemble_db_connection(cls, v: Optional[str], info: ValidationInfo) -> Any:
@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.
"""Set S3_DOWNLOAD_ROOT for S3 downloads.
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.
This is required, when we use a containerised S3 service.
The S3_ENDPOINT is a docker compose service name and not
resolvable outside of the stack.
S3_DOWNLOAD_ROOT is equal to S3_ENDPOINT if a public S3 instance
is used (e.g. AWS S3).
"""
# If set manually, pass through
if isinstance(v, str) and v != "":
if v and 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

# Externally hosted S3
s3_endpoint = info.data.get("S3_ENDPOINT")
if s3_endpoint.startswith("https://"):
return s3_endpoint

# Containerised S3
else:
fmtm_domain = info.data.get("FMTM_DOMAIN")
# Local dev
if s3_endpoint == "http://s3:9000":
dev_port = info.data.get("FMTM_DEV_PORT")
return f"http://s3.{fmtm_domain}:{dev_port}"
return f"https://s3.{fmtm_domain}"

UNDERPASS_API_URL: str = "https://api-prod.raw-data.hotosm.org/v1/"
SENTRY_DSN: Optional[str] = None
Expand Down

0 comments on commit 95fdbc4

Please sign in to comment.