44This module contains data models for configuration objects used in the CodeFlow system.
55"""
66
7- from dataclasses import dataclass , field
87from enum import StrEnum
98from typing import Any
109
10+ from pydantic import BaseModel , Field , SecretStr , field_validator
11+
1112
1213class LogLevel (StrEnum ):
1314 """Logging levels for the application."""
@@ -28,59 +29,79 @@ class Environment(StrEnum):
2829 TESTING = "testing"
2930
3031
31- @dataclass
32- class DatabaseConfig :
33- """Database configuration model."""
32+ class DatabaseConfig (BaseModel ):
33+ """Database configuration model with validation."""
3434
3535 url : str
36- pool_size : int = 5
37- max_overflow : int = 10
36+ pool_size : int = Field ( default = 5 , ge = 0 )
37+ max_overflow : int = Field ( default = 10 , ge = 0 )
3838 echo : bool = False
3939 ssl_required : bool = True
4040
41+ @field_validator ("url" )
42+ @classmethod
43+ def validate_url (cls , v : str ) -> str :
44+ """Validate database URL format."""
45+ if not v :
46+ raise ValueError ("Database URL cannot be empty" )
47+ # Basic URL validation - must contain ://
48+ if "://" not in v :
49+ raise ValueError (
50+ "Invalid database URL format. Expected format: dialect://user:password@host:port/database"
51+ )
52+ return v
53+
4154
42- @dataclass
43- class RedisConfig :
44- """Redis configuration model."""
55+ class RedisConfig (BaseModel ):
56+ """Redis configuration model with validation."""
4557
4658 url : str
47- max_connections : int = 10
59+ max_connections : int = Field ( default = 10 , ge = 0 )
4860 ssl : bool = True
4961
62+ @field_validator ("url" )
63+ @classmethod
64+ def validate_url (cls , v : str ) -> str :
65+ """Validate Redis URL format."""
66+ if not v :
67+ raise ValueError ("Redis URL cannot be empty" )
68+ # Basic URL validation - must contain ://
69+ if "://" not in v :
70+ raise ValueError (
71+ "Invalid Redis URL format. Expected format: redis://host:port or rediss://host:port"
72+ )
73+ return v
74+
5075
51- @dataclass
52- class LLMConfig :
53- """LLM provider configuration model."""
76+ class LLMConfig (BaseModel ):
77+ """LLM provider configuration model with validation."""
5478
5579 provider : str
56- api_key : str | None = None
80+ api_key : SecretStr | None = None
5781 model : str # Required; provider-specific (e.g., gpt-4, claude-3-opus, mistral-large)
58- temperature : float = 0.7
59- max_tokens : int = 4096
82+ temperature : float = Field ( default = 0.7 , ge = 0.0 , le = 2.0 )
83+ max_tokens : int = Field ( default = 4096 , gt = 0 )
6084
6185
62- @dataclass
63- class GitHubConfig :
64- """GitHub integration configuration model."""
86+ class GitHubConfig (BaseModel ):
87+ """GitHub integration configuration model with secrets protection."""
6588
66- token : str | None = None
89+ token : SecretStr | None = None
6790 app_id : str | None = None
68- private_key : str | None = None
69- webhook_secret : str | None = None
91+ private_key : SecretStr | None = None
92+ webhook_secret : SecretStr | None = None
7093
7194
72- @dataclass
73- class WorkflowConfig :
74- """Workflow execution configuration model."""
95+ class WorkflowConfig (BaseModel ):
96+ """Workflow execution configuration model with validation."""
7597
76- max_concurrent : int = 10
77- timeout_seconds : int = 300
78- retry_attempts : int = 3
79- retry_delay_seconds : int = 5
98+ max_concurrent : int = Field ( default = 10 , gt = 0 )
99+ timeout_seconds : int = Field ( default = 300 , gt = 0 )
100+ retry_attempts : int = Field ( default = 3 , ge = 0 )
101+ retry_delay_seconds : int = Field ( default = 5 , gt = 0 )
80102
81103
82- @dataclass
83- class AppConfig :
104+ class AppConfig (BaseModel ):
84105 """Main application configuration model."""
85106
86107 environment : Environment = Environment .DEVELOPMENT
@@ -90,8 +111,8 @@ class AppConfig:
90111 redis : RedisConfig | None = None
91112 llm : LLMConfig | None = None
92113 github : GitHubConfig | None = None
93- workflow : WorkflowConfig = field (default_factory = WorkflowConfig )
94- custom_settings : dict [str , Any ] = field (default_factory = dict )
114+ workflow : WorkflowConfig = Field (default_factory = WorkflowConfig )
115+ custom_settings : dict [str , Any ] = Field (default_factory = dict )
95116
96117
97118__all__ = [
0 commit comments