prepared skeleton for lab5
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Конфигурация MinIO; значения credentials читаются только из файлов."""
|
||||
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
class S3Settings(BaseSettings):
|
||||
endpoint: str = "http://minio:9000"
|
||||
region: str = "us-east-1"
|
||||
bucket: str = "messenger-attachments"
|
||||
access_key_id_file: Path = Path("/run/secrets/s3_access_key_id")
|
||||
secret_access_key_file: Path = Path("/run/secrets/s3_secret_access_key")
|
||||
connect_timeout_seconds: float = Field(default=2, gt=0, le=5)
|
||||
read_timeout_seconds: float = Field(default=10, gt=0, le=15)
|
||||
upload_timeout_seconds: float = Field(default=30, gt=0, le=60)
|
||||
download_timeout_seconds: float = Field(default=60, gt=0, le=120)
|
||||
image_timeout_seconds: float = Field(default=10, gt=0, le=15)
|
||||
max_upload_bytes: int = Field(default=10_485_760, ge=1, le=10_485_760)
|
||||
max_image_pixels: int = Field(default=40_000_000, ge=1, le=40_000_000)
|
||||
chunk_bytes: int = Field(default=65_536, ge=1024, le=262_144)
|
||||
max_concurrent_uploads: int = Field(default=2, ge=1, le=2)
|
||||
cleanup_grace_seconds: int = Field(default=86_400, ge=300)
|
||||
cleanup_interval_seconds: int = Field(default=300, ge=1)
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="S3_", env_file=".env", extra="ignore", frozen=True)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_endpoint(self):
|
||||
url = urlsplit(self.endpoint)
|
||||
if (url.scheme not in {"http", "https"} or not url.hostname or url.username
|
||||
or url.password or url.path not in {"", "/"} or url.query or url.fragment):
|
||||
raise ValueError("S3_ENDPOINT должен быть http(s) адресом без credentials/пути")
|
||||
return self
|
||||
Reference in New Issue
Block a user