-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
114 lines (97 loc) · 3.5 KB
/
config.py
File metadata and controls
114 lines (97 loc) · 3.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from pydantic import Field, field_validator
from pydantic_settings import BaseSettings
class Config(BaseSettings):
"""Application configuration using Pydantic for validation"""
# Admin credentials
admin_username: str = Field(
default="admin",
env="ADMIN_USERNAME",
description="Admin panel username",
)
admin_password: str = Field(
default="admin123",
env="ADMIN_PASSWORD",
description="Admin panel password",
)
# Database
database_url: str = Field(
default="postgresql+asyncpg://user:password@localhost/superchromia",
env="DATABASE_URL",
description="Database connection URL",
)
# Telegram
telegram_api_id: str | None = Field(default=None, env="TELEGRAM_API_ID", description="Telegram API ID")
telegram_api_hash: str | None = Field(default=None, env="TELEGRAM_API_HASH", description="Telegram API Hash")
telethon_session_string: str = Field(
env="TELETHON_SESSION_STRING",
description="Telegram session ",
)
# Security
secret_key: str = Field(
default="your-secret-key-change-this-in-production",
env="SECRET_KEY",
description="Secret key for session encryption",
)
# HTTPS Configuration
force_https: bool = Field(
default=True,
env="FORCE_HTTPS",
description="Force HTTPS for admin panel and API",
)
# MCP configuration
mcp_enabled: bool = Field(
default=False,
env="MCP_ENABLED",
description="Enable integration with external MCP servers",
)
# Validation
@field_validator("admin_username")
@classmethod
def validate_admin_username(cls, v):
if not v or len(v.strip()) == 0:
raise ValueError("Admin username cannot be empty")
if len(v) < 3:
raise ValueError("Admin username must be at least 3 characters")
return v.strip()
@field_validator("admin_password")
@classmethod
def validate_admin_password(cls, v):
if not v or len(v.strip()) == 0:
raise ValueError("Admin password cannot be empty")
if len(v) < 6:
raise ValueError("Admin password must be at least 6 characters")
return v
@field_validator("telegram_api_id")
@classmethod
def validate_telegram_api_id(cls, v):
if v is not None:
try:
int(v)
except ValueError as err:
raise ValueError("TELEGRAM_API_ID must be a valid integer") from err
return v
@field_validator("telegram_api_hash")
@classmethod
def validate_telegram_api_hash(cls, v):
if v is not None and len(v) != 32:
raise ValueError("TELEGRAM_API_HASH must be exactly 32 characters")
return v
@field_validator("secret_key")
@classmethod
def validate_secret_key(cls, v):
if len(v) < 32:
raise ValueError("SECRET_KEY must be at least 32 characters long")
return v
def validate_required_telegram_config(self) -> None:
"""Validate that required Telegram configuration is present"""
if not self.telegram_api_id:
raise ValueError("TELEGRAM_API_ID environment variable is required")
if not self.telegram_api_hash:
raise ValueError("TELEGRAM_API_HASH environment variable is required")
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = False
extra = "ignore"
# Create global config instance
config = Config()