Island: Remove disused dict_encryptor

This commit is contained in:
Mike Salvatore 2022-07-14 07:56:42 -04:00
parent 80f2dfd590
commit 86ce7f2cf9
2 changed files with 0 additions and 54 deletions

View File

@ -14,11 +14,5 @@ from .data_store_encryptor import (
unlock_datastore_encryptor,
reset_datastore_encryptor,
)
from .dict_encryptor import (
SensitiveField,
encrypt_dict,
decrypt_dict,
FieldNotFoundError,
)
from .field_encryptors.i_field_encryptor import IFieldEncryptor
from .field_encryptors.string_encryptor import StringEncryptor

View File

@ -1,48 +0,0 @@
from dataclasses import dataclass
from typing import Callable, List, Type
import dpath.util
from .field_encryptors import IFieldEncryptor
class FieldNotFoundError(Exception):
pass
@dataclass
class SensitiveField:
path: str
path_separator = "."
field_encryptor: Type[IFieldEncryptor]
def encrypt_dict(sensitive_fields: List[SensitiveField], document_dict: dict) -> dict:
for sensitive_field in sensitive_fields:
_apply_operation_to_document_field(
document_dict, sensitive_field, sensitive_field.field_encryptor.encrypt
)
return document_dict
def decrypt_dict(sensitive_fields: List[SensitiveField], document_dict: dict) -> dict:
for sensitive_field in sensitive_fields:
_apply_operation_to_document_field(
document_dict, sensitive_field, sensitive_field.field_encryptor.decrypt
)
return document_dict
def _apply_operation_to_document_field(
report: dict, sensitive_field: SensitiveField, operation: Callable
):
field_value = dpath.util.get(report, sensitive_field.path, sensitive_field.path_separator, None)
if field_value is None:
raise FieldNotFoundError(
f"Can't encrypt object because the path {sensitive_field.path} doesn't exist."
)
modified_value = operation(field_value)
dpath.util.set(report, sensitive_field.path, modified_value, sensitive_field.path_separator)