Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade EFS guardian service (Pydantic v2) #6516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions services/efs-guardian/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ aiormq==6.8.0
# via aio-pika
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via
# fast-depends
Expand All @@ -54,13 +56,10 @@ arrow==1.3.0
# -r requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/_base.in
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/_base.in
async-timeout==4.0.3
# via
# aiohttp
# redis
attrs==23.2.0
# via
# aiohttp
Expand Down Expand Up @@ -99,24 +98,10 @@ dnspython==2.6.1
# via email-validator
email-validator==2.1.1
# via pydantic
exceptiongroup==1.2.1
# via anyio
fast-depends==2.4.3
# via faststream
fastapi==0.99.1
fastapi==0.115.0
# via
# -c requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../requirements/constraints.txt
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
# -r requirements/_base.in
# prometheus-fastapi-instrumentator
Expand Down Expand Up @@ -203,7 +188,7 @@ prometheus-client==0.20.0
# prometheus-fastapi-instrumentator
prometheus-fastapi-instrumentator==6.1.0
# via -r requirements/../../../packages/service-library/requirements/_fastapi.in
pydantic==1.10.15
pydantic==2.9.2
# via
# -c requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand All @@ -214,7 +199,6 @@ pydantic==1.10.15
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
# -c requirements/../../../packages/service-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../requirements/constraints.txt
Expand All @@ -231,6 +215,26 @@ pydantic==1.10.15
# -r requirements/../../../packages/settings-library/requirements/_base.in
# fast-depends
# fastapi
# pydantic-extra-types
# pydantic-settings
pydantic-core==2.23.4
# via pydantic
pydantic-extra-types==2.9.0
# via
# -r requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
pydantic-settings==2.5.2
# via
# -r requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
# -r requirements/../../../packages/aws-library/requirements/../../../packages/settings-library/requirements/_base.in
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
# -r requirements/../../../packages/settings-library/requirements/_base.in
pygments==2.18.0
# via rich
pyinstrument==4.6.2
Expand All @@ -241,6 +245,8 @@ python-dateutil==2.9.0.post0
# via
# arrow
# botocore
python-dotenv==1.0.1
# via pydantic-settings
pyyaml==6.0.1
# via
# -c requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -302,7 +308,7 @@ sniffio==1.3.1
# via
# anyio
# httpx
starlette==0.27.0
starlette==0.38.6
# via
# -c requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/aws-library/requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -352,16 +358,15 @@ typing-extensions==4.11.0
# via
# aiodebug
# aiodocker
# anyio
# fastapi
# faststream
# pydantic
# pydantic-core
# typer
# types-aiobotocore
# types-aiobotocore-ec2
# types-aiobotocore-s3
# types-aiobotocore-ssm
# uvicorn
urllib3==2.2.1
# via
# -c requirements/../../../packages/aws-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand Down
31 changes: 13 additions & 18 deletions services/efs-guardian/requirements/_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ aiosignal==1.3.1
# via
# -c requirements/_base.txt
# aiohttp
annotated-types==0.7.0
# via
# -c requirements/_base.txt
# pydantic
antlr4-python3-runtime==4.13.2
# via moto
anyio==4.4.0
Expand All @@ -19,11 +23,6 @@ anyio==4.4.0
# httpx
asgi-lifespan==2.1.0
# via -r requirements/_test.in
async-timeout==4.0.3
# via
# -c requirements/_base.txt
# aiohttp
# redis
attrs==23.2.0
# via
# -c requirements/_base.txt
Expand Down Expand Up @@ -82,11 +81,6 @@ docker==7.1.0
# via
# -r requirements/_test.in
# moto
exceptiongroup==1.2.1
# via
# -c requirements/_base.txt
# anyio
# pytest
faker==27.0.0
# via -r requirements/_test.in
fakeredis==2.23.5
Expand Down Expand Up @@ -205,11 +199,15 @@ py-partiql-parser==0.5.5
# via moto
pycparser==2.22
# via cffi
pydantic==1.10.15
pydantic==2.9.2
# via
# -c requirements/../../../requirements/constraints.txt
# -c requirements/_base.txt
# aws-sam-translator
pydantic-core==2.23.4
# via
# -c requirements/_base.txt
# pydantic
pyparsing==3.1.2
# via moto
pytest==8.3.2
Expand All @@ -235,7 +233,9 @@ python-dateutil==2.9.0.post0
# faker
# moto
python-dotenv==1.0.1
# via -r requirements/_test.in
# via
# -c requirements/_base.txt
# -r requirements/_test.in
pyyaml==6.0.1
# via
# -c requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -296,19 +296,14 @@ sortedcontainers==2.4.0
# via fakeredis
sympy==1.13.2
# via cfn-lint
tomli==2.0.1
# via
# coverage
# pytest
typing-extensions==4.11.0
# via
# -c requirements/_base.txt
# aiodocker
# anyio
# aws-sam-translator
# cfn-lint
# fakeredis
# pydantic
# pydantic-core
urllib3==2.2.1
# via
# -c requirements/../../../requirements/constraints.txt
Expand Down
10 changes: 0 additions & 10 deletions services/efs-guardian/requirements/_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,12 @@ setuptools==73.0.1
# via
# -c requirements/_test.txt
# pip-tools
tomli==2.0.1
# via
# -c requirements/_test.txt
# black
# build
# mypy
# pip-tools
# pylint
tomlkit==0.13.2
# via pylint
typing-extensions==4.11.0
# via
# -c requirements/_base.txt
# -c requirements/_test.txt
# astroid
# black
# mypy
virtualenv==20.26.3
# via pre-commit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def create_app(settings: ApplicationSettings) -> FastAPI:
logger.info("app settings: %s", settings.json(indent=1))
logger.info("app settings: %s", settings.model_dump_json(indent=1))

