11from functools import cached_property
22from typing import Annotated
33
4+ from common_library .basic_types import DEFAULT_FACTORY
45from models_library .basic_types import BootModeEnum , LogLevel
56from pydantic import (
67 AliasChoices ,
2829
2930class WebServerSettings (WebServerBaseSettings , MixinSessionSettings ):
3031
31- WEBSERVER_SESSION_SECRET_KEY : SecretStr = Field (
32- ...,
33- description = "Secret key to encrypt cookies. "
34- 'TIP: python3 -c "from cryptography.fernet import *; print(Fernet.generate_key())"' ,
35- min_length = 44 ,
36- validation_alias = AliasChoices (
37- "SESSION_SECRET_KEY" , "WEBSERVER_SESSION_SECRET_KEY"
32+ WEBSERVER_SESSION_SECRET_KEY : Annotated [
33+ SecretStr ,
34+ Field (
35+ description = "Secret key to encrypt cookies. "
36+ 'TIP: python3 -c "from cryptography.fernet import *; print(Fernet.generate_key())"' ,
37+ min_length = 44 ,
38+ validation_alias = AliasChoices (
39+ "SESSION_SECRET_KEY" , "WEBSERVER_SESSION_SECRET_KEY"
40+ ),
3841 ),
39- )
42+ ]
4043 WEBSERVER_SESSION_NAME : str = DEFAULT_SESSION_COOKIE_NAME
4144
4245 @field_validator ("WEBSERVER_SESSION_SECRET_KEY" )
4346 @classmethod
44- def check_valid_fernet_key (cls , v ):
47+ def _check_valid_fernet_key (cls , v ):
4548 return cls .do_check_valid_fernet_key (v )
4649
4750
@@ -50,12 +53,14 @@ def check_valid_fernet_key(cls, v):
5053
5154class BasicSettings (BaseCustomSettings , MixinLoggingSettings ):
5255 # DEVELOPMENT
53- API_SERVER_DEV_FEATURES_ENABLED : bool = Field (
54- default = False ,
55- validation_alias = AliasChoices (
56- "API_SERVER_DEV_FEATURES_ENABLED" , "FAKE_API_SERVER_ENABLED"
56+ API_SERVER_DEV_FEATURES_ENABLED : Annotated [
57+ bool ,
58+ Field (
59+ validation_alias = AliasChoices (
60+ "API_SERVER_DEV_FEATURES_ENABLED" , "FAKE_API_SERVER_ENABLED"
61+ ),
5762 ),
58- )
63+ ] = False
5964
6065 # LOGGING
6166 LOG_LEVEL : Annotated [
@@ -67,20 +72,27 @@ class BasicSettings(BaseCustomSettings, MixinLoggingSettings):
6772 ),
6873 ] = LogLevel .INFO
6974
70- API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED : bool = Field (
71- default = False ,
72- validation_alias = AliasChoices (
73- "API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED" , "LOG_FORMAT_LOCAL_DEV_ENABLED"
75+ API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED : Annotated [
76+ bool ,
77+ Field (
78+ validation_alias = AliasChoices (
79+ "API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED" ,
80+ "LOG_FORMAT_LOCAL_DEV_ENABLED" ,
81+ ),
82+ description = "Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!" ,
7483 ),
75- description = "Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!" ,
76- )
77- API_SERVER_LOG_FILTER_MAPPING : dict [LoggerName , list [MessageSubstring ]] = Field (
78- default_factory = dict ,
79- validation_alias = AliasChoices (
80- "API_SERVER_LOG_FILTER_MAPPING" , "LOG_FILTER_MAPPING"
84+ ] = False
85+
86+ API_SERVER_LOG_FILTER_MAPPING : Annotated [
87+ dict [LoggerName , list [MessageSubstring ]],
88+ Field (
89+ default_factory = dict ,
90+ validation_alias = AliasChoices (
91+ "API_SERVER_LOG_FILTER_MAPPING" , "LOG_FILTER_MAPPING"
92+ ),
93+ description = "is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out." ,
8194 ),
82- description = "is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out." ,
83- )
95+ ] = DEFAULT_FACTORY
8496
8597 @field_validator ("LOG_LEVEL" , mode = "before" )
8698 @classmethod
@@ -98,35 +110,43 @@ class ApplicationSettings(BasicSettings):
98110 Field (json_schema_extra = {"auto_default_from_env" : True }),
99111 ]
100112
101- API_SERVER_RABBITMQ : RabbitSettings | None = Field (
102- json_schema_extra = {"auto_default_from_env" : True },
103- description = "settings for service/rabbitmq" ,
104- )
113+ API_SERVER_RABBITMQ : Annotated [
114+ RabbitSettings | None ,
115+ Field (
116+ json_schema_extra = {"auto_default_from_env" : True },
117+ description = "settings for service/rabbitmq" ,
118+ ),
119+ ]
105120
106121 # SERVICES with http API
107- API_SERVER_WEBSERVER : WebServerSettings | None = Field (
108- json_schema_extra = {"auto_default_from_env" : True }
109- )
110- API_SERVER_CATALOG : CatalogSettings | None = Field (
111- json_schema_extra = {"auto_default_from_env" : True }
112- )
113- API_SERVER_STORAGE : StorageSettings | None = Field (
114- json_schema_extra = {"auto_default_from_env" : True }
115- )
116- API_SERVER_DIRECTOR_V2 : DirectorV2Settings | None = Field (
117- json_schema_extra = {"auto_default_from_env" : True }
118- )
122+ API_SERVER_WEBSERVER : Annotated [
123+ WebServerSettings | None ,
124+ Field (json_schema_extra = {"auto_default_from_env" : True }),
125+ ]
126+ API_SERVER_CATALOG : Annotated [
127+ CatalogSettings | None , Field (json_schema_extra = {"auto_default_from_env" : True })
128+ ]
129+ API_SERVER_STORAGE : Annotated [
130+ StorageSettings | None , Field (json_schema_extra = {"auto_default_from_env" : True })
131+ ]
132+ API_SERVER_DIRECTOR_V2 : Annotated [
133+ DirectorV2Settings | None ,
134+ Field (json_schema_extra = {"auto_default_from_env" : True }),
135+ ]
119136 API_SERVER_LOG_CHECK_TIMEOUT_SECONDS : NonNegativeInt = 3 * 60
120137 API_SERVER_PROMETHEUS_INSTRUMENTATION_ENABLED : bool = True
121138 API_SERVER_HEALTH_CHECK_TASK_PERIOD_SECONDS : PositiveInt = 30
122139 API_SERVER_HEALTH_CHECK_TASK_TIMEOUT_SECONDS : PositiveInt = 10
123140 API_SERVER_ALLOWED_HEALTH_CHECK_FAILURES : PositiveInt = 5
124141 API_SERVER_PROMETHEUS_INSTRUMENTATION_COLLECT_SECONDS : PositiveInt = 5
125142 API_SERVER_PROFILING : bool = False
126- API_SERVER_TRACING : TracingSettings | None = Field (
127- description = "settings for opentelemetry tracing" ,
128- json_schema_extra = {"auto_default_from_env" : True },
129- )
143+ API_SERVER_TRACING : Annotated [
144+ TracingSettings | None ,
145+ Field (
146+ description = "settings for opentelemetry tracing" ,
147+ json_schema_extra = {"auto_default_from_env" : True },
148+ ),
149+ ]
130150
131151 @cached_property
132152 def debug (self ) -> bool :
0 commit comments