99 ensure_unique_dict_values_validator ,
1010 ensure_unique_list_values_validator ,
1111)
12- from pydantic import Field , PositiveInt , validator
12+ from pydantic import AliasChoices , field_validator , Field , PositiveInt
1313from settings_library .aws_s3_cli import AwsS3CliSettings
1414from settings_library .base import BaseCustomSettings
1515from settings_library .efs import AwsEfsSettings
@@ -45,7 +45,7 @@ class RCloneSettings(SettingsLibraryRCloneSettings):
4545 description = "VFS operation mode, defines how and when the disk cache is synced" ,
4646 )
4747
48- @validator ("R_CLONE_POLL_INTERVAL_SECONDS" )
48+ @field_validator ("R_CLONE_POLL_INTERVAL_SECONDS" )
4949 @classmethod
5050 def enforce_r_clone_requirement (cls , v : int , values ) -> PositiveInt :
5151 dir_cache_time = values ["R_CLONE_DIR_CACHE_TIME_SECONDS" ]
@@ -60,7 +60,7 @@ class PlacementSettings(BaseCustomSettings):
6060 # https://docs.docker.com/engine/swarm/services/#control-service-placement.
6161 DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS : list [DockerPlacementConstraint ] = Field (
6262 default_factory = list ,
63- example = '["node.labels.region==east", "one!=yes"]' ,
63+ examples = [ '["node.labels.region==east", "one!=yes"]' ] ,
6464 )
6565
6666 DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS : dict [
@@ -72,20 +72,18 @@ class PlacementSettings(BaseCustomSettings):
7272 "see https://github.com/ITISFoundation/osparc-simcore/issues/5250 "
7373 "When `None` (default), uses generic resources"
7474 ),
75- example = '{"AIRAM": "node.labels.custom==true"}' ,
75+ examples = [ '{"AIRAM": "node.labels.custom==true"}' ] ,
7676 )
7777
78- _unique_custom_constraints = validator (
78+ _unique_custom_constraints = field_validator (
7979 "DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS" ,
80- allow_reuse = True ,
8180 )(ensure_unique_list_values_validator )
8281
83- _unique_resource_placement_constraints_substitutions = validator (
82+ _unique_resource_placement_constraints_substitutions = field_validator (
8483 "DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS" ,
85- allow_reuse = True ,
8684 )(ensure_unique_dict_values_validator )
8785
88- @validator ("DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS" )
86+ @field_validator ("DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS" )
8987 @classmethod
9088 def warn_if_any_values_provided (cls , value : dict ) -> dict :
9189 if len (value ) > 0 :
@@ -101,40 +99,40 @@ def warn_if_any_values_provided(cls, value: dict) -> dict:
10199class DynamicSidecarSettings (BaseCustomSettings , MixinLoggingSettings ):
102100 DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED : bool = Field ( # doc: https://docs.docker.com/engine/swarm/networking/#configure-service-discovery
103101 default = False ,
104- env = [ "DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED" ] ,
102+ validation_alias = AliasChoices ( "DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED" ) ,
105103 description = "dynamic-sidecar's service 'endpoint_spec' with {'Mode': 'dnsrr'}" ,
106104 )
107105 DYNAMIC_SIDECAR_SC_BOOT_MODE : BootModeEnum = Field (
108106 ...,
109107 description = "Boot mode used for the dynamic-sidecar services"
110108 "By defaults, it uses the same boot mode set for the director-v2" ,
111- env = [ "DYNAMIC_SIDECAR_SC_BOOT_MODE" , "SC_BOOT_MODE" ] ,
109+ validation_alias = AliasChoices ( "DYNAMIC_SIDECAR_SC_BOOT_MODE" , "SC_BOOT_MODE" ) ,
112110 )
113111
114112 DYNAMIC_SIDECAR_LOG_LEVEL : str = Field (
115113 "WARNING" ,
116114 description = "log level of the dynamic sidecar"
117115 "If defined, it captures global env vars LOG_LEVEL and LOGLEVEL from the director-v2 service" ,
118- env = [ "DYNAMIC_SIDECAR_LOG_LEVEL" , "LOG_LEVEL" , "LOGLEVEL" ] ,
116+ validation_alias = AliasChoices ( "DYNAMIC_SIDECAR_LOG_LEVEL" , "LOG_LEVEL" , "LOGLEVEL" ) ,
119117 )
120118
121119 DYNAMIC_SIDECAR_IMAGE : str = Field (
122120 ...,
123- regex = DYNAMIC_SIDECAR_DOCKER_IMAGE_RE ,
121+ pattern = DYNAMIC_SIDECAR_DOCKER_IMAGE_RE ,
124122 description = "used by the director to start a specific version of the dynamic-sidecar" ,
125123 )
126124
127- DYNAMIC_SIDECAR_R_CLONE_SETTINGS : RCloneSettings = Field (auto_default_from_env = True )
125+ DYNAMIC_SIDECAR_R_CLONE_SETTINGS : RCloneSettings = Field (json_schema_extra = { "auto_default_from_env" : True } )
128126
129127 DYNAMIC_SIDECAR_AWS_S3_CLI_SETTINGS : AwsS3CliSettings | None = Field (
130- auto_default_from_env = True
128+ json_schema_extra = { "auto_default_from_env" : True }
131129 )
132130 DYNAMIC_SIDECAR_EFS_SETTINGS : AwsEfsSettings | None = Field (
133- auto_default_from_env = True
131+ json_schema_extra = { "auto_default_from_env" : True }
134132 )
135133
136134 DYNAMIC_SIDECAR_PLACEMENT_SETTINGS : PlacementSettings = Field (
137- auto_default_from_env = True
135+ json_schema_extra = { "auto_default_from_env" : True }
138136 )
139137
140138 #
@@ -144,7 +142,7 @@ class DynamicSidecarSettings(BaseCustomSettings, MixinLoggingSettings):
144142 DYNAMIC_SIDECAR_MOUNT_PATH_DEV : Path | None = Field (
145143 None ,
146144 description = "Host path to the dynamic-sidecar project. Used as source path to mount to the dynamic-sidecar [DEVELOPMENT ONLY]" ,
147- example = "osparc-simcore/services/dynamic-sidecar" ,
145+ examples = [ "osparc-simcore/services/dynamic-sidecar" ] ,
148146 )
149147
150148 DYNAMIC_SIDECAR_PORT : PortInt = Field (
@@ -157,9 +155,10 @@ class DynamicSidecarSettings(BaseCustomSettings, MixinLoggingSettings):
157155 description = "Publishes the service on localhost for debuging and testing [DEVELOPMENT ONLY]"
158156 "Can be used to access swagger doc from the host as http://127.0.0.1:30023/dev/doc "
159157 "where 30023 is the host published port" ,
158+ validate_default = True
160159 )
161160
162- @validator ("DYNAMIC_SIDECAR_MOUNT_PATH_DEV" , pre = True )
161+ @field_validator ("DYNAMIC_SIDECAR_MOUNT_PATH_DEV" , mode = "before" )
163162 @classmethod
164163 def auto_disable_if_production (cls , v , values ):
165164 if v and values .get ("DYNAMIC_SIDECAR_SC_BOOT_MODE" ) == BootModeEnum .PRODUCTION :
@@ -170,7 +169,7 @@ def auto_disable_if_production(cls, v, values):
170169 return None
171170 return v
172171
173- @validator ("DYNAMIC_SIDECAR_EXPOSE_PORT" , pre = True , always = True )
172+ @field_validator ("DYNAMIC_SIDECAR_EXPOSE_PORT" , mode = "before" )
174173 @classmethod
175174 def auto_enable_if_development (cls , v , values ):
176175 if (
@@ -180,12 +179,12 @@ def auto_enable_if_development(cls, v, values):
180179 return True
181180 return v
182181
183- @validator ("DYNAMIC_SIDECAR_IMAGE" , pre = True )
182+ @field_validator ("DYNAMIC_SIDECAR_IMAGE" , mode = "before" )
184183 @classmethod
185184 def strip_leading_slashes (cls , v : str ) -> str :
186185 return v .lstrip ("/" )
187186
188- @validator ("DYNAMIC_SIDECAR_LOG_LEVEL" )
187+ @field_validator ("DYNAMIC_SIDECAR_LOG_LEVEL" )
189188 @classmethod
190189 def _validate_log_level (cls , value ) -> str :
191190 log_level : str = cls .validate_log_level (value )
0 commit comments