Base
Base class for Data Masking
Usage Documentation
| CLASS | DESCRIPTION |
|---|---|
DataMasking |
The DataMasking class orchestrates erasing, encrypting, and decrypting |
| FUNCTION | DESCRIPTION |
|---|---|
prepare_data |
Recursively convert complex objects into dictionaries or simple types. |
DataMasking ¶
DataMasking(provider: BaseProvider | None = None, raise_on_missing_field: bool = True)
The DataMasking class orchestrates erasing, encrypting, and decrypting for the base provider.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
| METHOD | DESCRIPTION |
|---|---|
decrypt |
Decrypt data using the configured encryption provider. |
encrypt |
Encrypt data using the configured encryption provider. |
erase |
Erase or mask sensitive data in the input. |
Source code in aws_lambda_powertools/utilities/data_masking/base.py
131 132 133 134 135 136 137 138 139 140 | |
decrypt ¶
decrypt(data, provider_options: dict | None = None, **encryption_context: str) -> Any
Decrypt data using the configured encryption provider.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data to encrypt.
TYPE:
|
provider_options
|
Provider-specific options for encryption.
TYPE:
|
**encryption_context
|
Additional key-value pairs for encryption context.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted data as a base64-encoded string. |
Example
1 2 3 | |
Source code in aws_lambda_powertools/utilities/data_masking/base.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
encrypt ¶
encrypt(data: dict | Mapping | Sequence | Number, provider_options: dict | None = None, **encryption_context: str) -> str
Encrypt data using the configured encryption provider.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data to encrypt.
TYPE:
|
provider_options
|
Provider-specific options for encryption.
TYPE:
|
**encryption_context
|
Additional key-value pairs for encryption context.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted data as a base64-encoded string. |
Example
1 2 3 | |
Source code in aws_lambda_powertools/utilities/data_masking/base.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
erase ¶
erase(data: Any, fields: list[str] | None = None, *, dynamic_mask: bool | None = None, custom_mask: str | None = None, regex_pattern: str | None = None, mask_format: str | None = None, masking_rules: dict | None = None) -> Any
Erase or mask sensitive data in the input.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data to be erased or masked.
TYPE:
|
fields
|
List of field names to be erased or masked.
TYPE:
|
dynamic_mask
|
Whether to use dynamic masking.
TYPE:
|
custom_mask
|
Custom mask to apply instead of the default.
TYPE:
|
regex_pattern
|
Regular expression pattern for identifying data to mask.
TYPE:
|
mask_format
|
Format string for the mask.
TYPE:
|
masking_rules
|
Dictionary of custom masking rules.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The data with sensitive information erased or masked. |
Source code in aws_lambda_powertools/utilities/data_masking/base.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
prepare_data ¶
prepare_data(data: Any, _visited: set[int] | None = None) -> Any
Recursively convert complex objects into dictionaries or simple types.
Handles dataclasses, Pydantic models, objects with __dict__ or __slots__,
and prevents circular references. _visited holds only the ancestors of the current
recursion path, so the same object referenced twice in a structure is converted twice
instead of being mistaken for a cycle.
Source code in aws_lambda_powertools/utilities/data_masking/base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |