init: new structure + fix lint errors

This commit is contained in:
Daniil
2026-02-03 02:15:07 +03:00
commit 67e0f22b4f
89 changed files with 7654 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
"""
Infrastructure-level dependencies for FastAPI dependency injection.
"""
from __future__ import annotations
from functools import lru_cache
from cpv3.infrastructure.settings import get_settings
from cpv3.infrastructure.storage.base import StorageBackend, StorageService
from cpv3.infrastructure.storage.local import LocalConfig, LocalStorageBackend
from cpv3.infrastructure.storage.s3 import S3Config, S3StorageBackend
@lru_cache
def _get_storage_service() -> StorageService:
settings = get_settings()
backend: StorageBackend
if settings.storage_backend.upper() == "LOCAL":
backend = LocalStorageBackend(LocalConfig(root_dir=settings.local_storage_dir))
else:
if not settings.s3_access_key or not settings.s3_secret_key:
raise RuntimeError(
"S3_ACCESS_KEY and S3_SECRET_KEY are required for S3 storage"
)
backend = S3StorageBackend(
S3Config(
access_key=settings.s3_access_key,
secret_key=settings.s3_secret_key,
bucket_name=settings.s3_bucket_name,
endpoint_url_internal=settings.s3_endpoint_url_internal,
endpoint_url_public=settings.s3_endpoint_url_public,
presign_expires_seconds=settings.s3_presign_expires_seconds,
)
)
return StorageService(backend)
async def get_storage() -> StorageService:
return _get_storage_service()