Files
officeconvert/python/packages/server/src/officeconvert_server/config.py
T
end 26cd0ef071
Docker server image / build-and-push (push) Successful in 1m7s
fix AWS S3 startup for production deployments
Pass S3_REGION and S3_PUBLIC_USE_SSL through compose, treat blank public
SSL as unset, and skip CreateBucket when IAM only allows access to an
existing bucket.
2026-06-17 11:55:53 -07:00

76 lines
2.8 KiB
Python

"""Runtime configuration for the officeconvert Connect server."""
from __future__ import annotations
from dataclasses import dataclass
import os
@dataclass(frozen=True, slots=True)
class ServerConfig:
"""Defines environment-driven settings for server orchestration."""
s3_bucket: str
s3_endpoint: str
s3_access_key: str
s3_secret_key: str
s3_secure: bool
s3_region: str | None
s3_public_endpoint: str
s3_public_secure: bool
s3_session_ttl_seconds: int
conversion_pptx_to_pdf_timeout_seconds: int
conversion_pdf_to_images_timeout_seconds: int
conversion_pptx_to_pdf_base_timeout_seconds: int
conversion_pptx_to_pdf_per_slide_timeout_seconds: int
conversion_pdf_to_images_base_timeout_seconds: int
conversion_pdf_to_images_per_slide_timeout_seconds: int
conversion_cleanup_delay_seconds: int
def load_server_config() -> ServerConfig:
"""Load server configuration from environment variables."""
s3_secure = os.getenv("S3_USE_SSL", "false").lower() == "true"
public_ssl_env = os.getenv("S3_PUBLIC_USE_SSL", "").strip()
s3_public_secure = (
public_ssl_env.lower() == "true"
if public_ssl_env
else s3_secure
)
region_env = os.getenv("S3_REGION", "").strip()
s3_bucket = os.getenv("S3_BUCKET", "").strip()
if not s3_bucket:
raise ValueError("S3_BUCKET is required")
return ServerConfig(
s3_bucket=s3_bucket,
s3_endpoint=os.getenv("S3_ENDPOINT", "localhost:8333"),
s3_access_key=os.getenv("S3_ACCESS_KEY", "minioadmin"),
s3_secret_key=os.getenv("S3_SECRET_KEY", "minioadmin"),
s3_secure=s3_secure,
s3_region=region_env or None,
s3_public_endpoint=os.getenv("S3_PUBLIC_ENDPOINT", "localhost:8333"),
s3_public_secure=s3_public_secure,
s3_session_ttl_seconds=int(os.getenv("S3_SESSION_TTL_SECONDS", "3600")),
conversion_pptx_to_pdf_timeout_seconds=int(
os.getenv("CONVERSION_PPTX_TO_PDF_TIMEOUT_SECONDS", "180")
),
conversion_pdf_to_images_timeout_seconds=int(
os.getenv("CONVERSION_PDF_TO_IMAGES_TIMEOUT_SECONDS", "1800")
),
conversion_pptx_to_pdf_base_timeout_seconds=int(
os.getenv("CONVERSION_PPTX_TO_PDF_BASE_TIMEOUT_SECONDS", "45")
),
conversion_pptx_to_pdf_per_slide_timeout_seconds=int(
os.getenv("CONVERSION_PPTX_TO_PDF_PER_SLIDE_TIMEOUT_SECONDS", "3")
),
conversion_pdf_to_images_base_timeout_seconds=int(
os.getenv("CONVERSION_PDF_TO_IMAGES_BASE_TIMEOUT_SECONDS", "30")
),
conversion_pdf_to_images_per_slide_timeout_seconds=int(
os.getenv("CONVERSION_PDF_TO_IMAGES_PER_SLIDE_TIMEOUT_SECONDS", "8")
),
conversion_cleanup_delay_seconds=int(
os.getenv("CONVERSION_CLEANUP_DELAY_SECONDS", "3600")
),
)