Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1184 allow delete only saas endpoints #1420

Merged
merged 9 commits into from
Oct 13, 2022
34 changes: 7 additions & 27 deletions src/fides/api/ops/schemas/saas/saas_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,35 +303,15 @@ def get_graph(self) -> Dataset:
read_request = endpoint.requests.get("read")
delete_request = endpoint.requests.get("delete")
if read_request:
for param in read_request.param_values or []:
if param.references:
references = []
for reference in param.references:
first, *rest = reference.field.split(".")
references.append(
(
FieldAddress(reference.dataset, first, *rest),
reference.direction,
)
)
fields.append(
ScalarField(name=param.name, references=references)
)
if param.identity:
fields.append(
ScalarField(name=param.name, identity=param.identity)
)
self._process_param_values(fields, read_request.param_values)
elif delete_request:
# The preferred way to build the graph for a SaaS connector is to convert
# a read requests' param_values into identity and dataset references.
# If the endpoint only specifies a delete request without a read,
# then we must create a single placeholder field for the graph traversal
# to still visit this delete-only collection and call the delete request.
fields.append(
ScalarField(
name="placeholder", identity="email", primary_key="True"
)
)
# then we must use the delete request's param_values instead.
# One of the fields must automatically be flagged as a primary key
# in order for the deletion to execute. See fides#1199
self._process_param_values(fields, delete_request.param_values)
if fields:
fields[0].primary_key = True

if fields:
grouped_inputs: Optional[Set[str]] = set()
Expand Down
15 changes: 3 additions & 12 deletions tests/ops/models/test_saasconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import pytest
from pydantic import ValidationError

from fides.api.ops.graph.config import (
CollectionAddress,
FieldAddress,
FieldPath,
ScalarField,
)
from fides.api.ops.graph.config import CollectionAddress, FieldAddress
from fides.api.ops.schemas.dataset import FidesopsDatasetReference
from fides.api.ops.schemas.saas.saas_config import (
ConnectorParam,
Expand Down Expand Up @@ -139,15 +134,11 @@ def test_saas_config_to_dataset(saas_example_config: Dict[str, Dict]):
)
assert direction == "from"

# assert that delete-only endpoints generate a collection with
# a single primary key identity field as a placeholder
# assert that delete-only endpoints generate a collection with at least one primary key field
people_collection = next(
col for col in saas_dataset.collections if col.name == "people"
)
people_id_field = people_collection.field(FieldPath("placeholder"))
assert people_id_field == ScalarField(
name="placeholder", identity="email", primary_key="True"
)
assert any(field for field in people_collection.fields if field.primary_key)


@pytest.mark.unit_saas
Expand Down
2 changes: 1 addition & 1 deletion tests/ops/service/connectors/test_saas_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fides.api.ops.graph.traversal import TraversalNode
from fides.api.ops.models.policy import Policy
from fides.api.ops.models.privacy_request import PrivacyRequest
from fides.api.ops.schemas.saas.saas_config import SaaSRequest
from fides.api.ops.schemas.saas.saas_config import SaaSConfig, SaaSRequest
galvana marked this conversation as resolved.
Show resolved Hide resolved
from fides.api.ops.schemas.saas.shared_schemas import HTTPMethod
from fides.api.ops.service.connectors import get_connector
from fides.api.ops.service.connectors.saas_connector import SaaSConnector
Expand Down