mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-04 20:05:16 +02:00
feat(file-storage): add settings, key builder, and backend factory
This commit is contained in:
parent
74fcad6496
commit
1bb1022d35
4 changed files with 117 additions and 0 deletions
37
surfsense_backend/app/file_storage/settings.py
Normal file
37
surfsense_backend/app/file_storage/settings.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""Environment-driven configuration for the file-storage module."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
LOCAL_BACKEND = "local"
|
||||
AZURE_BACKEND = "azure"
|
||||
|
||||
# surfsense_backend/ — two levels up from app/file_storage/settings.py
|
||||
_BACKEND_ROOT = Path(__file__).resolve().parents[2]
|
||||
_DEFAULT_LOCAL_ROOT = str(_BACKEND_ROOT / ".local_object_store")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class StorageSettings:
|
||||
"""Resolved storage configuration for the current process."""
|
||||
|
||||
backend: str
|
||||
azure_connection_string: str | None
|
||||
azure_container: str | None
|
||||
local_root: str
|
||||
|
||||
|
||||
def load_storage_settings() -> StorageSettings:
|
||||
"""Read storage settings from the environment.
|
||||
|
||||
Defaults to the ``local`` backend so development needs no cloud creds.
|
||||
"""
|
||||
return StorageSettings(
|
||||
backend=os.getenv("FILE_STORAGE_BACKEND", LOCAL_BACKEND).strip().lower(),
|
||||
azure_connection_string=os.getenv("AZURE_STORAGE_CONNECTION_STRING"),
|
||||
azure_container=os.getenv("AZURE_STORAGE_CONTAINER"),
|
||||
local_root=os.getenv("FILE_STORAGE_LOCAL_PATH", _DEFAULT_LOCAL_ROOT),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue