Skip to content

Commit b6d2a94

Browse files
Adding docstring + arg parameter
1 parent 3fa18cc commit b6d2a94

File tree

1 file changed

+79
-1
lines changed
  • aws_lambda_powertools/utilities/data_masking

1 file changed

+79
-1
lines changed

aws_lambda_powertools/utilities/data_masking/base.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ def encrypt(
6969
provider_options: dict | None = None,
7070
**encryption_context: str,
7171
) -> str:
72+
"""
73+
Encrypt data using the configured encryption provider.
74+
75+
Parameters
76+
----------
77+
data : dict, Mapping, Sequence, or Number
78+
The data to encrypt.
79+
provider_options : dict, optional
80+
Provider-specific options for encryption.
81+
**encryption_context : str
82+
Additional key-value pairs for encryption context.
83+
84+
Returns
85+
-------
86+
str
87+
The encrypted data as a base64-encoded string.
88+
89+
Example
90+
--------
91+
92+
encryption_provider = AWSEncryptionSDKProvider(keys=[KMS_KEY_ARN])
93+
data_masker = DataMasking(provider=encryption_provider)
94+
encrypted = data_masker.encrypt({"secret": "value"})
95+
"""
7296
return self._apply_action(
7397
data=data,
7498
fields=None,
@@ -87,6 +111,31 @@ def decrypt(
87111
provider_options: dict | None = None,
88112
**encryption_context: str,
89113
) -> Any:
114+
"""
115+
Decrypt data using the configured encryption provider.
116+
117+
Parameters
118+
----------
119+
data : dict, Mapping, Sequence, or Number
120+
The data to encrypt.
121+
provider_options : dict, optional
122+
Provider-specific options for encryption.
123+
**encryption_context : str
124+
Additional key-value pairs for encryption context.
125+
126+
Returns
127+
-------
128+
str
129+
The encrypted data as a base64-encoded string.
130+
131+
Example
132+
--------
133+
134+
encryption_provider = AWSEncryptionSDKProvider(keys=[KMS_KEY_ARN])
135+
data_masker = DataMasking(provider=encryption_provider)
136+
encrypted = data_masker.decrypt(encrypted_data)
137+
"""
138+
90139
return self._apply_action(
91140
data=data,
92141
fields=None,
@@ -110,6 +159,31 @@ def erase(
110159
mask_format: str | None = None,
111160
masking_rules: dict | None = None,
112161
) -> Any:
162+
"""
163+
Erase or mask sensitive data in the input.
164+
165+
Parameters
166+
----------
167+
data : Any
168+
The data to be erased or masked.
169+
fields : list of str, optional
170+
List of field names to be erased or masked.
171+
dynamic_mask : bool, optional
172+
Whether to use dynamic masking.
173+
custom_mask : str, optional
174+
Custom mask to apply instead of the default.
175+
regex_pattern : str, optional
176+
Regular expression pattern for identifying data to mask.
177+
mask_format : str, optional
178+
Format string for the mask.
179+
masking_rules : dict, optional
180+
Dictionary of custom masking rules.
181+
182+
Returns
183+
-------
184+
Any
185+
The data with sensitive information erased or masked.
186+
"""
113187
if masking_rules:
114188
return self._apply_masking_rules(data=data, masking_rules=masking_rules)
115189
else:
@@ -313,7 +387,11 @@ def _apply_masking_rules(self, data: dict, masking_rules: dict) -> dict:
313387
match.full_path.update(result, masked_value)
314388

315389
except Exception as e:
316-
warnings.warn(f"Error masking value for path {path}: {str(e)}", category=PowertoolsUserWarning, stacklevel=2)
390+
warnings.warn(
391+
f"Error masking value for path {path}: {str(e)}",
392+
category=PowertoolsUserWarning,
393+
stacklevel=2,
394+
)
317395
continue
318396

319397
except Exception as e:

0 commit comments

Comments
 (0)