11"""Configuration loading and validation."""
22
3- from typing import Optional
43
54from loguru import logger
6- from pydantic import BaseModel
5+ from pydantic import BaseModel , field_validator
76from pydantic_settings import BaseSettings
87
98
@@ -22,7 +21,7 @@ class _LokiConfig(EnvConfig, env_prefix="loki_"):
2221
2322 api_url : str
2423 jobs : list [str ]
25- max_logs : Optional [ int ] = 5_000
24+ max_logs : int | None = 5_000
2625
2726
2827LOKI_CONFIG = _LokiConfig ()
@@ -31,7 +30,7 @@ class _LokiConfig(EnvConfig, env_prefix="loki_"):
3130class _DiscordConfig (EnvConfig , env_prefix = "discord_" ):
3231 """Configuration for Discord alerting."""
3332
34- webhook_url : Optional [ str ]
33+ webhook_url : str | None
3534
3635
3736DISCORD_CONFIG = _DiscordConfig ()
@@ -41,8 +40,8 @@ class TokenConfig(BaseModel):
4140 """Class representing a token config entry."""
4241
4342 token : str
44- color : Optional [ str ] = "#7289DA"
45- case_sensitive : Optional [ bool ] = False
43+ color : str | None = "#7289DA"
44+ case_sensitive : bool | None = False
4645
4746
4847class _ServiceConfig (EnvConfig , env_prefix = "service_" ):
@@ -51,15 +50,18 @@ class _ServiceConfig(EnvConfig, env_prefix="service_"):
5150 interval_minutes : int
5251 tokens : list [TokenConfig ]
5352
54- @validator ("interval_minutes" )
53+ @field_validator ("interval_minutes" )
54+ @classmethod
5555 def must_be_above_zero (cls , value : int ) -> int :
5656 """Validate that the interval minutes is 1 or greater."""
5757 if value < 1 :
58- raise ValueError ("Interval must be above zero minutes." )
58+ msg = "Interval must be above zero minutes."
59+ raise ValueError (msg )
5960
6061 return value
6162
62- @validator ("tokens" )
63+ @field_validator ("tokens" )
64+ @classmethod
6365 def warn_above_ten (cls , value : list [TokenConfig ]) -> list [TokenConfig ]:
6466 """
6567 Warn a user if they have more than 10 tokens.
0 commit comments