From 219ac3baeafb7019423f1c9b78025c211a591b71 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 19 Nov 2024 09:32:25 -0300 Subject: [PATCH 1/4] Base request override --- .../segment_request_overrides.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py diff --git a/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py new file mode 100644 index 0000000000..25a350e400 --- /dev/null +++ b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py @@ -0,0 +1,61 @@ + + +import hashlib +import json +from typing import Any, Dict, List + +from loguru import logger +from fides.api.models.policy import Policy +from fides.api.models.privacy_request import PrivacyRequest +from fides.api.schemas.saas.shared_schemas import HTTPMethod, SaaSRequestParams +from fides.api.service.connectors.saas.authenticated_client import AuthenticatedClient +from fides.api.service.saas_request.saas_request_override_factory import ( + register, + SaaSRequestType +) + + +@register("segment_delete_md5", [SaaSRequestType.DELETE]) +def segment_delete_md5( + client: AuthenticatedClient, + param_values_per_row: List[Dict[str, Any]], + policy: Policy, + privacy_request: PrivacyRequest, + secrets: Dict[str, Any], +) -> int: + rows_deleted = 0 + + headers = { + "Content-Type": "application/json", + } + + for row_param_values in param_values_per_row: + email = row_param_values["email"] + hashed_email = hashlib.md5(email.encode('utf-8')).hexdigest() + logger.debug(f"Deleting PII for email {email} with hashed email {hashed_email}") + + payload = json.dumps( + { + "regulation_type": "Suppress_With_Delete", + "attributes": { + "name": "userId", + "values": [hashed_email] + } + }) + + logger.debug(f"Payload: {payload}") + + + workspace_name = row_param_values["workspace_name"] + + client.send( + SaaSRequestParams( + method=HTTPMethod.POST, + path=f"/v1beta/workspaces/{workspace_name}/regulations", + headers=headers, + body=payload, + ) + ) + rows_deleted += 1 + + return rows_deleted From 00ce97aa6bd4809e3d6f611947042f0b8b06bad1 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 19 Nov 2024 09:33:05 -0300 Subject: [PATCH 2/4] Removing debug logs --- .../override_implementations/segment_request_overrides.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py index 25a350e400..7d28209462 100644 --- a/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py +++ b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py @@ -1,5 +1,3 @@ - - import hashlib import json from typing import Any, Dict, List @@ -32,7 +30,6 @@ def segment_delete_md5( for row_param_values in param_values_per_row: email = row_param_values["email"] hashed_email = hashlib.md5(email.encode('utf-8')).hexdigest() - logger.debug(f"Deleting PII for email {email} with hashed email {hashed_email}") payload = json.dumps( { @@ -43,9 +40,6 @@ def segment_delete_md5( } }) - logger.debug(f"Payload: {payload}") - - workspace_name = row_param_values["workspace_name"] client.send( From a84bbbc78159c1f7e749f415df4c8aec63a6ec20 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 19 Nov 2024 09:40:13 -0300 Subject: [PATCH 3/4] running static checks --- .../segment_request_overrides.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py index 7d28209462..6cc42a8916 100644 --- a/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py +++ b/src/fides/api/service/saas_request/override_implementations/segment_request_overrides.py @@ -2,14 +2,13 @@ import json from typing import Any, Dict, List -from loguru import logger from fides.api.models.policy import Policy from fides.api.models.privacy_request import PrivacyRequest from fides.api.schemas.saas.shared_schemas import HTTPMethod, SaaSRequestParams from fides.api.service.connectors.saas.authenticated_client import AuthenticatedClient from fides.api.service.saas_request.saas_request_override_factory import ( + SaaSRequestType, register, - SaaSRequestType ) @@ -29,16 +28,14 @@ def segment_delete_md5( for row_param_values in param_values_per_row: email = row_param_values["email"] - hashed_email = hashlib.md5(email.encode('utf-8')).hexdigest() + hashed_email = hashlib.md5(email.encode("utf-8")).hexdigest() - payload = json.dumps( + payload = json.dumps( { - "regulation_type": "Suppress_With_Delete", - "attributes": { - "name": "userId", - "values": [hashed_email] - } - }) + "regulation_type": "Suppress_With_Delete", + "attributes": {"name": "userId", "values": [hashed_email]}, + } + ) workspace_name = row_param_values["workspace_name"] From c42dbc7e2929fe38afe58215e0c658dbac8c5dea Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 19 Nov 2024 10:09:24 -0300 Subject: [PATCH 4/4] Adding Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64652fff67..c29a08ab05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The types of changes are: ### Added - Added namespace support for Snowflake [#5486](https://github.com/ethyca/fides/pull/5486) - Added support for field-level masking overrides [#5446](https://github.com/ethyca/fides/pull/5446) +- Added MD5 Hashing Request Override for segment Right to forget endpoint [#5514](https://github.com/ethyca/fides/pull/5514) ### Developer Experience - Migrated several instances of Chakra's Select component to use Ant's Select component [#5475](https://github.com/ethyca/fides/pull/5475)