close #4: [feat] add config

This commit is contained in:
Azamat 2026-04-02 12:20:16 +03:00
parent 7b3f82e805
commit 3448266c1d
4 changed files with 100 additions and 1 deletions

View file

@ -12,6 +12,7 @@ from .model import (
LoggingConfig,
MetricsConfig,
OtelConfig,
SandboxConfig,
SecurityConfig,
TracingConfig,
)
@ -38,6 +39,7 @@ def load_config(
logging_section = _section(yaml_data, 'logging')
metrics_section = _section(yaml_data, 'metrics')
tracing_section = _section(yaml_data, 'tracing')
sandbox_section = _section(yaml_data, 'sandbox')
security_section = _section(yaml_data, 'security')
logging_output = _yaml_or_env_choice(
@ -128,6 +130,7 @@ def load_config(
enable_metrics=metrics_enabled,
enable_tracing=tracing_enabled,
),
sandbox=_load_sandbox_config(sandbox_section, env_values),
security=SecurityConfig(
token_header=_yaml_or_env_str(
security_section,
@ -221,6 +224,77 @@ def _optional_section(data: Mapping[str, object], name: str) -> dict[str, object
return section
def _load_sandbox_config(
section: Mapping[str, object],
env: Mapping[str, str],
) -> SandboxConfig:
return SandboxConfig(
image=_yaml_or_env_str(
section,
'image',
'sandbox.image',
env,
'APP_SANDBOX_IMAGE',
),
ttl_seconds=_yaml_or_env_int(
section,
'ttl_seconds',
'sandbox.ttl_seconds',
env,
'APP_SANDBOX_TTL_SECONDS',
),
cleanup_interval_seconds=_yaml_or_env_int(
section,
'cleanup_interval_seconds',
'sandbox.cleanup_interval_seconds',
env,
'APP_SANDBOX_CLEANUP_INTERVAL_SECONDS',
),
chats_root=_yaml_or_env_str(
section,
'chats_root',
'sandbox.chats_root',
env,
'APP_SANDBOX_CHATS_ROOT',
),
dependencies_host_path=_yaml_or_env_str(
section,
'dependencies_host_path',
'sandbox.dependencies_host_path',
env,
'APP_SANDBOX_DEPENDENCIES_HOST_PATH',
),
lambda_tools_host_path=_yaml_or_env_str(
section,
'lambda_tools_host_path',
'sandbox.lambda_tools_host_path',
env,
'APP_SANDBOX_LAMBDA_TOOLS_HOST_PATH',
),
chat_mount_path=_yaml_or_env_str(
section,
'chat_mount_path',
'sandbox.chat_mount_path',
env,
'APP_SANDBOX_CHAT_MOUNT_PATH',
),
dependencies_mount_path=_yaml_or_env_str(
section,
'dependencies_mount_path',
'sandbox.dependencies_mount_path',
env,
'APP_SANDBOX_DEPENDENCIES_MOUNT_PATH',
),
lambda_tools_mount_path=_yaml_or_env_str(
section,
'lambda_tools_mount_path',
'sandbox.lambda_tools_mount_path',
env,
'APP_SANDBOX_LAMBDA_TOOLS_MOUNT_PATH',
),
)
def _load_otel_config(
data: Mapping[str, object],
env: Mapping[str, str],

View file

@ -40,6 +40,19 @@ class OtelConfig:
metric_export_interval: int
@dataclass(frozen=True, slots=True)
class SandboxConfig:
image: str
ttl_seconds: int
cleanup_interval_seconds: int
chats_root: str
dependencies_host_path: str
lambda_tools_host_path: str
chat_mount_path: str
dependencies_mount_path: str
lambda_tools_mount_path: str
@dataclass(frozen=True, slots=True)
class SecurityConfig:
token_header: str
@ -55,4 +68,5 @@ class AppConfig:
metrics: MetricsConfig
tracing: TracingConfig
otel: OtelConfig
sandbox: SandboxConfig
security: SecurityConfig