-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (49 loc) · 1.86 KB
/
app.py
File metadata and controls
65 lines (49 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fastapi import FastAPI
from api.routes import create_fastapi_app
from config.config import Config
from config.logger import get_logger, setup_logging
from services.audio_processor import AudioProcessor
from services.storage import CloudflareR2, R2Storage
logger = get_logger(__name__)
def validate_environment(config):
"""Validate environment configuration"""
warnings = []
errors = []
if not config.r2_storage_enabled:
errors.append("R2 storage is required but not configured")
else:
missing_r2_configs = []
if not config.cloudflare_account_id:
missing_r2_configs.append("CLOUDFLARE_ACCOUNT_ID")
if not config.r2_access_key_id:
missing_r2_configs.append("R2_ACCESS_KEY_ID")
if not config.r2_secret_access_key:
missing_r2_configs.append("R2_SECRET_ACCESS_KEY")
if not config.r2_public_domain:
missing_r2_configs.append("R2_PUBLIC_DOMAIN")
if missing_r2_configs:
errors.append(
f"Missing required R2 environment variables: {', '.join(missing_r2_configs)}"
)
for w in warnings:
logger.warning(w)
for error in errors:
logger.error(error)
if errors:
raise RuntimeError(f"Configuration errors: {'; '.join(errors)}")
return warnings
def create_app() -> FastAPI:
config = Config()
config.validate_for_production()
setup_logging(config.server.debug)
storage = CloudflareR2(
config=R2Storage(
account_id=config.cloudflare_account_id,
bucket_name=config.r2_storage.bucket_name,
public_domain=config.r2_storage.public_domain,
access_key_id=config.r2_storage.access_key_id,
secret_access_key=config.r2_storage.secret_access_key,
)
)
app = create_fastapi_app(config, storage)
return app