Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Update the "instantiate_connection_from_template" to return a portion…
Browse files Browse the repository at this point in the history
… of both the connection config and the dataset. (#1105)
  • Loading branch information
pattisdr authored Aug 17, 2022
1 parent 80c8266 commit f7011e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/fidesops/ops/api/v1/endpoints/saas_config_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
from fidesops.ops.models.connectionconfig import ConnectionConfig, ConnectionType
from fidesops.ops.models.datasetconfig import DatasetConfig
from fidesops.ops.schemas.connection_configuration.connection_config import (
SaasConnectionTemplateResponse,
SaasConnectionTemplateValues,
)
from fidesops.ops.schemas.dataset import FidesopsDataset
from fidesops.ops.schemas.saas.saas_config import (
SaaSConfig,
SaaSConfigValidationDetails,
Expand Down Expand Up @@ -268,13 +268,13 @@ def authorize_connection(
@router.post(
SAAS_CONNECTOR_FROM_TEMPLATE,
dependencies=[Security(verify_oauth_client, scopes=[SAAS_CONNECTION_INSTANTIATE])],
response_model=FidesopsDataset,
response_model=SaasConnectionTemplateResponse,
)
def instantiate_connection_from_template(
saas_connector_type: str,
template_values: SaasConnectionTemplateValues,
db: Session = Depends(deps.get_db),
) -> FidesopsDataset:
) -> SaasConnectionTemplateResponse:
"""
Creates a SaaS Connector and a SaaS Dataset from a template.
Expand Down Expand Up @@ -331,4 +331,6 @@ def instantiate_connection_from_template(
logger.info(
f"SaaS Connector and Dataset {template_values.instance_key} successfully created from '{saas_connector_type}' template."
)
return dataset_config.dataset
return SaasConnectionTemplateResponse(
connection=connection_config, dataset=dataset_config.dataset
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fidesops.ops.models.connectionconfig import AccessLevel, ConnectionType
from fidesops.ops.schemas.api import BulkResponse, BulkUpdateFailed
from fidesops.ops.schemas.connection_configuration import connection_secrets_schemas
from fidesops.ops.schemas.dataset import FidesopsDataset
from fidesops.ops.schemas.saas.saas_config import SaaSConfigBase, SaaSType
from fidesops.ops.schemas.shared_schemas import FidesOpsKey

Expand Down Expand Up @@ -109,3 +110,8 @@ class SaasConnectionTemplateValues(BaseModel):
description: Optional[str] # For ConnectionConfig
secrets: connection_secrets_schemas # For ConnectionConfig
instance_key: FidesOpsKey # For DatasetConfig.fides_key


class SaasConnectionTemplateResponse(BaseModel):
connection: ConnectionConfigurationResponse
dataset: FidesopsDataset
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,14 @@ def test_instantiate_connection_from_template(
)

assert resp.status_code == 200
assert resp.json()["fides_key"] == "secondary_mailchimp_instance"
assert set(resp.json().keys()) == {"connection", "dataset"}
connection_data = resp.json()["connection"]
assert connection_data["key"] == "mailchimp_connection_config"
assert connection_data["name"] == "Mailchimp Connector"
assert "secrets" not in connection_data

dataset_data = resp.json()["dataset"]
assert dataset_data["fides_key"] == "secondary_mailchimp_instance"

connection_config = ConnectionConfig.filter(
db=db, conditions=(ConnectionConfig.key == "mailchimp_connection_config")
Expand Down

0 comments on commit f7011e1

Please sign in to comment.