Skip to content

Commit

Permalink
Merge branch 'develop' into fix-match-reserved-word
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brewer committed Aug 16, 2021
2 parents c18b81c + 25f067a commit 6825fbc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
5 changes: 5 additions & 0 deletions aws_lambda_powertools/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Shared exceptions that don't belong to a single utility"""


class InvalidEnvelopeExpressionError(Exception):
"""When JMESPath fails to parse expression"""
8 changes: 5 additions & 3 deletions aws_lambda_powertools/shared/jmespath_utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/utilities/feature_flags/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
6 changes: 4 additions & 2 deletions aws_lambda_powertools/utilities/validation/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from ...exceptions import InvalidEnvelopeExpressionError


class SchemaValidationError(Exception):
"""When serialization fail schema validation"""

Expand All @@ -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"]
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/validation/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)

Expand Down
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/idempotency/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6825fbc

Please sign in to comment.