Skip to content

Commit 5b83b66

Browse files
heitorlessadependabot[bot]leandrodamascenagithub-actions[bot]Powertools for AWS Lambda (Python) bot
authored
chore: fix merge conflict, remove itsdangerous leftovers (#2)
* fix(parameters): make cache aware of single vs multiple calls Signed-off-by: heitorlessa <[email protected]> * chore: cleanup, add test for single and nested Signed-off-by: heitorlessa <[email protected]> * chore(deps): bump pypa/gh-action-pypi-publish from 1.8.8 to 1.8.9 (aws-powertools#2943) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump the boto-typing group with 1 update (aws-powertools#2944) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Leandro Damascena <[email protected]> * chore(ci): changelog rebuild (aws-powertools#2945) Co-authored-by: Powertools for AWS Lambda (Python) bot <[email protected]> * chore(deps-dev): bump aws-cdk from 2.90.0 to 2.91.0 (aws-powertools#2947) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump gitpython from 3.1.31 to 3.1.32 in /docs (aws-powertools#2948) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump pypa/gh-action-pypi-publish from 1.8.9 to 1.8.10 (aws-powertools#2946) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Leandro Damascena <[email protected]> * chore(ci): changelog rebuild (aws-powertools#2952) Co-authored-by: Powertools for AWS Lambda (Python) bot <[email protected]> * feat(event_handler): allow stripping route prefixes using regexes (aws-powertools#2521) Co-authored-by: Roy Assis <[email protected]> Co-authored-by: Ruben Fonseca <[email protected]> * feat(metrics): add Datadog observability provider (aws-powertools#2906) Co-authored-by: Leandro Damascena <[email protected]> Co-authored-by: heitorlessa <[email protected]> * chore(deps-dev): bump xenon from 0.9.0 to 0.9.1 (aws-powertools#2955) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump actions/setup-node from 3.7.0 to 3.8.0 (aws-powertools#2957) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump cfn-lint from 0.79.6 to 0.79.7 (aws-powertools#2956) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Leandro Damascena <[email protected]> * chore(ci): changelog rebuild (aws-powertools#2958) Co-authored-by: Powertools for AWS Lambda (Python) bot <[email protected]> * docs(metrics): update Datadog integration diagram (aws-powertools#2954) Co-authored-by: Leandro Damascena <[email protected]> * docs(roadmap): add GovCloud and China region item (aws-powertools#2960) * fix(parameters): make cache aware of single vs multiple calls Signed-off-by: heitorlessa <[email protected]> * chore: cleanup, add test for single and nested Signed-off-by: heitorlessa <[email protected]> * chore(test): remove itsdangerous from perf test Signed-off-by: heitorlessa <[email protected]> * chore(deps): remove itsdangerous dependencies * chore: disable sockets in encryption sdk tests Signed-off-by: heitorlessa <[email protected]> * refactor(tests): use a test double * chore: address make pr errors Signed-off-by: heitorlessa <[email protected]> --------- Signed-off-by: heitorlessa <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Leandro Damascena <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Powertools for AWS Lambda (Python) bot <[email protected]> Co-authored-by: roy <[email protected]> Co-authored-by: Roy Assis <[email protected]> Co-authored-by: Ruben Fonseca <[email protected]> Co-authored-by: Roger Zhang <[email protected]> Co-authored-by: aal80 <[email protected]> Co-authored-by: Seshu Brahma <[email protected]>
1 parent 01885a5 commit 5b83b66

File tree

6 files changed

+120
-54
lines changed

6 files changed

+120
-54
lines changed

aws_lambda_powertools/utilities/data_masking/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ def _apply_action_to_fields(self, data: Union[dict, str], fields, action, **prov
9898
)
9999

100100
for field in fields:
101+
# prevent overriding loop variable
102+
current_field = field
101103
if not isinstance(field, str):
102-
field = json.dumps(field)
103-
keys = field.split(".")
104+
current_field = json.dumps(field)
105+
106+
keys = current_field.split(".")
104107

105108
curr_dict = my_dict_parsed
106109
for key in keys[:-1]:

poetry.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@ version = "2.23.1"
44
description = "Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverless best practices and increase developer velocity."
55
authors = ["Amazon Web Services"]
66
include = ["aws_lambda_powertools/py.typed", "THIRD-PARTY-LICENSES"]
7-
classifiers=[
8-
"Development Status :: 5 - Production/Stable",
9-
"Intended Audience :: Developers",
10-
"License :: OSI Approved :: MIT No Attribution License (MIT-0)",
11-
"Natural Language :: English",
12-
"Programming Language :: Python :: 3.7",
13-
"Programming Language :: Python :: 3.8",
14-
"Programming Language :: Python :: 3.9",
15-
"Programming Language :: Python :: 3.10",
16-
"Programming Language :: Python :: 3.11",
7+
classifiers = [
8+
"Development Status :: 5 - Production/Stable",
9+
"Intended Audience :: Developers",
10+
"License :: OSI Approved :: MIT No Attribution License (MIT-0)",
11+
"Natural Language :: English",
12+
"Programming Language :: Python :: 3.7",
13+
"Programming Language :: Python :: 3.8",
14+
"Programming Language :: Python :: 3.9",
15+
"Programming Language :: Python :: 3.10",
16+
"Programming Language :: Python :: 3.11",
1717
]
1818
repository = "https://github.com/aws-powertools/powertools-lambda-python"
1919
documentation = "https://docs.powertools.aws.dev/lambda/python/"
2020
readme = "README.md"
21-
keywords = ["aws_lambda_powertools", "aws", "tracing", "logging", "lambda", "powertools", "feature_flags", "idempotency", "middleware"]
21+
keywords = [
22+
"aws_lambda_powertools",
23+
"aws",
24+
"tracing",
25+
"logging",
26+
"lambda",
27+
"powertools",
28+
"feature_flags",
29+
"idempotency",
30+
"middleware",
31+
]
2232
# MIT-0 is not recognized as an existing license from poetry.
2333
# By using `MIT` as a license value, a `License :: OSI Approved :: MIT License` classifier is added to the classifiers list.
2434
license = "MIT"
@@ -38,7 +48,7 @@ datadog-lambda = { version = "^4.77.0", optional = true }
3848
aws-encryption-sdk = { version = "^3.1.1", optional = true }
3949

4050
[tool.poetry.dev-dependencies]
41-
coverage = {extras = ["toml"], version = "^7.2"}
51+
coverage = { extras = ["toml"], version = "^7.2" }
4252
pytest = "^7.4.1"
4353
black = "^23.3"
4454
boto3 = "^1.18"
@@ -75,7 +85,7 @@ filelock = "^3.12.2"
7585
checksumdir = "^1.2.0"
7686
mypy-boto3-appconfigdata = "^1.28.36"
7787
ijson = "^3.2.2"
78-
typed-ast = { version = "^1.5.5", python = "< 3.8"}
88+
typed-ast = { version = "^1.5.5", python = "< 3.8" }
7989
hvac = "^1.1.1"
8090
aws-requests-auth = "^0.4.3"
8191
datadog-lambda = "^4.77.0"
@@ -89,7 +99,7 @@ tracer = ["aws-xray-sdk"]
8999
all = ["pydantic", "aws-xray-sdk", "fastjsonschema", "aws-encryption-sdk"]
90100
# allow customers to run code locally without emulators (SAM CLI, etc.)
91101
aws-sdk = ["boto3"]
92-
datadog=["datadog-lambda"]
102+
datadog = ["datadog-lambda"]
93103

94104
[tool.poetry.group.dev.dependencies]
95105
cfn-lint = "0.79.9"
@@ -99,10 +109,16 @@ httpx = ">=0.23.3,<0.25.0"
99109
sentry-sdk = "^1.22.2"
100110
ruff = ">=0.0.272,<0.0.288"
101111
retry2 = "^0.9.5"
112+
pytest-socket = "^0.6.0"
102113

103114
[tool.coverage.run]
104115
source = ["aws_lambda_powertools"]
105-
omit = ["tests/*", "aws_lambda_powertools/exceptions/*", "aws_lambda_powertools/utilities/parser/types.py", "aws_lambda_powertools/utilities/jmespath_utils/envelopes.py"]
116+
omit = [
117+
"tests/*",
118+
"aws_lambda_powertools/exceptions/*",
119+
"aws_lambda_powertools/utilities/parser/types.py",
120+
"aws_lambda_powertools/utilities/jmespath_utils/envelopes.py",
121+
]
106122
branch = true
107123

108124
[tool.coverage.html]
@@ -112,26 +128,26 @@ title = "Powertools for AWS Lambda (Python) Test Coverage"
112128
[tool.coverage.report]
113129
fail_under = 90
114130
exclude_lines = [
115-
# Have to re-enable the standard pragma
116-
"pragma: no cover",
131+
# Have to re-enable the standard pragma
132+
"pragma: no cover",
117133

118-
# Don't complain about missing debug-only code:
119-
"def __repr__",
120-
"if self.debug",
134+
# Don't complain about missing debug-only code:
135+
"def __repr__",
136+
"if self.debug",
121137

122-
# Don't complain if tests don't hit defensive assertion code:
123-
"raise AssertionError",
124-
"raise NotImplementedError",
138+
# Don't complain if tests don't hit defensive assertion code:
139+
"raise AssertionError",
140+
"raise NotImplementedError",
125141

126-
# Don't complain if non-runnable code isn't run:
127-
"if 0:",
128-
"if __name__ == .__main__.:",
142+
# Don't complain if non-runnable code isn't run:
143+
"if 0:",
144+
"if __name__ == .__main__.:",
129145

130-
# Ignore runtime type checking
131-
"if TYPE_CHECKING:",
146+
# Ignore runtime type checking
147+
"if TYPE_CHECKING:",
132148

133-
# Ignore type function overload
134-
"@overload",
149+
# Ignore type function overload
150+
"@overload",
135151
]
136152

137153
[tool.isort]
@@ -164,16 +180,16 @@ minversion = "6.0"
164180
addopts = "-ra -vv"
165181
testpaths = "./tests"
166182
markers = [
167-
"perf: marks perf tests to be deselected (deselect with '-m \"not perf\"')",
183+
"perf: marks perf tests to be deselected (deselect with '-m \"not perf\"')",
168184
]
169185

170186
# MAINTENANCE: Remove these lines when drop support to Pydantic v1
171-
filterwarnings=[
187+
filterwarnings = [
172188
"ignore:.*The `parse_obj` method is deprecated*:DeprecationWarning",
173189
"ignore:.*The `parse_raw` method is deprecated*:DeprecationWarning",
174190
"ignore:.*load_str_bytes is deprecated*:DeprecationWarning",
175191
"ignore:.*The `dict` method is deprecated; use `model_dump` instead*:DeprecationWarning",
176-
"ignore:.*Pydantic V1 style `@validator` validators are deprecated*:DeprecationWarning"
192+
"ignore:.*Pydantic V1 style `@validator` validators are deprecated*:DeprecationWarning",
177193
]
178194

179195
[build-system]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import annotations
2+
3+
from typing import Tuple
4+
5+
from pytest_socket import disable_socket
6+
7+
8+
def pytest_runtest_setup():
9+
"""Disable Unix and TCP sockets for Data masking tests"""
10+
disable_socket()
11+
12+
13+
class FakeEncryptionClient:
14+
ENCRYPTION_HEADER = "test"
15+
16+
def encrypt(self, source: bytes | str, **kwargs) -> Tuple[bytes, str]:
17+
if isinstance(source, str):
18+
return source.encode(), self.ENCRYPTION_HEADER
19+
20+
return source, self.ENCRYPTION_HEADER
21+
22+
def decrypt(self, source: bytes, **kwargs) -> Tuple[bytes, str]:
23+
return source, "dummy_decryption_header"

tests/functional/data_masking/test_aws_encryption_sdk.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
from aws_lambda_powertools.utilities.data_masking.base import DataMasking
4-
from aws_lambda_powertools.utilities.data_masking.providers.aws_encryption_sdk import AwsEncryptionSdkProvider
5-
from tests.unit.data_masking.setup import *
6-
7-
AWS_SDK_KEY = "arn:aws:kms:us-west-2:683517028648:key/269301eb-81eb-4067-ac72-98e8e49bf2b3"
6+
from aws_lambda_powertools.utilities.data_masking.providers.aws_encryption_sdk import (
7+
AwsEncryptionSdkProvider,
8+
)
9+
from tests.functional.data_masking.conftest import FakeEncryptionClient
10+
from tests.unit.data_masking.setup import (
11+
aws_encrypted_with_fields,
12+
data_types,
13+
data_types_and_masks,
14+
dict_fields,
15+
dictionaries,
16+
fields_to_mask,
17+
json_blob,
18+
json_dict,
19+
masked_with_fields,
20+
python_dict,
21+
)
822

923

1024
@pytest.fixture
11-
def data_masker():
12-
return DataMasking(provider=AwsEncryptionSdkProvider(keys=[AWS_SDK_KEY]))
25+
def data_masker() -> DataMasking:
26+
"""DataMasking using AWS Encryption SDK Provider with a fake client"""
27+
fake_client = FakeEncryptionClient()
28+
provider = AwsEncryptionSdkProvider(keys=["dummy"], client=fake_client)
29+
return DataMasking(provider=provider)
1330

1431

1532
@pytest.mark.parametrize("value, value_masked", data_types_and_masks)
@@ -36,7 +53,7 @@ def test_mask_with_fields(data_masker):
3653

3754

3855
@pytest.mark.parametrize("value", data_types)
39-
def test_encrypt_decrypt(value, data_masker):
56+
def test_encrypt_decrypt(value, data_masker: DataMasking):
4057
# GIVEN an instantiation of DataMasking with the AWS encryption provider
4158

4259
# WHEN encrypting and then decrypting the encrypted data
@@ -62,7 +79,4 @@ def test_encrypt_decrypt_with_fields(value, fields, data_masker):
6279
print("json blob!!!!")
6380
assert decrypted_data == value
6481
else:
65-
print("json_blob_fields!!!!")
66-
assert decrypted_data == str(value)
67-
print("decrypted_data:", decrypted_data)
68-
print("aws_encrypted_with_fields:", aws_encrypted_with_fields)
82+
assert decrypted_data == aws_encrypted_with_fields

tests/performance/test_data_masking.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import pytest
55

66
from aws_lambda_powertools.utilities.data_masking.base import DataMasking
7-
from aws_lambda_powertools.utilities.data_masking.providers.itsdangerous import (
8-
ItsDangerousProvider,
9-
)
107

118
DATA_MASKING_PACKAGE = "aws_lambda_powertools.utilities.data_masking"
129
DATA_MASKING_INIT_SLA: float = 0.002
@@ -58,16 +55,15 @@ def test_data_masking_init(benchmark):
5855
pytest.fail(f"High level imports should be below {DATA_MASKING_INIT_SLA}s: {stat}")
5956

6057

61-
def encrypt_json_blob():
62-
data_masker = DataMasking(provider=ItsDangerousProvider("mykey"))
63-
encrypted = data_masker.encrypt(json_blob, json_blob_fields)
64-
data_masker.decrypt(encrypted, json_blob_fields)
58+
def mask_json_blob():
59+
data_masker = DataMasking()
60+
data_masker.mask(json_blob, json_blob_fields)
6561

6662

6763
@pytest.mark.perf
6864
@pytest.mark.benchmark(group="core", disable_gc=True, warmup=False)
6965
def test_data_masking_encrypt_with_json_blob(benchmark):
70-
benchmark.pedantic(encrypt_json_blob)
66+
benchmark.pedantic(mask_json_blob)
7167
stat = benchmark.stats.stats.max
7268
if stat > DATA_MASKING_NESTED_ENCRYPT_SLA:
7369
pytest.fail(f"High level imports should be below {DATA_MASKING_NESTED_ENCRYPT_SLA}s: {stat}")

0 commit comments

Comments
 (0)