Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update bento_lib (w/ refactors) + dependencies + images #39

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.11.10
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.12.01

# 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 poetry==1.6.1 "uvicorn[standard]==0.24.0"
RUN pip install --no-cache-dir poetry==1.7.1 "uvicorn[standard]==0.25.0"

# Backwards-compatible with old BentoV2 container layout
WORKDIR /drop-box
Expand Down
40 changes: 3 additions & 37 deletions bento_drop_box_service/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import json

from bento_lib.logging import LogLevelLiteral
from bento_lib.config.pydantic import BentoBaseConfig
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 typing import Annotated, Literal

from .constants import SERVICE_TYPE

Expand All @@ -16,48 +12,18 @@
]


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
bento_container_local: bool = False

class Config(BentoBaseConfig):
service_id: str = str(":".join(list(SERVICE_TYPE.values())[:2]))
service_name: str = "Bento Drop Box Service"
service_description: str = "Drop box service for a Bento platform node."
service_contact_url: str = "mailto:[email protected]"
service_url: str = "http://127.0.0.1:5000" # base URL to construct object URIs from

service_data: str = "data/"
service_data_source: Literal["local"] = "local"
traversal_limit: int = 16

bento_authz_service_url: str # Bento authorization service base URL
authz_enabled: bool = True

cors_origins: tuple[str, ...]

log_level: LogLevelLiteral = "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:
Expand Down
2 changes: 1 addition & 1 deletion bento_drop_box_service/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bento_lib.service_info import GA4GHServiceType
from bento_lib.service_info.types import GA4GHServiceType
from bento_drop_box_service import __version__

__all__ = [
Expand Down
22 changes: 10 additions & 12 deletions bento_drop_box_service/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bento_lib.auth.permissions import P_VIEW_DROP_BOX, P_INGEST_DROP_BOX, P_DELETE_DROP_BOX
from bento_lib.auth.resources import RESOURCE_EVERYTHING
from bento_lib.service_info import SERVICE_ORGANIZATION_C3G, build_service_info
from bento_lib.service_info.helpers import build_service_info_from_pydantic_config
from fastapi import APIRouter, Form, Request, status
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse
Expand Down Expand Up @@ -74,15 +74,13 @@ async def drop_box_delete(path: str, backend: BackendDependency):
@drop_box_router.get("/service-info", dependencies=[authz_middleware.dep_public_endpoint()])
async def service_info(config: ConfigDependency, logger: LoggerDependency) -> Response:
# Spec: https://github.com/ga4gh-discovery/ga4gh-service-info
return JSONResponse(await build_service_info({
"id": config.service_id,
"name": config.service_name,
"type": SERVICE_TYPE,
"description": config.service_description,
"organization": SERVICE_ORGANIZATION_C3G,
"contactUrl": config.service_contact_url,
"version": __version__,
"bento": {
"serviceKind": BENTO_SERVICE_KIND
return JSONResponse(await build_service_info_from_pydantic_config(
config,
logger,
{
"serviceKind": BENTO_SERVICE_KIND,
"gitRepository": "https://github.com/bento-platform/bento_drop_box_service",
},
}, debug=config.bento_debug, local=config.bento_container_local, logger=logger))
SERVICE_TYPE,
__version__,
))
4 changes: 2 additions & 2 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.11.10
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.12.01

RUN pip install --no-cache-dir poetry==1.6.1 "uvicorn[standard]==0.24.0"
RUN pip install --no-cache-dir poetry==1.7.1 "uvicorn[standard]==0.25.0"

# Backwards-compatible with old BentoV2 container layout
WORKDIR /drop-box
Expand Down
Loading