diff --git a/packages/service-library/src/servicelib/application.py b/packages/service-library/src/servicelib/application.py index 1e2cd1228d7c..d07d5ff47590 100644 --- a/packages/service-library/src/servicelib/application.py +++ b/packages/service-library/src/servicelib/application.py @@ -17,7 +17,7 @@ async def shutdown_info(app: web.Application): def create_safe_application(config: Optional[Dict] = None) -> web.Application: app = web.Application() - # Enxures config entry + # Ensures config entry app[APP_CONFIG_KEY] = config or {} app.on_startup.append(startup_info) diff --git a/packages/service-library/src/servicelib/tracing.py b/packages/service-library/src/servicelib/tracing.py index be6b6885a528..9aa19465f5d5 100644 --- a/packages/service-library/src/servicelib/tracing.py +++ b/packages/service-library/src/servicelib/tracing.py @@ -14,7 +14,7 @@ def setup_tracing( - app: web.Application, app_name: str, host: str, port: str, config: Dict + app: web.Application, app_name: str, host: str, port: int, config: Dict ) -> bool: zipkin_address = f"{config['zipkin_endpoint']}/api/v2/spans" endpoint = az.create_endpoint(app_name, ipv4=host, port=port) diff --git a/services/storage/src/simcore_service_storage/application.py b/services/storage/src/simcore_service_storage/application.py index 469cec4ca42e..0fd8bb05f000 100644 --- a/services/storage/src/simcore_service_storage/application.py +++ b/services/storage/src/simcore_service_storage/application.py @@ -6,8 +6,7 @@ from typing import Optional from aiohttp import web -from pydantic import BaseSettings -from servicelib.application import create_safe_application +from servicelib.application import APP_CONFIG_KEY, create_safe_application from servicelib.monitoring import setup_monitoring from servicelib.tracing import setup_tracing @@ -16,18 +15,20 @@ from .meta import WELCOME_MSG from .rest import setup_rest from .s3 import setup_s3 +from .settings import Settings log = logging.getLogger(__name__) -def create(settings: BaseSettings) -> web.Application: +def create(settings: Settings) -> web.Application: log.debug( "Initializing app with settings:\n%s", settings.json(indent=2, sort_keys=True), ) # TODO: tmp using dict() until webserver is also pydantic-compatible - app = create_safe_application(settings.dict()) + app = create_safe_application(None) + app[APP_CONFIG_KEY] = settings if settings.STORAGE_TRACING.enabled: setup_tracing( @@ -48,7 +49,7 @@ def create(settings: BaseSettings) -> web.Application: return app -def run(settings: BaseSettings, app: Optional[web.Application] = None): +def run(settings: Settings, app: Optional[web.Application] = None): log.debug("Serving application ") if not app: app = create(settings) diff --git a/services/storage/src/simcore_service_storage/db.py b/services/storage/src/simcore_service_storage/db.py index 61341e678069..181368efab67 100644 --- a/services/storage/src/simcore_service_storage/db.py +++ b/services/storage/src/simcore_service_storage/db.py @@ -16,20 +16,23 @@ from .constants import APP_CONFIG_KEY, APP_DB_ENGINE_KEY from .models import metadata +from .settings import PostgresSettings log = logging.getLogger(__name__) async def pg_engine(app: web.Application): - pg_cfg = app[APP_CONFIG_KEY]["STORAGE_POSTGRES"] + engine = None + + pg_cfg: PostgresSettings = app[APP_CONFIG_KEY].STORAGE_POSTGRES dsn = DataSourceName( application_name=f"{__name__}_{id(app)}", - database=pg_cfg["db"], - user=pg_cfg["user"], - password=pg_cfg["password"].get_secret_value(), - host=pg_cfg["host"], - port=pg_cfg["port"], - ) + database=pg_cfg.db, + user=pg_cfg.user, + password=pg_cfg.password.get_secret_value(), + host=pg_cfg.host, + port=pg_cfg.port, + ) # type: ignore log.info("Creating pg engine for %s", dsn) async for attempt in AsyncRetrying( @@ -37,11 +40,11 @@ async def pg_engine(app: web.Application): ): with attempt: engine = await create_pg_engine( - dsn, minsize=pg_cfg["minsize"], maxsize=pg_cfg["maxsize"] + dsn, minsize=pg_cfg.minsize, maxsize=pg_cfg.maxsize ) await raise_if_not_responsive(engine) - if app[APP_CONFIG_KEY]["STORAGE_TESTING"]: + if app[APP_CONFIG_KEY].STORAGE_TESTING: log.info("Initializing tables for %s", dsn) init_pg_tables(dsn, schema=metadata) @@ -78,7 +81,7 @@ def get_engine_state(app: web.Application) -> Dict[str, Any]: def setup_db(app: web.Application): - if "postgres" in app[APP_CONFIG_KEY]["STORAGE_DISABLE_SERVICES"]: + if "postgres" in app[APP_CONFIG_KEY].STORAGE_DISABLE_SERVICES: app[APP_DB_ENGINE_KEY] = None log.warning("Service '%s' explicitly disabled in config", "postgres") return diff --git a/services/storage/src/simcore_service_storage/db_tokens.py b/services/storage/src/simcore_service_storage/db_tokens.py index 4f51c66e9b85..1602ac02e1d6 100644 --- a/services/storage/src/simcore_service_storage/db_tokens.py +++ b/services/storage/src/simcore_service_storage/db_tokens.py @@ -33,8 +33,8 @@ async def get_api_token_and_secret(app: web.Application, userid) -> Tuple[str, s engine = app.get(APP_DB_ENGINE_KEY, None) # defaults from config if any, othewise None - api_token = app[APP_CONFIG_KEY]["BF_API_KEY"] - api_secret = app[APP_CONFIG_KEY]["BF_API_SECRET"] + api_token = app[APP_CONFIG_KEY].BF_API_KEY + api_secret = app[APP_CONFIG_KEY].BF_API_SECRET if engine: try: diff --git a/services/storage/src/simcore_service_storage/s3.py b/services/storage/src/simcore_service_storage/s3.py index d43f681d70d4..c577cb543411 100644 --- a/services/storage/src/simcore_service_storage/s3.py +++ b/services/storage/src/simcore_service_storage/s3.py @@ -59,7 +59,7 @@ def setup_s3(app: web.Application): """minio/s3 service setup""" log.debug("Setting up %s ...", __name__) - STORAGE_DISABLE_SERVICES = app[APP_CONFIG_KEY]["STORAGE_DISABLE_SERVICES"] + STORAGE_DISABLE_SERVICES = app[APP_CONFIG_KEY].STORAGE_DISABLE_SERVICES if "s3" in STORAGE_DISABLE_SERVICES: log.warning("Service '%s' explicitly disabled in config", "s3") @@ -79,5 +79,5 @@ def setup_s3(app: web.Application): def get_config_s3(app: web.Application) -> Dict: - cfg = app[APP_CONFIG_KEY]["STORAGE_S3"] + cfg = app[APP_CONFIG_KEY].STORAGE_S3 return cfg diff --git a/services/storage/tests/test_rest.py b/services/storage/tests/test_rest.py index 065c4702aa17..93491170a138 100644 --- a/services/storage/tests/test_rest.py +++ b/services/storage/tests/test_rest.py @@ -71,7 +71,7 @@ def client( settings = Settings.create_from_env() print(settings.json(indent=2)) - app[APP_CONFIG_KEY] = settings.dict() + app[APP_CONFIG_KEY] = settings setup_db(app) setup_rest(app)