forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated examples into more tabs, fixed comments
- Loading branch information
Showing
10 changed files
with
111 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": 1, | ||
"name": "John Doe", | ||
"age": 30, | ||
"email": "[email protected]", | ||
"address": { | ||
"street": "123 Main St", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345" | ||
}, | ||
"company_address": { | ||
"street": "456 ACME Ave", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": 1, | ||
"name": "John Doe", | ||
"age": 30, | ||
"email": "InRoaXMgaXMgYSBzdHJpbmciHsLZGx2na-XzP_TB5Bf2LNU1bLc", | ||
"address": { | ||
"street": "XMgYSB_KDddaDJYMb-JpbmGnagTklwQ-msdaDLP", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345" | ||
}, | ||
"company_address": "B_KDddaDJYMb-93daSFGmnrtepytrejPNVXX98" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,89 +18,17 @@ def lambda_handler(event, context): | |
"state": "CA", | ||
"zip": "12345", | ||
}, | ||
"company_address": { | ||
"street": "456 ACME Ave", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345", | ||
}, | ||
} | ||
|
||
encryption_provider = AwsEncryptionSdkProvider(keys=[KMS_KEY_ARN]) | ||
data_masker = DataMasking(provider=encryption_provider) | ||
|
||
encrypted = data_masker.encrypt(data=data, fields=["email", "address.street"]) | ||
# encrypted = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "InRoaXMgaXMgYSBzdHJpbmciHsLZGx2na-XzP_TB5Bf2LNU1bLc", | ||
# "address": { | ||
# "street": "XMgYSB_KDddaDJYMb-JpbmGnagTklwQ-msdaDLP", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
|
||
decrypted = data_masker.decrypt(data=encrypted, fields=["email", "address.street"]) | ||
# decrypted = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "[email protected]", | ||
# "address": { | ||
# "street": "123 Main St", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
|
||
encrypted = data_masker.encrypt(data=data, fields=["email", "address"]) | ||
# encrypted = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "InRoaXMgaXMgYSBzdHJpbmciHsLZGx2na-XzP_TB5Bf2LNU1bLc", | ||
# "address": "XMgYSB_KDddaDJYMb-JpbmGnagTklwQ-msdaDLP" | ||
# } | ||
|
||
decrypted = data_masker.decrypt(data=encrypted, fields=["email", "address"]) | ||
# decrypted = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "[email protected]", | ||
# "address": { | ||
# "street": "123 Main St", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
|
||
encrypted = data_masker.encrypt(data=data) | ||
# encrypted = "InRoaXMgaXMgYSBzdHJpbmciHsLZGx2na-XzP_TB5Bf2LNU1bLc" | ||
|
||
decrypted = data_masker.decrypt(data=encrypted) | ||
# decrypted = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "[email protected]", | ||
# "address": { | ||
# "street": "123 Main St", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
encrypted = data_masker.encrypt(data=data, fields=["email", "address.street", "company_address"]) | ||
|
||
masked = data_masker.mask(data=data, fields=["email", "address.street"]) | ||
# masked = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "*****", | ||
# "address": { | ||
# "street": "*****", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
data_masker.decrypt(data=encrypted, fields=["email", "address.street", "company_address"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from aws_lambda_powertools.utilities.data_masking import DataMasking | ||
|
||
|
||
def lambda_handler(event, context: LambdaContext): | ||
def lambda_handler(event, context): | ||
|
||
data_masker = DataMasking() | ||
|
||
|
@@ -16,30 +16,12 @@ def lambda_handler(event, context: LambdaContext): | |
"state": "CA", | ||
"zip": "12345", | ||
}, | ||
"company_address": { | ||
"street": "456 ACME Ave", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345", | ||
}, | ||
} | ||
|
||
masked = data_masker.mask(data=data, fields=["email", "address.street"]) | ||
# masked = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "*****", | ||
# "address": { | ||
# "street": "*****", | ||
# "city": "Anytown", | ||
# "state": "CA", | ||
# "zip": "12345" | ||
# }, | ||
# } | ||
|
||
masked = data_masker.mask(data=data, fields=["address"]) | ||
# masked = { | ||
# "id": 1, | ||
# "name": "John Doe", | ||
# "age": 30, | ||
# "email": "[email protected]", | ||
# "address": "*****" | ||
# } | ||
|
||
masked = data_masker.mask(data=data) | ||
# masked = "*****" | ||
data_masker.mask(data=data, fields=["email", "address.street", "company_address"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": 1, | ||
"name": "John Doe", | ||
"age": 30, | ||
"email": "*****", | ||
"address": { | ||
"street": "*****", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345" | ||
}, | ||
"company_address": "*****" | ||
} |
Oops, something went wrong.