-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from bento-platform/refact/fastapi-rewrite
refact!: remove tables concept + rewrite with FastAPI
- Loading branch information
Showing
31 changed files
with
1,922 additions
and
1,673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.03.22 | ||
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.08.16 | ||
|
||
# Run as root in the Dockerfile until we drop down to the service user in the entrypoint | ||
USER root | ||
|
||
# Use uvicorn (instead of hypercorn) in production since I've found | ||
# multiple benchmarks showing it to be faster - David L | ||
RUN pip install --no-cache-dir "uvicorn[standard]==0.20.0" | ||
RUN pip install --no-cache-dir "uvicorn[standard]==0.23.2" | ||
|
||
WORKDIR /aggregation | ||
|
||
COPY pyproject.toml . | ||
COPY poetry.toml . | ||
COPY poetry.lock . | ||
|
||
# Install production dependencies | ||
# Without --no-root, we get errors related to the code not being copied in yet. | ||
# But we don't want the code here, otherwise Docker cache doesn't work well. | ||
RUN poetry install --without dev --no-root | ||
RUN poetry config virtualenvs.create false && \ | ||
poetry install --without dev --no-root | ||
|
||
# Manually copy only what's relevant | ||
# (Don't use .dockerignore, which allows us to have development containers too) | ||
COPY bento_aggregation_service bento_aggregation_service | ||
COPY LICENSE . | ||
COPY README.md . | ||
COPY run.py . | ||
COPY run.bash . | ||
|
||
# Install the module itself, locally (similar to `pip install -e .`) | ||
RUN poetry install --without dev | ||
|
||
# Use base image entrypoint for dropping down into bento_user & running this CMD | ||
CMD [ "python3", "run.py" ] | ||
CMD ["bash", "./run.bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
|
||
from fastapi import Depends | ||
from functools import lru_cache | ||
from pydantic.fields import FieldInfo | ||
from pydantic_settings import BaseSettings, EnvSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict | ||
from typing import Annotated, Any, Literal | ||
|
||
from .constants import SERVICE_TYPE | ||
|
||
__all__ = [ | ||
"Config", | ||
"get_config", | ||
"ConfigDependency", | ||
] | ||
|
||
|
||
class CorsOriginsParsingSource(EnvSettingsSource): | ||
def prepare_field_value(self, field_name: str, field: FieldInfo, value: Any, value_is_complex: bool) -> Any: | ||
if field_name == "cors_origins": | ||
return tuple(x.strip() for x in value.split(";")) if value is not None else () | ||
return json.loads(value) if value_is_complex else value | ||
|
||
|
||
class Config(BaseSettings): | ||
bento_debug: bool = False | ||
|
||
service_id: str = str(":".join(list(SERVICE_TYPE.values())[:2])) | ||
|
||
request_timeout: int = 180 # seconds | ||
|
||
bento_authz_service_url: str # Bento authorization service base URL | ||
authz_enabled: bool = True | ||
|
||
# Other services - settings and flags | ||
use_gohan: bool = False | ||
katsu_url: str | ||
service_registry_url: str # used for fetching list of data services, so we can get data type providers | ||
|
||
cors_origins: tuple[str, ...] = ("*",) | ||
|
||
log_level: Literal["debug", "info", "warning", "error"] = "debug" | ||
|
||
# Make Config instances hashable + immutable | ||
model_config = SettingsConfigDict(frozen=True) | ||
|
||
@classmethod | ||
def settings_customise_sources( | ||
cls, | ||
settings_cls: type[BaseSettings], | ||
init_settings: PydanticBaseSettingsSource, | ||
env_settings: PydanticBaseSettingsSource, | ||
dotenv_settings: PydanticBaseSettingsSource, | ||
file_secret_settings: PydanticBaseSettingsSource, | ||
) -> tuple[PydanticBaseSettingsSource, ...]: | ||
return (CorsOriginsParsingSource(settings_cls),) | ||
|
||
|
||
@lru_cache() | ||
def get_config() -> Config: | ||
return Config() | ||
|
||
|
||
ConfigDependency = Annotated[Config, Depends(get_config)] |
Oops, something went wrong.