app = FastAPI(
debug=settings.EFS_GUARDIAN_DEBUG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
LogLevel,
VersionTag,
)
from pydantic import Field, PositiveInt, validator
from pydantic import AliasChoices, Field, PositiveInt, field_validator
from settings_library.base import BaseCustomSettings
from settings_library.efs import AwsEfsSettings
from settings_library.rabbit import RabbitSettings
Expand Down Expand Up @@ -59,28 +59,35 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):

# RUNTIME -----------------------------------------------------------
EFS_GUARDIAN_DEBUG: bool = Field(
default=False, description="Debug mode", env=["EFS_GUARDIAN_DEBUG", "DEBUG"]
default=False,
description="Debug mode",
validation_alias=AliasChoices("EFS_GUARDIAN_DEBUG", "DEBUG"),
)
EFS_GUARDIAN_LOGLEVEL: LogLevel = Field(
LogLevel.INFO, env=["EFS_GUARDIAN_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"]
LogLevel.INFO,
validation_alias=AliasChoices("EFS_GUARDIAN_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
)
EFS_GUARDIAN_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
default=False,
env=[
validation_alias=AliasChoices(
"EFS_GUARDIAN_LOG_FORMAT_LOCAL_DEV_ENABLED",
"LOG_FORMAT_LOCAL_DEV_ENABLED",
],
),
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
)

EFS_GUARDIAN_AWS_EFS_SETTINGS: AwsEfsSettings = Field(auto_default_from_env=True)
EFS_GUARDIAN_RABBITMQ: RabbitSettings = Field(auto_default_from_env=True)
EFS_GUARDIAN_AWS_EFS_SETTINGS: AwsEfsSettings = Field(
json_schema_extra={"auto_default_from_env": True}
)
EFS_GUARDIAN_RABBITMQ: RabbitSettings = Field(
json_schema_extra={"auto_default_from_env": True}
)

@cached_property
def LOG_LEVEL(self) -> LogLevel: # noqa: N802
return self.EFS_GUARDIAN_LOGLEVEL

@validator("EFS_GUARDIAN_LOGLEVEL")
@field_validator("EFS_GUARDIAN_LOGLEVEL")
@classmethod
def valid_log_level(cls, value: str) -> str:
return cls.validate_log_level(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from typing import Any

from models_library.errors_classes import OsparcErrorMixin
from common_library.errors_classes import OsparcErrorMixin


class EfsGuardianBaseError(OsparcErrorMixin, Exception):
def __init__(self, **ctx: Any) -> None:
super().__init__(**ctx)
"""EFS guardian base error class."""
Loading