11import datetime
22from functools import cached_property
3- from typing import Any , ClassVar , Final , cast
3+ from typing import Annotated , Final , cast
44
55from aws_library .ec2 import EC2InstanceBootSpecific , EC2Tags
66from fastapi import FastAPI
1414from models_library .clusters import InternalClusterAuthentication
1515from models_library .docker import DockerLabelKey
1616from pydantic import (
17+ AliasChoices ,
1718 AnyUrl ,
1819 Field ,
1920 NonNegativeInt ,
2021 PositiveInt ,
21- parse_obj_as ,
22- root_validator ,
23- validator ,
22+ TypeAdapter ,
23+ field_validator ,
24+ model_validator ,
2425)
26+ from pytest_simcore .helpers .dict_tools import ConfigDict
2527from settings_library .base import BaseCustomSettings
2628from settings_library .docker_registry import RegistrySettings
2729from settings_library .ec2 import EC2Settings
@@ -41,10 +43,9 @@ class AutoscalingSSMSettings(SSMSettings):
4143
4244
4345class AutoscalingEC2Settings (EC2Settings ):
44- class Config (EC2Settings .Config ):
45- env_prefix = AUTOSCALING_ENV_PREFIX
46-
47- schema_extra : ClassVar [dict [str , Any ]] = { # type: ignore[misc]
46+ model_config = ConfigDict (
47+ env_prefix = AUTOSCALING_ENV_PREFIX ,
48+ json_schema_extra = {
4849 "examples" : [
4950 {
5051 f"{ AUTOSCALING_ENV_PREFIX } EC2_ACCESS_KEY_ID" : "my_access_key_id" ,
@@ -53,7 +54,8 @@ class Config(EC2Settings.Config):
5354 f"{ AUTOSCALING_ENV_PREFIX } EC2_SECRET_ACCESS_KEY" : "my_secret_access_key" ,
5455 }
5556 ],
56- }
57+ },
58+ )
5759
5860
5961class EC2InstancesSettings (BaseCustomSettings ):
@@ -93,7 +95,7 @@ class EC2InstancesSettings(BaseCustomSettings):
9395
9496 EC2_INSTANCES_SECURITY_GROUP_IDS : list [str ] = Field (
9597 ...,
96- min_items = 1 ,
98+ min_length = 1 ,
9799 description = "A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic"
98100 " (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html), "
99101 " this is required to start a new EC2 instance" ,
@@ -130,7 +132,7 @@ class EC2InstancesSettings(BaseCustomSettings):
130132 description = "ARN the EC2 instance should be attached to (example: arn:aws:iam::XXXXX:role/NAME), to disable pass an empty string" ,
131133 )
132134
133- @validator ("EC2_INSTANCES_TIME_BEFORE_DRAINING" )
135+ @field_validator ("EC2_INSTANCES_TIME_BEFORE_DRAINING" )
134136 @classmethod
135137 def ensure_draining_delay_time_is_in_range (
136138 cls , value : datetime .timedelta
@@ -141,7 +143,7 @@ def ensure_draining_delay_time_is_in_range(
141143 value = datetime .timedelta (minutes = 1 )
142144 return value
143145
144- @validator ("EC2_INSTANCES_TIME_BEFORE_TERMINATION" )
146+ @field_validator ("EC2_INSTANCES_TIME_BEFORE_TERMINATION" )
145147 @classmethod
146148 def ensure_termination_delay_time_is_in_range (
147149 cls , value : datetime .timedelta
@@ -152,14 +154,14 @@ def ensure_termination_delay_time_is_in_range(
152154 value = datetime .timedelta (minutes = 59 )
153155 return value
154156
155- @validator ("EC2_INSTANCES_ALLOWED_TYPES" )
157+ @field_validator ("EC2_INSTANCES_ALLOWED_TYPES" )
156158 @classmethod
157159 def check_valid_instance_names (
158160 cls , value : dict [str , EC2InstanceBootSpecific ]
159161 ) -> dict [str , EC2InstanceBootSpecific ]:
160162 # NOTE: needed because of a flaw in BaseCustomSettings
161163 # issubclass raises TypeError if used on Aliases
162- parse_obj_as (list [InstanceTypeType ], list (value ))
164+ TypeAdapter (list [InstanceTypeType ]). validate_python ( list (value ))
163165 return value
164166
165167
@@ -181,7 +183,7 @@ class NodesMonitoringSettings(BaseCustomSettings):
181183
182184
183185class DaskMonitoringSettings (BaseCustomSettings ):
184- DASK_MONITORING_URL : AnyUrl = Field (
186+ DASK_MONITORING_URL : Annotated [ str , AnyUrl ] = Field (
185187 ..., description = "the url to the osparc-dask-scheduler"
186188 )
187189 DASK_SCHEDULER_AUTH : InternalClusterAuthentication = Field (
@@ -217,36 +219,39 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
217219
218220 # RUNTIME -----------------------------------------------------------
219221 AUTOSCALING_DEBUG : bool = Field (
220- default = False , description = "Debug mode" , env = ["AUTOSCALING_DEBUG" , "DEBUG" ]
222+ default = False ,
223+ description = "Debug mode" ,
224+ validation_alias = AliasChoices ("AUTOSCALING_DEBUG" , "DEBUG" ),
221225 )
222- AUTOSCALING_REMOTE_DEBUG_PORT : PortInt = PortInt ( 3000 )
226+ AUTOSCALING_REMOTE_DEBUG_PORT : PortInt = 3000
223227
224228 AUTOSCALING_LOGLEVEL : LogLevel = Field (
225- LogLevel .INFO , env = ["AUTOSCALING_LOGLEVEL" , "LOG_LEVEL" , "LOGLEVEL" ]
229+ LogLevel .INFO ,
230+ validation_alias = AliasChoices ("AUTOSCALING_LOGLEVEL" , "LOG_LEVEL" , "LOGLEVEL" ),
226231 )
227232 AUTOSCALING_LOG_FORMAT_LOCAL_DEV_ENABLED : bool = Field (
228233 default = False ,
229- env = [
234+ validation_alias = AliasChoices (
230235 "AUTOSCALING_LOG_FORMAT_LOCAL_DEV_ENABLED" ,
231236 "LOG_FORMAT_LOCAL_DEV_ENABLED" ,
232- ] ,
237+ ) ,
233238 description = "Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!" ,
234239 )
235240
236241 AUTOSCALING_EC2_ACCESS : AutoscalingEC2Settings | None = Field (
237- auto_default_from_env = True
242+ json_schema_extra = { "auto_default_from_env" : True }
238243 )
239244
240245 AUTOSCALING_SSM_ACCESS : AutoscalingSSMSettings | None = Field (
241- auto_default_from_env = True
246+ json_schema_extra = { "auto_default_from_env" : True }
242247 )
243248
244249 AUTOSCALING_EC2_INSTANCES : EC2InstancesSettings | None = Field (
245- auto_default_from_env = True
250+ json_schema_extra = { "auto_default_from_env" : True }
246251 )
247252
248253 AUTOSCALING_NODES_MONITORING : NodesMonitoringSettings | None = Field (
249- auto_default_from_env = True
254+ json_schema_extra = { "auto_default_from_env" : True }
250255 )
251256
252257 AUTOSCALING_POLL_INTERVAL : datetime .timedelta = Field (
@@ -255,13 +260,21 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
255260 "(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)" ,
256261 )
257262
258- AUTOSCALING_RABBITMQ : RabbitSettings | None = Field (auto_default_from_env = True )
263+ AUTOSCALING_RABBITMQ : RabbitSettings | None = Field (
264+ json_schema_extra = {"auto_default_from_env" : True }
265+ )
259266
260- AUTOSCALING_REDIS : RedisSettings = Field (auto_default_from_env = True )
267+ AUTOSCALING_REDIS : RedisSettings = Field (
268+ json_schema_extra = {"auto_default_from_env" : True }
269+ )
261270
262- AUTOSCALING_REGISTRY : RegistrySettings | None = Field (auto_default_from_env = True )
271+ AUTOSCALING_REGISTRY : RegistrySettings | None = Field (
272+ json_schema_extra = {"auto_default_from_env" : True }
273+ )
263274
264- AUTOSCALING_DASK : DaskMonitoringSettings | None = Field (auto_default_from_env = True )
275+ AUTOSCALING_DASK : DaskMonitoringSettings | None = Field (
276+ json_schema_extra = {"auto_default_from_env" : True }
277+ )
265278
266279 AUTOSCALING_PROMETHEUS_INSTRUMENTATION_ENABLED : bool = True
267280
@@ -276,12 +289,12 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
276289 def LOG_LEVEL (self ): # noqa: N802
277290 return self .AUTOSCALING_LOGLEVEL
278291
279- @validator ("AUTOSCALING_LOGLEVEL" )
292+ @field_validator ("AUTOSCALING_LOGLEVEL" )
280293 @classmethod
281294 def valid_log_level (cls , value : str ) -> str :
282295 return cls .validate_log_level (value )
283296
284- @root_validator ( )
297+ @model_validator ( mode = "after" )
285298 @classmethod
286299 def exclude_both_dynamic_computational_mode (cls , values ):
287300 if (
0 commit comments