diff --git a/cloud_storage_handler/api/elixircloud/csh/client.py b/cloud_storage_handler/api/elixircloud/csh/client.py index 634ff5a..a5941e7 100644 --- a/cloud_storage_handler/api/elixircloud/csh/client.py +++ b/cloud_storage_handler/api/elixircloud/csh/client.py @@ -1,7 +1,6 @@ """MinIO client class and convenience functions.""" import logging -from typing import Type from connexion import FlaskApp from minio import Minio @@ -28,7 +27,7 @@ def __init__(self, config: MinioConfig) -> None: config: MinIO configuration. """ self.config: MinioConfig = config - self.client: Type[Minio] = Minio( + self.client: Minio = Minio( endpoint=f"{config.hostname}:{config.port}", access_key=config.access_key, secret_key=config.secret_key, @@ -48,14 +47,14 @@ def register_minio_client(app: FlaskApp) -> FlaskApp: """Register MinIO client and create bucket. Args: - app: FOCA app instance. + app: Connexion Flask app instance. Returns: - FOCA app instance with MinIO client instance added to config. + Connexion Flask app instance with a MinIO client instance added to + its config. """ - minio_config = app.app.config.foca.custom.minio - minio_client = MinioClient(config=minio_config) + minio_client = MinioClient(config=app.app.config.foca.custom.minio) minio_client.create_bucket() - minio_config.client = minio_client + app.app.config.foca.custom.minio.client = minio_client logger.info("MinIO client registered.") return app diff --git a/cloud_storage_handler/api/elixircloud/csh/models.py b/cloud_storage_handler/api/elixircloud/csh/models.py index ffced88..5508c56 100644 --- a/cloud_storage_handler/api/elixircloud/csh/models.py +++ b/cloud_storage_handler/api/elixircloud/csh/models.py @@ -1,6 +1,6 @@ """Model for MinIO Configuration.""" -from typing import Annotated, Optional, Type +from typing import Annotated, Optional from minio import Minio from pydantic import BaseModel, conint, constr @@ -37,4 +37,9 @@ class MinioConfig(BaseModel): secret_key: str = "minioadmin" bucket_name: Annotated[str, constr(min_length=1)] = "files" secure: bool = False - client: Optional[Type[Minio]] = None + client: Optional[Minio] = None + + class Config: + """Model configuration.""" + + arbitrary_types_allowed = True diff --git a/cloud_storage_handler/main.py b/cloud_storage_handler/main.py index fa1a957..d54bba7 100644 --- a/cloud_storage_handler/main.py +++ b/cloud_storage_handler/main.py @@ -19,7 +19,7 @@ def init_app() -> FlaskApp: the default path if not. Returns: - A Connexion application instance. + A Connexion Flask application instance. """ config_path = Path( os.getenv(