Skip to content

Commit f233071

Browse files
committed
cleanup payments settings
1 parent 15103a3 commit f233071

File tree

1 file changed

+123
-88
lines changed
  • services/payments/src/simcore_service_payments/core

1 file changed

+123
-88
lines changed

services/payments/src/simcore_service_payments/core/settings.py

Lines changed: 123 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from functools import cached_property
33
from typing import Annotated
44

5+
from common_library.basic_types import DEFAULT_FACTORY
56
from models_library.basic_types import NonNegativeDecimal
67
from pydantic import (
78
AliasChoices,
@@ -36,32 +37,41 @@ class _BaseApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
3637

3738
# RUNTIME -----------------------------------------------------------
3839

39-
PAYMENTS_LOGLEVEL: LogLevel = Field(
40-
default=LogLevel.INFO,
41-
validation_alias=AliasChoices("PAYMENTS_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
42-
)
43-
PAYMENTS_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
44-
default=False,
45-
validation_alias=AliasChoices(
46-
"LOG_FORMAT_LOCAL_DEV_ENABLED", "PAYMENTS_LOG_FORMAT_LOCAL_DEV_ENABLED"
47-
),
48-
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
49-
)
50-
PAYMENTS_LOG_FILTER_MAPPING: dict[LoggerName, list[MessageSubstring]] = Field(
51-
default_factory=dict,
52-
validation_alias=AliasChoices(
53-
"LOG_FILTER_MAPPING", "PAYMENTS_LOG_FILTER_MAPPING"
54-
),
55-
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.",
56-
)
40+
PAYMENTS_LOGLEVEL: Annotated[
41+
LogLevel,
42+
Field(
43+
validation_alias=AliasChoices("PAYMENTS_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
44+
),
45+
] = LogLevel.INFO
46+
47+
PAYMENTS_LOG_FORMAT_LOCAL_DEV_ENABLED: Annotated[
48+
bool,
49+
Field(
50+
validation_alias=AliasChoices(
51+
"LOG_FORMAT_LOCAL_DEV_ENABLED", "PAYMENTS_LOG_FORMAT_LOCAL_DEV_ENABLED"
52+
),
53+
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
54+
),
55+
] = False
56+
57+
PAYMENTS_LOG_FILTER_MAPPING: Annotated[
58+
dict[LoggerName, list[MessageSubstring]],
59+
Field(
60+
default_factory=dict,
61+
validation_alias=AliasChoices(
62+
"LOG_FILTER_MAPPING", "PAYMENTS_LOG_FILTER_MAPPING"
63+
),
64+
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.",
65+
),
66+
] = DEFAULT_FACTORY
5767

5868
@cached_property
5969
def LOG_LEVEL(self): # noqa: N802
6070
return self.PAYMENTS_LOGLEVEL
6171

6272
@field_validator("PAYMENTS_LOGLEVEL", mode="before")
6373
@classmethod
64-
def valid_log_level(cls, value: str) -> str:
74+
def _valid_log_level(cls, value: str) -> str:
6575
return cls.validate_log_level(value)
6676

6777

@@ -71,31 +81,37 @@ class ApplicationSettings(_BaseApplicationSettings):
7181
These settings includes extra configuration for the http-API
7282
"""
7383

74-
PAYMENTS_GATEWAY_URL: HttpUrl = Field(
75-
..., description="Base url to the payment gateway"
76-
)
77-
78-
PAYMENTS_GATEWAY_API_SECRET: SecretStr = Field(
79-
..., description="Credentials for payments-gateway api"
80-
)
81-
82-
PAYMENTS_USERNAME: str = Field(
83-
...,
84-
description="Username for Auth. Required if started as a web app.",
85-
min_length=3,
86-
)
87-
PAYMENTS_PASSWORD: SecretStr = Field(
88-
...,
89-
description="Password for Auth. Required if started as a web app.",
90-
min_length=10,
91-
)
92-
93-
PAYMENTS_ACCESS_TOKEN_SECRET_KEY: SecretStr = Field(
94-
...,
95-
description="To generate a random password with openssl in hex format with 32 bytes, run `openssl rand -hex 32`",
96-
min_length=30,
97-
)
98-
PAYMENTS_ACCESS_TOKEN_EXPIRE_MINUTES: PositiveFloat = Field(default=30)
84+
PAYMENTS_GATEWAY_URL: Annotated[
85+
HttpUrl, Field(description="Base url to the payment gateway")
86+
]
87+
88+
PAYMENTS_GATEWAY_API_SECRET: Annotated[
89+
SecretStr, Field(description="Credentials for payments-gateway api")
90+
]
91+
92+
PAYMENTS_USERNAME: Annotated[
93+
str,
94+
Field(
95+
description="Username for Auth. Required if started as a web app.",
96+
min_length=3,
97+
),
98+
]
99+
PAYMENTS_PASSWORD: Annotated[
100+
SecretStr,
101+
Field(
102+
description="Password for Auth. Required if started as a web app.",
103+
min_length=10,
104+
),
105+
]
106+
107+
PAYMENTS_ACCESS_TOKEN_SECRET_KEY: Annotated[
108+
SecretStr,
109+
Field(
110+
description="To generate a random password with openssl in hex format with 32 bytes, run `openssl rand -hex 32`",
111+
min_length=30,
112+
),
113+
]
114+
PAYMENTS_ACCESS_TOKEN_EXPIRE_MINUTES: PositiveFloat = 30.0
99115

100116
PAYMENTS_AUTORECHARGE_MIN_BALANCE_IN_CREDITS: Annotated[
101117
NonNegativeDecimal,
@@ -118,50 +134,69 @@ class ApplicationSettings(_BaseApplicationSettings):
118134
),
119135
] = Decimal(10_000)
120136

121-
PAYMENTS_AUTORECHARGE_ENABLED: bool = Field(
122-
default=False,
123-
description="Based on this variable is the auto recharge functionality in Payment service enabled",
124-
)
125-
126-
PAYMENTS_BCC_EMAIL: EmailStr | None = Field(
127-
default=None,
128-
description="Special email for finance department. Currently used to BCC invoices.",
129-
)
130-
131-
PAYMENTS_RABBITMQ: RabbitSettings = Field(
132-
json_schema_extra={"auto_default_from_env": True},
133-
description="settings for service/rabbitmq",
134-
)
135-
136-
PAYMENTS_TRACING: TracingSettings | None = Field(
137-
json_schema_extra={"auto_default_from_env": True},
138-
description="settings for opentelemetry tracing",
139-
)
140-
141-
PAYMENTS_POSTGRES: PostgresSettings = Field(
142-
json_schema_extra={"auto_default_from_env": True},
143-
description="settings for postgres service",
144-
)
145-
146-
PAYMENTS_STRIPE_URL: HttpUrl = Field(
147-
..., description="Base url to the payment Stripe"
148-
)
149-
PAYMENTS_STRIPE_API_SECRET: SecretStr = Field(
150-
..., description="Credentials for Stripe api"
151-
)
152-
153-
PAYMENTS_SWAGGER_API_DOC_ENABLED: bool = Field(
154-
default=True, description="If true, it displays swagger doc at /doc"
155-
)
156-
157-
PAYMENTS_RESOURCE_USAGE_TRACKER: ResourceUsageTrackerSettings = Field(
158-
json_schema_extra={"auto_default_from_env": True},
159-
description="settings for RUT service",
160-
)
137+
PAYMENTS_AUTORECHARGE_ENABLED: Annotated[
138+
bool,
139+
Field(
140+
description="Based on this variable is the auto recharge functionality in Payment service enabled",
141+
),
142+
] = False
143+
144+
PAYMENTS_BCC_EMAIL: Annotated[
145+
EmailStr | None,
146+
Field(
147+
description="Special email for finance department. Currently used to BCC invoices.",
148+
),
149+
] = None
150+
151+
PAYMENTS_RABBITMQ: Annotated[
152+
RabbitSettings,
153+
Field(
154+
json_schema_extra={"auto_default_from_env": True},
155+
description="settings for service/rabbitmq",
156+
),
157+
]
158+
159+
PAYMENTS_TRACING: Annotated[
160+
TracingSettings | None,
161+
Field(
162+
json_schema_extra={"auto_default_from_env": True},
163+
description="settings for opentelemetry tracing",
164+
),
165+
]
166+
167+
PAYMENTS_POSTGRES: Annotated[
168+
PostgresSettings,
169+
Field(
170+
json_schema_extra={"auto_default_from_env": True},
171+
description="settings for postgres service",
172+
),
173+
]
174+
175+
PAYMENTS_STRIPE_URL: Annotated[
176+
HttpUrl, Field(description="Base url to the payment Stripe")
177+
]
178+
PAYMENTS_STRIPE_API_SECRET: Annotated[
179+
SecretStr, Field(description="Credentials for Stripe api")
180+
]
181+
182+
PAYMENTS_SWAGGER_API_DOC_ENABLED: Annotated[
183+
bool, Field(description="If true, it displays swagger doc at /doc")
184+
] = True
185+
186+
PAYMENTS_RESOURCE_USAGE_TRACKER: Annotated[
187+
ResourceUsageTrackerSettings,
188+
Field(
189+
json_schema_extra={"auto_default_from_env": True},
190+
description="settings for RUT service",
191+
),
192+
]
161193

162194
PAYMENTS_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True
163195

164-
PAYMENTS_EMAIL: SMTPSettings | None = Field(
165-
json_schema_extra={"auto_default_from_env": True},
166-
description="optional email (see notifier_email service)",
167-
)
196+
PAYMENTS_EMAIL: Annotated[
197+
SMTPSettings | None,
198+
Field(
199+
json_schema_extra={"auto_default_from_env": True},
200+
description="optional email (see notifier_email service)",
201+
),
202+
]

0 commit comments

Comments
 (0)