This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracts privacy request endpoint logic into separate service for DRP (…
…#470) * extracts privacy request endpoint logic into separate service for DRP * lint * unused import * enum formatting * return types * more lint * import DrpAction enum instead of using str * remove db call abstraction * remove import
- Loading branch information
1 parent
23dbb25
commit 04fb26d
Showing
5 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from enum import Enum | ||
from typing import Optional, List | ||
|
||
from fidesops.models.policy import DrpAction | ||
from fidesops.schemas.base_class import BaseSchema | ||
|
||
|
||
class DrpMeta(BaseSchema): | ||
"""Enum to hold Drp metadata. Only version is supported at this time""" | ||
|
||
version: str | ||
|
||
|
||
class DrpRegime(Enum): | ||
"""Enum to hold Drp Regime. Only ccpa supported at this time""" | ||
|
||
ccpa = "ccpa" | ||
|
||
|
||
class DrpPrivacyRequestCreate(BaseSchema): | ||
"""Data required to create a DRP PrivacyRequest""" | ||
|
||
meta: DrpMeta | ||
regime: Optional[DrpRegime] | ||
exercise: DrpAction | ||
relationships: Optional[List[str]] | ||
identity: str | ||
status_callback: Optional[str] | ||
|
||
class Config: | ||
"""Populate models with the raw value of enum fields, rather than the enum itself""" | ||
|
||
use_enum_values = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import logging | ||
from datetime import datetime | ||
from typing import Optional, Any, Dict, Set, List | ||
|
||
from fidesops.models.policy import Policy, ActionType | ||
from fidesops.models.privacy_request import PrivacyRequest | ||
from fidesops.schemas.drp_privacy_request import DrpPrivacyRequestCreate | ||
from fidesops.schemas.masking.masking_configuration import MaskingConfiguration | ||
from fidesops.schemas.masking.masking_secrets import MaskingSecretCache | ||
from fidesops.schemas.policy import Rule | ||
from fidesops.schemas.redis_cache import PrivacyRequestIdentity | ||
from fidesops.service.masking.strategy.masking_strategy_factory import get_strategy | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def build_required_privacy_request_kwargs( | ||
requested_at: Optional[datetime], policy_id: str | ||
) -> Dict[str, Any]: | ||
"""Build kwargs required for creating privacy request""" | ||
return { | ||
"requested_at": requested_at, | ||
"policy_id": policy_id, | ||
"status": "pending", | ||
} | ||
|
||
|
||
def cache_data( | ||
privacy_request: PrivacyRequest, | ||
policy: Policy, | ||
identity: PrivacyRequestIdentity, | ||
encryption_key: Optional[str], | ||
drp_request_body: Optional[DrpPrivacyRequestCreate], | ||
) -> None: | ||
"""Cache privacy request data""" | ||
# Store identity and encryption key in the cache | ||
logger.info(f"Caching identity for privacy request {privacy_request.id}") | ||
privacy_request.cache_identity(identity) | ||
privacy_request.cache_encryption(encryption_key) # handles None already | ||
|
||
# Store masking secrets in the cache | ||
logger.info(f"Caching masking secrets for privacy request {privacy_request.id}") | ||
erasure_rules: List[Rule] = policy.get_rules_for_action( | ||
action_type=ActionType.erasure | ||
) | ||
unique_masking_strategies_by_name: Set[str] = set() | ||
for rule in erasure_rules: | ||
strategy_name: str = rule.masking_strategy["strategy"] | ||
configuration: MaskingConfiguration = rule.masking_strategy["configuration"] | ||
if strategy_name in unique_masking_strategies_by_name: | ||
continue | ||
unique_masking_strategies_by_name.add(strategy_name) | ||
masking_strategy = get_strategy(strategy_name, configuration) | ||
if masking_strategy.secrets_required(): | ||
masking_secrets: List[ | ||
MaskingSecretCache | ||
] = masking_strategy.generate_secrets_for_cache() | ||
for masking_secret in masking_secrets: | ||
privacy_request.cache_masking_secret(masking_secret) | ||
if drp_request_body: | ||
privacy_request.cache_drp_request_body(drp_request_body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters