Skip to content

Commit c498b77

Browse files
committed
improv: add logging; linting
1 parent 6bda0f5 commit c498b77

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

aws_lambda_powertools/utilities/validation/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import json
2+
import logging
23
from typing import Dict
34

45
import fastjsonschema
56

67
from .exceptions import InvalidEnvelopeExpressionError, InvalidSchemaError, SchemaValidationError
78

9+
logger = logging.getLogger(__name__)
10+
811
try:
912
import jmespath
1013

@@ -36,6 +39,7 @@ def unwrap_event_from_envelope(data: Dict, envelope: str, jmespath_options: Dict
3639
jmespath_options = {"custom_functions": PowertoolsJson()}
3740

3841
try:
42+
logger.debug(f"Envelope detected: {envelope}. JMESPath options: {jmespath_options}")
3943
return jmespath.search(envelope, data, options=jmespath.Options(**jmespath_options))
4044
except jmespath.exceptions.LexerError as e:
4145
raise InvalidEnvelopeExpressionError(e)

aws_lambda_powertools/utilities/validation/validator.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
from typing import Any, Callable, Dict, Union
43

@@ -18,9 +17,6 @@ def validator(
1817
envelope: str = None,
1918
jmespath_options: Dict = None,
2019
):
21-
if isinstance(event, str):
22-
event = json.loads(event)
23-
2420
if envelope:
2521
event = unwrap_event_from_envelope(data=event, envelope=envelope, jmespath_options=jmespath_options)
2622

@@ -41,7 +37,4 @@ def validate(event: Dict, schema: Dict = None, envelope: str = None, jmespath_op
4137
if envelope:
4238
event = unwrap_event_from_envelope(data=event, envelope=envelope, jmespath_options=jmespath_options)
4339

44-
if isinstance(event, str):
45-
event = json.loads(event)
46-
4740
validate_data_against_schema(data=event, schema=schema)

0 commit comments

Comments
 (0)