Skip to content

Commit

Permalink
fix: use S3_DOWNLOAD_ROOT for s3 downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 21, 2023
1 parent e40a9ba commit 72ef564
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import logging
import sys
from typing import Union
from typing import Optional

import sentry_sdk
from fastapi import FastAPI, Request
Expand Down Expand Up @@ -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}

Expand Down

0 comments on commit 72ef564

Please sign in to comment.