Skip to content

Commit d1d13ab

Browse files
authored
feature: upgrade to pydantic v2 (#682)
1 parent a481060 commit d1d13ab

File tree

24 files changed

+549
-376
lines changed

24 files changed

+549
-376
lines changed

.github/workflows/scorecard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ jobs:
3232

3333
steps:
3434
- name: "Checkout code"
35-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
35+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3636
with:
3737
persist-credentials: false
3838

3939
- name: "Run analysis"
40-
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
40+
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0
4141
with:
4242
results_file: results.sarif
4343
results_format: sarif
@@ -59,7 +59,7 @@ jobs:
5959
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6060
# format to the repository Actions tab.
6161
- name: "Upload artifact"
62-
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
62+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
6363
with:
6464
name: SARIF file
6565
path: results.sarif

.github/workflows/serverless-service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
python-version: "3.10"
3030
- name: Set up Node
31-
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
31+
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
3232
with:
3333
node-version: "16"
3434
- name: Install dependencies

cdk/my_service/configuration/configuration_construct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ def _get_and_validate_configuration(self, environment: str) -> str:
8888
conf_filepath = current / (f'json/{environment}_configuration.json')
8989
configuration_str = conf_filepath.read_text()
9090
# validate configuration (check feature flags schema structure if exists)
91-
FeatureFlagsConfiguration.parse_raw(configuration_str)
91+
FeatureFlagsConfiguration.model_validate_json(configuration_str)
9292
return configuration_str

cdk/my_service/configuration/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from typing import Any, Dict, Optional
22

33
from aws_lambda_powertools.utilities.feature_flags import SchemaValidator
4-
from pydantic import BaseModel, validator
4+
from pydantic import BaseModel, field_validator
55

66

77
class FeatureFlagsConfiguration(BaseModel):
88
features: Optional[Dict[str, Any]]
99

10-
@validator('features', pre=True)
10+
@field_validator('features', mode='before')
1111
def validate_features(cls, value):
1212
validator = SchemaValidator(value)
1313
try:

cdk/my_service/service_stack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,9 @@ def _add_security_tests(self) -> None:
8080
'id': 'AwsSolutions-COG4',
8181
'reason': 'not using cognito'
8282
},
83+
{
84+
'id': 'AwsSolutions-L1',
85+
'reason': 'https://github.com/aws/aws-cdk/issues/26451'
86+
},
8387
],
8488
)

docs/examples/best_practices/dynamic_configuration/evaluate_feature_flags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from http import HTTPStatus
22
from typing import Any, Dict
33

4+
from aws_lambda_env_modeler import init_environment_variables
45
from aws_lambda_powertools.utilities.feature_flags.exceptions import ConfigurationStoreError, SchemaValidationError
56
from aws_lambda_powertools.utilities.typing import LambdaContext
67

78
from service.handlers.schemas.dynamic_configuration import MyConfiguration
89
from service.handlers.schemas.env_vars import MyHandlerEnvVars
910
from service.handlers.utils.dynamic_configuration import get_dynamic_configuration_store, parse_configuration
10-
from service.handlers.utils.env_vars_parser import init_environment_variables
1111
from service.handlers.utils.http_responses import build_response
1212
from service.handlers.utils.observability import logger
1313

@@ -16,7 +16,7 @@
1616
def my_handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]:
1717
try:
1818
my_configuration: MyConfiguration = parse_configuration(model=MyConfiguration) # type: ignore
19-
logger.debug('fetched dynamic configuration', extra={'configuration': my_configuration.dict()})
19+
logger.debug('fetched dynamic configuration', extra={'configuration': my_configuration.model_dump()})
2020
except (SchemaValidationError, ConfigurationStoreError) as exc:
2121
logger.exception(f'dynamic configuration error, error={str(exc)}')
2222
return build_response(http_status=HTTPStatus.INTERNAL_SERVER_ERROR, body={})

docs/examples/best_practices/dynamic_configuration/parse_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from http import HTTPStatus
22
from typing import Any, Dict
33

4+
from aws_lambda_env_modeler import init_environment_variables
45
from aws_lambda_powertools.utilities.feature_flags.exceptions import ConfigurationStoreError, SchemaValidationError
56
from aws_lambda_powertools.utilities.typing import LambdaContext
67

78
from service.handlers.schemas.dynamic_configuration import MyConfiguration
89
from service.handlers.schemas.env_vars import MyHandlerEnvVars
910
from service.handlers.utils.dynamic_configuration import parse_configuration
10-
from service.handlers.utils.env_vars_parser import init_environment_variables
1111
from service.handlers.utils.http_responses import build_response
1212
from service.handlers.utils.observability import logger
1313

docs/examples/best_practices/environment_variables/getter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from http import HTTPStatus
33
from typing import Any, Dict
44

5+
from aws_lambda_env_modeler import get_environment_variables, init_environment_variables
56
from aws_lambda_powertools.utilities.typing import LambdaContext
67

78
from service.handlers.schemas.env_vars import MyHandlerEnvVars
8-
from service.handlers.utils.env_vars_parser import get_environment_variables, init_environment_variables
99

1010

1111
@init_environment_variables(model=MyHandlerEnvVars)

docs/examples/best_practices/environment_variables/my_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from http import HTTPStatus
33
from typing import Any, Dict
44

5+
from aws_lambda_env_modeler import get_environment_variables, init_environment_variables
56
from aws_lambda_powertools.utilities.typing import LambdaContext
67

78
from service.handlers.schemas.env_vars import MyHandlerEnvVars
8-
from service.handlers.utils.env_vars_parser import get_environment_variables, init_environment_variables
99

1010

1111
@init_environment_variables(model=MyHandlerEnvVars)

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ markdown_extensions:
7373
class: mermaid
7474
format: !!python/name:pymdownx.superfences.fence_code_format
7575

76-
copyright: Copyright © 2022 Ran Isenberg
76+
copyright: Copyright © 2023 Ran Isenberg
7777

7878
plugins:
7979
- git-revision-date

0 commit comments

Comments
 (0)