|
3 | 3 | from typing import Any, Final |
4 | 4 |
|
5 | 5 | from aiohttp import web |
| 6 | +from common_library.pydantic_fields_extension import is_nullable |
6 | 7 | from models_library.basic_types import ( |
7 | 8 | BootModeEnum, |
8 | 9 | BuildTargetEnum, |
|
11 | 12 | VersionTag, |
12 | 13 | ) |
13 | 14 | from models_library.utils.change_case import snake_to_camel |
14 | | -from pydantic import AliasChoices, TypeAdapter, field_validator, model_validator, AnyHttpUrl |
15 | | -from pydantic.fields import Field, ModelField |
| 15 | +from pydantic import AliasChoices, TypeAdapter, ValidationInfo, field_validator, model_validator, AnyHttpUrl |
| 16 | +from pydantic.fields import Field |
16 | 17 | from pydantic.types import PositiveInt |
17 | 18 | from settings_library.base import BaseCustomSettings |
18 | 19 | from settings_library.email import SMTPSettings |
@@ -105,12 +106,12 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): |
105 | 106 | ) |
106 | 107 | WEBSERVER_LOGLEVEL: LogLevel = Field( |
107 | 108 | default=LogLevel.WARNING.value, |
108 | | - env=["WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"], |
| 109 | + validation_alias=AliasChoices("WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"), |
109 | 110 | # NOTE: suffix '_LOGLEVEL' is used overall |
110 | 111 | ) |
111 | 112 | WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field( |
112 | 113 | default=False, |
113 | | - env=["WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"], |
| 114 | + validation_alias=AliasChoices("WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"), |
114 | 115 | description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!", |
115 | 116 | ) |
116 | 117 | # TODO: find a better name!? |
@@ -168,51 +169,50 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): |
168 | 169 | ) |
169 | 170 |
|
170 | 171 | WEBSERVER_DYNAMIC_SCHEDULER: DynamicSchedulerSettings | None = Field( |
171 | | - auto_default_from_env=True, description="dynamic-scheduler plugin settings" |
| 172 | + description="dynamic-scheduler plugin settings", json_schema_extra={"auto_default_from_env": True} |
172 | 173 | ) |
173 | 174 |
|
174 | | - WEBSERVER_REDIS: RedisSettings | None = Field(auto_default_from_env=True) |
| 175 | + WEBSERVER_REDIS: RedisSettings | None = Field(json_schema_extra={"auto_default_from_env": True}) |
175 | 176 |
|
176 | 177 | WEBSERVER_REST: RestSettings | None = Field( |
177 | | - auto_default_from_env=True, description="rest api plugin" |
| 178 | + description="rest api plugin", json_schema_extra={"auto_default_from_env": True} |
178 | 179 | ) |
179 | 180 |
|
180 | 181 | WEBSERVER_RESOURCE_MANAGER: ResourceManagerSettings = Field( |
181 | | - auto_default_from_env=True, description="resource_manager plugin" |
| 182 | + description="resource_manager plugin", json_schema_extra={"auto_default_from_env": True} |
182 | 183 | ) |
183 | 184 | WEBSERVER_RESOURCE_USAGE_TRACKER: ResourceUsageTrackerSettings | None = Field( |
184 | | - auto_default_from_env=True, |
185 | | - description="resource usage tracker service client's plugin", |
| 185 | + description="resource usage tracker service client's plugin", json_schema_extra={"auto_default_from_env": True} |
186 | 186 | ) |
187 | 187 | WEBSERVER_SCICRUNCH: SciCrunchSettings | None = Field( |
188 | | - auto_default_from_env=True, description="scicrunch plugin" |
| 188 | + description="scicrunch plugin", json_schema_extra={"auto_default_from_env": True} |
189 | 189 | ) |
190 | 190 | WEBSERVER_SESSION: SessionSettings = Field( |
191 | | - auto_default_from_env=True, description="session plugin" |
| 191 | + description="session plugin", json_schema_extra={"auto_default_from_env": True} |
192 | 192 | ) |
193 | 193 |
|
194 | 194 | WEBSERVER_STATICWEB: StaticWebserverModuleSettings | None = Field( |
195 | | - auto_default_from_env=True, description="static-webserver service plugin" |
| 195 | + description="static-webserver service plugin", json_schema_extra={"auto_default_from_env": True} |
196 | 196 | ) |
197 | 197 | WEBSERVER_STORAGE: StorageSettings | None = Field( |
198 | | - auto_default_from_env=True, description="storage service client's plugin" |
| 198 | + description="storage service client's plugin", json_schema_extra={"auto_default_from_env": True} |
199 | 199 | ) |
200 | 200 | WEBSERVER_STUDIES_DISPATCHER: StudiesDispatcherSettings | None = Field( |
201 | | - auto_default_from_env=True, description="studies dispatcher plugin" |
| 201 | + description="studies dispatcher plugin", json_schema_extra={"auto_default_from_env": True} |
202 | 202 | ) |
203 | 203 |
|
204 | 204 | WEBSERVER_TRACING: TracingSettings | None = Field( |
205 | | - auto_default_from_env=True, description="tracing plugin" |
| 205 | + description="tracing plugin", json_schema_extra={"auto_default_from_env": True} |
206 | 206 | ) |
207 | 207 |
|
208 | 208 | WEBSERVER_PROJECTS: ProjectsSettings | None = Field( |
209 | | - auto_default_from_env=True, description="projects plugin" |
| 209 | + description="projects plugin", json_schema_extra={"auto_default_from_env": True} |
210 | 210 | ) |
211 | 211 | WEBSERVER_RABBITMQ: RabbitSettings | None = Field( |
212 | | - auto_default_from_env=True, description="rabbitmq plugin" |
| 212 | + description="rabbitmq plugin", json_schema_extra={"auto_default_from_env": True} |
213 | 213 | ) |
214 | 214 | WEBSERVER_USERS: UsersSettings | None = Field( |
215 | | - auto_default_from_env=True, description="users plugin" |
| 215 | + description="users plugin", json_schema_extra={"auto_default_from_env": True} |
216 | 216 | ) |
217 | 217 |
|
218 | 218 | # These plugins only require (for the moment) an entry to toggle between enabled/disabled |
@@ -268,17 +268,18 @@ def build_vcs_release_url_if_unset(cls, values): |
268 | 268 | mode="before" |
269 | 269 | ) |
270 | 270 | @classmethod |
271 | | - def enable_only_if_dev_features_allowed(cls, v, values, field: ModelField): |
| 271 | + def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo): |
272 | 272 | """Ensures that plugins 'under development' get programatically |
273 | 273 | disabled if WEBSERVER_DEV_FEATURES_ENABLED=False |
274 | 274 | """ |
275 | | - if values["WEBSERVER_DEV_FEATURES_ENABLED"]: |
| 275 | + if info.data["WEBSERVER_DEV_FEATURES_ENABLED"]: |
276 | 276 | return v |
277 | 277 | if v: |
278 | 278 | _logger.warning( |
279 | | - "%s still under development and will be disabled.", field.name |
| 279 | + "%s still under development and will be disabled.", info.field_name |
280 | 280 | ) |
281 | | - return None if field.allow_none else False |
| 281 | + |
| 282 | + return None if info.field_name and is_nullable(cls.model_fields[info.field_name]) else False |
282 | 283 |
|
283 | 284 | @cached_property |
284 | 285 | def log_level(self) -> int: |
|
0 commit comments