11from functools import cached_property
2+ from typing import Annotated
23
4+ from common_library .basic_types import DEFAULT_FACTORY
35from models_library .products import ProductName
4- from pydantic import (
5- AliasChoices ,
6- Field ,
7- HttpUrl ,
8- PositiveInt ,
9- SecretStr ,
10- field_validator ,
11- )
6+ from pydantic import AliasChoices , Field , HttpUrl , SecretStr , field_validator
127from servicelib .logging_utils_filtering import LoggerName , MessageSubstring
13- from settings_library .base import BaseCustomSettings
14- from settings_library .basic_types import BuildTargetEnum , LogLevel , VersionTag
8+ from settings_library .application import BaseApplicationSettings
9+ from settings_library .basic_types import LogLevel , VersionTag
1510from settings_library .tracing import TracingSettings
1611from settings_library .utils_logging import MixinLoggingSettings
1712
1813from .._meta import API_VERSION , API_VTAG , PROJECT_NAME
1914
2015
21- class _BaseApplicationSettings (BaseCustomSettings , MixinLoggingSettings ):
16+ class _BaseApplicationSettings (BaseApplicationSettings , MixinLoggingSettings ):
2217 """Base settings of any osparc service's app"""
2318
2419 # CODE STATICS ---------------------------------------------------------
2520 API_VERSION : str = API_VERSION
2621 APP_NAME : str = PROJECT_NAME
2722 API_VTAG : VersionTag = API_VTAG
2823
29- # IMAGE BUILDTIME ------------------------------------------------------
30- # @Makefile
31- SC_BUILD_DATE : str | None = None
32- SC_BUILD_TARGET : BuildTargetEnum | None = None
33- SC_VCS_REF : str | None = None
34- SC_VCS_URL : str | None = None
35-
36- # @Dockerfile
37- SC_BOOT_TARGET : BuildTargetEnum | None = None
38- SC_HEALTHCHECK_TIMEOUT : PositiveInt | None = Field (
39- default = None ,
40- description = "If a single run of the check takes longer than timeout seconds "
41- "then the check is considered to have failed."
42- "It takes retries consecutive failures of the health check for the container to be considered unhealthy." ,
43- )
44- SC_USER_ID : int | None = None
45- SC_USER_NAME : str | None = None
46-
4724 # RUNTIME -----------------------------------------------------------
4825
49- INVITATIONS_LOGLEVEL : LogLevel = Field (
50- default = LogLevel .INFO ,
51- validation_alias = AliasChoices ("INVITATIONS_LOGLEVEL" , "LOG_LEVEL" , "LOGLEVEL" ),
52- )
53- INVITATIONS_LOG_FORMAT_LOCAL_DEV_ENABLED : bool = Field (
54- default = False ,
55- validation_alias = AliasChoices (
56- "INVITATIONS_LOG_FORMAT_LOCAL_DEV_ENABLED" ,
57- "LOG_FORMAT_LOCAL_DEV_ENABLED" ,
26+ INVITATIONS_LOGLEVEL : Annotated [
27+ LogLevel ,
28+ Field (
29+ validation_alias = AliasChoices (
30+ "INVITATIONS_LOGLEVEL" , "LOG_LEVEL" , "LOGLEVEL"
31+ ),
32+ ),
33+ ] = LogLevel .INFO
34+
35+ INVITATIONS_LOG_FORMAT_LOCAL_DEV_ENABLED : Annotated [
36+ bool ,
37+ Field (
38+ validation_alias = AliasChoices (
39+ "INVITATIONS_LOG_FORMAT_LOCAL_DEV_ENABLED" ,
40+ "LOG_FORMAT_LOCAL_DEV_ENABLED" ,
41+ ),
42+ description = "Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!" ,
5843 ),
59- description = "Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!" ,
60- )
61- INVITATIONS_LOG_FILTER_MAPPING : dict [LoggerName , list [MessageSubstring ]] = Field (
62- default_factory = dict ,
63- validation_alias = AliasChoices (
64- "INVITATIONS_LOG_FILTER_MAPPING" , "LOG_FILTER_MAPPING"
44+ ] = False
45+
46+ INVITATIONS_LOG_FILTER_MAPPING : Annotated [
47+ dict [LoggerName , list [MessageSubstring ]],
48+ Field (
49+ default_factory = dict ,
50+ validation_alias = AliasChoices (
51+ "INVITATIONS_LOG_FILTER_MAPPING" , "LOG_FILTER_MAPPING"
52+ ),
53+ 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." ,
6554 ),
66- 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." ,
67- )
55+ ] = DEFAULT_FACTORY
6856
6957 @cached_property
7058 def LOG_LEVEL (self ):
7159 return self .INVITATIONS_LOGLEVEL
7260
7361 @field_validator ("INVITATIONS_LOGLEVEL" , mode = "before" )
7462 @classmethod
75- def valid_log_level (cls , value : str ) -> str :
63+ def _valid_log_level (cls , value : str ) -> str :
7664 return cls .validate_log_level (value )
7765
7866
@@ -83,23 +71,27 @@ class MinimalApplicationSettings(_BaseApplicationSettings):
8371 are not related to the web server.
8472 """
8573
86- INVITATIONS_SWAGGER_API_DOC_ENABLED : bool = Field (
87- default = True , description = "If true, it displays swagger doc at /doc"
88- )
74+ INVITATIONS_SWAGGER_API_DOC_ENABLED : Annotated [
75+ bool , Field ( description = "If true, it displays swagger doc at /doc" )
76+ ] = True
8977
90- INVITATIONS_SECRET_KEY : SecretStr = Field (
91- ...,
92- description = "Secret key to generate invitations. "
93- "TIP: simcore-service-invitations generate-key" ,
94- min_length = 44 ,
95- )
96-
97- INVITATIONS_OSPARC_URL : HttpUrl = Field (..., description = "Target platform" )
98- INVITATIONS_DEFAULT_PRODUCT : ProductName = Field (
99- ...,
100- description = "Default product if not specified in the request. "
101- "WARNING: this product must be defined in INVITATIONS_OSPARC_URL" ,
102- )
78+ INVITATIONS_SECRET_KEY : Annotated [
79+ SecretStr ,
80+ Field (
81+ description = "Secret key to generate invitations. "
82+ "TIP: simcore-service-invitations generate-key" ,
83+ min_length = 44 ,
84+ ),
85+ ]
86+
87+ INVITATIONS_OSPARC_URL : Annotated [HttpUrl , Field (description = "Target platform" )]
88+ INVITATIONS_DEFAULT_PRODUCT : Annotated [
89+ ProductName ,
90+ Field (
91+ description = "Default product if not specified in the request. "
92+ "WARNING: this product must be defined in INVITATIONS_OSPARC_URL" ,
93+ ),
94+ ]
10395
10496
10597class ApplicationSettings (MinimalApplicationSettings ):
@@ -108,18 +100,25 @@ class ApplicationSettings(MinimalApplicationSettings):
108100 These settings includes extra configuration for the http-API
109101 """
110102
111- INVITATIONS_USERNAME : str = Field (
112- ...,
113- description = "Username for HTTP Basic Auth. Required if started as a web app." ,
114- min_length = 3 ,
115- )
116- INVITATIONS_PASSWORD : SecretStr = Field (
117- ...,
118- description = "Password for HTTP Basic Auth. Required if started as a web app." ,
119- min_length = 10 ,
120- )
103+ INVITATIONS_USERNAME : Annotated [
104+ str ,
105+ Field (
106+ description = "Username for HTTP Basic Auth. Required if started as a web app." ,
107+ min_length = 3 ,
108+ ),
109+ ]
110+ INVITATIONS_PASSWORD : Annotated [
111+ SecretStr ,
112+ Field (
113+ description = "Password for HTTP Basic Auth. Required if started as a web app." ,
114+ min_length = 10 ,
115+ ),
116+ ]
121117 INVITATIONS_PROMETHEUS_INSTRUMENTATION_ENABLED : bool = True
122- INVITATIONS_TRACING : TracingSettings | None = Field (
123- json_schema_extra = {"auto_default_from_env" : True },
124- description = "settings for opentelemetry tracing" ,
125- )
118+ INVITATIONS_TRACING : Annotated [
119+ TracingSettings | None ,
120+ Field (
121+ json_schema_extra = {"auto_default_from_env" : True },
122+ description = "settings for opentelemetry tracing" ,
123+ ),
124+ ]
0 commit comments