From 8930915303b5b59b154ad22716e1dde27a182903 Mon Sep 17 00:00:00 2001 From: Heitor Lessa Date: Mon, 16 Aug 2021 20:57:05 +0200 Subject: [PATCH 1/3] chore(shared): fix cyclic import & refactor data extraction fn (#613) --- aws_lambda_powertools/exceptions/__init__.py | 5 +++++ aws_lambda_powertools/shared/jmespath_utils.py | 8 +++++--- .../utilities/feature_flags/appconfig.py | 2 +- aws_lambda_powertools/utilities/validation/exceptions.py | 6 ++++-- aws_lambda_powertools/utilities/validation/validator.py | 4 ++-- pyproject.toml | 2 +- tests/functional/idempotency/conftest.py | 4 ++-- 7 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 aws_lambda_powertools/exceptions/__init__.py diff --git a/aws_lambda_powertools/exceptions/__init__.py b/aws_lambda_powertools/exceptions/__init__.py new file mode 100644 index 00000000000..cb8724c4490 --- /dev/null +++ b/aws_lambda_powertools/exceptions/__init__.py @@ -0,0 +1,5 @@ +"""Shared exceptions that don't belong to a single utility""" + + +class InvalidEnvelopeExpressionError(Exception): + """When JMESPath fails to parse expression""" diff --git a/aws_lambda_powertools/shared/jmespath_utils.py b/aws_lambda_powertools/shared/jmespath_utils.py index f2a865d4807..9cc736aedfb 100644 --- a/aws_lambda_powertools/shared/jmespath_utils.py +++ b/aws_lambda_powertools/shared/jmespath_utils.py @@ -1,13 +1,15 @@ import base64 import gzip import json +import logging from typing import Any, Dict, Optional, Union import jmespath from jmespath.exceptions import LexerError -from aws_lambda_powertools.utilities.validation import InvalidEnvelopeExpressionError -from aws_lambda_powertools.utilities.validation.base import logger +from aws_lambda_powertools.exceptions import InvalidEnvelopeExpressionError + +logger = logging.getLogger(__name__) class PowertoolsFunctions(jmespath.functions.Functions): @@ -27,7 +29,7 @@ def _func_powertools_base64_gzip(self, value): return uncompressed.decode() -def unwrap_event_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any: +def extract_data_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any: """Searches data using JMESPath expression Parameters diff --git a/aws_lambda_powertools/utilities/feature_flags/appconfig.py b/aws_lambda_powertools/utilities/feature_flags/appconfig.py index 30c70b6c590..2e0edc3b9b1 100644 --- a/aws_lambda_powertools/utilities/feature_flags/appconfig.py +++ b/aws_lambda_powertools/utilities/feature_flags/appconfig.py @@ -80,7 +80,7 @@ def get_configuration(self) -> Dict[str, Any]: ) if self.envelope: - config = jmespath_utils.unwrap_event_from_envelope( + config = jmespath_utils.extract_data_from_envelope( data=config, envelope=self.envelope, jmespath_options=self.jmespath_options ) diff --git a/aws_lambda_powertools/utilities/validation/exceptions.py b/aws_lambda_powertools/utilities/validation/exceptions.py index 7dbe3f786e4..d4aaa500ec7 100644 --- a/aws_lambda_powertools/utilities/validation/exceptions.py +++ b/aws_lambda_powertools/utilities/validation/exceptions.py @@ -1,3 +1,6 @@ +from ...exceptions import InvalidEnvelopeExpressionError + + class SchemaValidationError(Exception): """When serialization fail schema validation""" @@ -6,5 +9,4 @@ class InvalidSchemaFormatError(Exception): """When JSON Schema is in invalid format""" -class InvalidEnvelopeExpressionError(Exception): - """When JMESPath fails to parse expression""" +__all__ = ["SchemaValidationError", "InvalidSchemaFormatError", "InvalidEnvelopeExpressionError"] diff --git a/aws_lambda_powertools/utilities/validation/validator.py b/aws_lambda_powertools/utilities/validation/validator.py index 02a685a1565..d9ce35fe41b 100644 --- a/aws_lambda_powertools/utilities/validation/validator.py +++ b/aws_lambda_powertools/utilities/validation/validator.py @@ -117,7 +117,7 @@ def handler(event, context): When JMESPath expression to unwrap event is invalid """ if envelope: - event = jmespath_utils.unwrap_event_from_envelope( + event = jmespath_utils.extract_data_from_envelope( data=event, envelope=envelope, jmespath_options=jmespath_options ) @@ -219,7 +219,7 @@ def handler(event, context): When JMESPath expression to unwrap event is invalid """ if envelope: - event = jmespath_utils.unwrap_event_from_envelope( + event = jmespath_utils.extract_data_from_envelope( data=event, envelope=envelope, jmespath_options=jmespath_options ) diff --git a/pyproject.toml b/pyproject.toml index bfb083371a3..033282f7465 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ pydantic = ["pydantic", "email-validator"] [tool.coverage.run] source = ["aws_lambda_powertools"] -omit = ["tests/*"] +omit = ["tests/*", "aws_lambda_powertools/exceptions/*"] branch = true [tool.coverage.html] diff --git a/tests/functional/idempotency/conftest.py b/tests/functional/idempotency/conftest.py index 9f61d50d656..e613bb85e60 100644 --- a/tests/functional/idempotency/conftest.py +++ b/tests/functional/idempotency/conftest.py @@ -11,7 +11,7 @@ from botocore.config import Config from jmespath import functions -from aws_lambda_powertools.shared.jmespath_utils import unwrap_event_from_envelope +from aws_lambda_powertools.shared.jmespath_utils import extract_data_from_envelope from aws_lambda_powertools.shared.json_encoder import Encoder from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer from aws_lambda_powertools.utilities.idempotency.idempotency import IdempotencyConfig @@ -149,7 +149,7 @@ def hashed_idempotency_key(lambda_apigw_event, default_jmespath, lambda_context) @pytest.fixture def hashed_idempotency_key_with_envelope(lambda_apigw_event): - event = unwrap_event_from_envelope( + event = extract_data_from_envelope( data=lambda_apigw_event, envelope=envelopes.API_GATEWAY_HTTP, jmespath_options={} ) return "test-func#" + hashlib.md5(json.dumps(event).encode()).hexdigest() From 94b8e8aa7b143df5d5f19cb6c347273191750aa6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Aug 2021 20:30:54 +0000 Subject: [PATCH 2/3] chore(deps): bump boto3 from 1.18.21 to 1.18.22 (#614) Bumps [boto3](https://github.com/boto/boto3) from 1.18.21 to 1.18.22.
Changelog

Sourced from boto3's changelog.

1.18.22

  • api-change:iotsitewise: [botocore] AWS IoT SiteWise added query window for the interpolation interval. AWS IoT SiteWise computes each interpolated value by using data points from the timestamp of each interval minus the window to the timestamp of each interval plus the window.
  • api-change:s3: [botocore] Documentation updates for Amazon S3
  • api-change:codebuild: [botocore] CodeBuild now allows you to select how batch build statuses are sent to the source provider for a project.
  • api-change:ds: [botocore] This release adds support for describing client authentication settings.
  • api-change:config: [botocore] Update ResourceType enum with values for Backup Plan, Selection, Vault, RecoveryPoint; ECS Cluster, Service, TaskDefinition; EFS AccessPoint, FileSystem; EKS Cluster; ECR Repository resources
  • api-change:license-manager: [botocore] AWS License Manager now allows end users to call CheckoutLicense API using new CheckoutType PERPETUAL. Perpetual checkouts allow sellers to check out a quantity of entitlements to be drawn down for consumption.
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=boto3&package-manager=pip&previous-version=1.18.21&new-version=1.18.22)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- poetry.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 02e4568e973..05ab9cc868c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -81,14 +81,14 @@ d = ["aiohttp (>=3.3.2)", "aiohttp-cors"] [[package]] name = "boto3" -version = "1.18.21" +version = "1.18.22" description = "The AWS SDK for Python" category = "main" optional = false python-versions = ">= 3.6" [package.dependencies] -botocore = ">=1.21.21,<1.22.0" +botocore = ">=1.21.22,<1.22.0" jmespath = ">=0.7.1,<1.0.0" s3transfer = ">=0.5.0,<0.6.0" @@ -97,7 +97,7 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.21.21" +version = "1.21.22" description = "Low-level, data-driven core of boto 3." category = "main" optional = false @@ -1086,12 +1086,12 @@ black = [ {file = "black-20.8b1.tar.gz", hash = "sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea"}, ] boto3 = [ - {file = "boto3-1.18.21-py3-none-any.whl", hash = "sha256:59b6e8e79b2114e21388288a06a004f2a9378b1e0fc58466a35da8fb74fe2dd8"}, - {file = "boto3-1.18.21.tar.gz", hash = "sha256:00748c760dc30be61c6db4b092718f6a9f8d27c767da0e232695a65adb75cde8"}, + {file = "boto3-1.18.22-py3-none-any.whl", hash = "sha256:6cc7011cb857fecee54884ff344d6b793cd22af51142f715706c757d26d02bb1"}, + {file = "boto3-1.18.22.tar.gz", hash = "sha256:7405ae77ce4f2151fae1b542183f9c0f7ffb57c288b1f152819cfcb88e9cf297"}, ] botocore = [ - {file = "botocore-1.21.21-py3-none-any.whl", hash = "sha256:fa5ac13829d24fcdd385e82c3b6d78e22d93f427cca8dac38158cae84a8cc2f5"}, - {file = "botocore-1.21.21.tar.gz", hash = "sha256:12cfe74b0a5c44afb34bdd86c1f8ad74bc2ad9ec168eaed9040ef70cb3db944f"}, + {file = "botocore-1.21.22-py3-none-any.whl", hash = "sha256:9df7a84840bcea10eb68f816d562c77656ec253a3a0dc3724e7e9ac086656e28"}, + {file = "botocore-1.21.22.tar.gz", hash = "sha256:9c133caab58b04b4a9ab3f6523cc61cf815c1a5fde7b5ee279eefa48dc3a01d1"}, ] certifi = [ {file = "certifi-2020.12.5-py2.py3-none-any.whl", hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"}, From 25f067a6c3d243c5d5f53578e276d1e340a8de87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Aug 2021 20:30:59 +0000 Subject: [PATCH 3/3] chore(deps-dev): bump flake8-comprehensions from 3.6.0 to 3.6.1 (#615) Bumps [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) from 3.6.0 to 3.6.1.
Changelog

Sourced from flake8-comprehensions's changelog.

3.6.1 (2021-08-16)

  • Fix type hint for tree argument.

    Thanks to kasium for the report in Issue [#352](https://github.com/adamchainz/flake8-comprehensions/issues/352) <https://github.com/adamchainz/flake8-comprehensions/issues/352>__.

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=flake8-comprehensions&package-manager=pip&previous-version=3.6.0&new-version=3.6.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 05ab9cc868c..06f679006e1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -273,7 +273,7 @@ test = ["coverage", "coveralls", "mock", "pytest", "pytest-cov"] [[package]] name = "flake8-comprehensions" -version = "3.6.0" +version = "3.6.1" description = "A flake8 plugin to help you write better list/set/dict comprehensions." category = "dev" optional = false @@ -1059,7 +1059,7 @@ pydantic = ["pydantic", "email-validator"] [metadata] lock-version = "1.1" python-versions = "^3.6.1" -content-hash = "ef80bd8445c78d1ad83e8b8b6809f41b753643085cc12735775cb4dbb015c539" +content-hash = "5b8f1cde398c9218d69c14c7c8abe2ba2369e554f1c680b5005f2cb7deb10d00" [metadata.files] appdirs = [ @@ -1199,8 +1199,8 @@ flake8-builtins = [ {file = "flake8_builtins-1.5.3-py2.py3-none-any.whl", hash = "sha256:7706babee43879320376861897e5d1468e396a40b8918ed7bccf70e5f90b8687"}, ] flake8-comprehensions = [ - {file = "flake8-comprehensions-3.6.0.tar.gz", hash = "sha256:4dbaf4be0b25376d568e072dd39798e0c9a40c7adb1b3f95ea680f94e1f9b9dd"}, - {file = "flake8_comprehensions-3.6.0-py3-none-any.whl", hash = "sha256:7a86d1f4dfb53ad0806eb352e9c5754fbd48f34093737d4e7a14e83f13c4df47"}, + {file = "flake8-comprehensions-3.6.1.tar.gz", hash = "sha256:4888de89248b7f7535159189ff693c77f8354f6d37a02619fa28c9921a913aa0"}, + {file = "flake8_comprehensions-3.6.1-py3-none-any.whl", hash = "sha256:e9a010b99aa90c05790d45281ad9953df44a4a08a1a8f6cd41f98b4fc6a268a0"}, ] flake8-debugger = [ {file = "flake8-debugger-4.0.0.tar.gz", hash = "sha256:e43dc777f7db1481db473210101ec2df2bd39a45b149d7218a618e954177eda6"}, diff --git a/pyproject.toml b/pyproject.toml index 033282f7465..5a92641e26c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ black = "^20.8b1" flake8 = "^3.9.0" flake8-black = "^0.2.3" flake8-builtins = "^1.5.3" -flake8-comprehensions = "^3.6.0" +flake8-comprehensions = "^3.6.1" flake8-debugger = "^4.0.0" flake8-fixme = "^1.1.1" flake8-isort = "^4.0.0"