forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.py
26 lines (20 loc) · 868 Bytes
/
provider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from abc import abstractmethod
from collections.abc import Iterable
from aws_lambda_powertools.shared.constants import DATA_MASKING_STRING
class Provider:
"""
When you try to create an instance of a subclass that does not implement the encrypt method,
you will get a NotImplementedError with a message that says the method is not implemented:
"""
@abstractmethod
def encrypt(self, data):
raise NotImplementedError("Subclasses must implement encrypt()")
@abstractmethod
def decrypt(self, data):
raise NotImplementedError("Subclasses must implement decrypt()")
def mask(self, data):
if isinstance(data, (str, dict, bytes)):
return DATA_MASKING_STRING
elif isinstance(data, Iterable):
return type(data)([DATA_MASKING_STRING] * len(data))
return DATA_MASKING_STRING