/ settings.py
settings.py
 1  import os
 2  
 3  import yaml
 4  from pydantic import BaseModel, ConfigDict
 5  
 6  
 7  class Config(BaseModel):
 8      model_config = ConfigDict(extra="forbid")
 9  
10      max_concurrency: int = 8
11      rule_timeout_s: int = 30
12      rulesets: list[str] = []
13      enabled_rules: list[str] = []
14  
15      def apply_env_overrides(self):
16          """Apply environment variable overrides to config values."""
17          if "CURATOR_MAX_CONCURRENCY" in os.environ:
18              self.max_concurrency = int(os.environ["CURATOR_MAX_CONCURRENCY"])
19  
20          if "CURATOR_RULE_TIMEOUT_S" in os.environ:
21              self.rule_timeout_s = int(os.environ["CURATOR_RULE_TIMEOUT_S"])
22  
23          if "CURATOR_RULESETS" in os.environ:
24              rulesets_str = os.environ["CURATOR_RULESETS"]
25              self.rulesets = [rs.strip() for rs in rulesets_str.split(",") if rs.strip()]
26  
27          if "CURATOR_ENABLED_RULES" in os.environ:
28              rules_str = os.environ["CURATOR_ENABLED_RULES"]
29              self.enabled_rules = [rule.strip() for rule in rules_str.split(",") if rule.strip()]
30  
31  
32  # Load config from file or environment variables
33  config_path = os.environ.get("CURATOR_CONFIG_PATH", os.path.join(os.path.dirname(__file__), "config.yml"))
34  
35  if os.path.exists(config_path):
36      with open(config_path) as f:
37          config = Config.model_validate(yaml.safe_load(f))
38      config.apply_env_overrides()
39  else:
40      # No config file - create from defaults and apply env overrides
41      config = Config()
42      config.apply_env_overrides()