Skip to content

Commit

Permalink
SaaS Connector Template Creation Fix: Integer fides_key (ethyca#1166)
Browse files Browse the repository at this point in the history
* Use quotes when replacing <"instance_fides_key"> in the saas config and dataset config files to force a string.

* Update CHANGELOG.
  • Loading branch information
pattisdr authored Aug 26, 2022
1 parent c9213c4 commit 28b6317
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ The types of changes are:
### Added
* Adds users and owners configuration for Hubspot connector [#1091](https://github.com/ethyca/fidesops/pull/1091)

### Fixed
* Accounts for integer "instance_fides_keys" when creating a saas connector from a template [#1166](https://github.com/ethyca/fidesops/pull/1166)


## [1.7.1](https://github.com/ethyca/fidesops/compare/1.7.0...1.7.1)

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/fidesops/ops/util/saas_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_config_with_replacement(
) -> Dict:
"""Loads the saas config from the yaml file and replaces any string with the given value"""
yaml_str: str = load_yaml_as_string(filename).replace(
string_to_replace, replacement
string_to_replace, f'"{replacement}"'
)
return yaml.safe_load(yaml_str).get("saas_config", [])

Expand All @@ -55,7 +55,7 @@ def load_dataset_with_replacement(
) -> Dict:
"""Loads the dataset from the yaml file and replaces any string with the given value"""
yaml_str: str = load_yaml_as_string(filename).replace(
string_to_replace, replacement
string_to_replace, f'"{replacement}"'
)
return yaml.safe_load(yaml_str).get("dataset", [])

Expand Down
43 changes: 43 additions & 0 deletions tests/ops/api/v1/endpoints/test_connection_template_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,43 @@ def test_dataset_config_saving_fails(
).first()
assert dataset_config is None

def test_instantiate_connection_from_template_integer_key(
self, db, generate_auth_header, api_client, base_url
):
auth_header = generate_auth_header(scopes=[SAAS_CONNECTION_INSTANTIATE])
request_body = {
"instance_key": "111",
"secrets": {
"domain": "test_mailchimp_domain",
"username": "test_mailchimp_username",
"api_key": "test_mailchimp_api_key",
},
"name": "Mailchimp Connector",
"description": "Mailchimp ConnectionConfig description",
"key": "mailchimp_connection_config",
}
resp = api_client.post(
base_url.format(saas_connector_type="mailchimp"),
headers=auth_header,
json=request_body,
)

connection_config = ConnectionConfig.filter(
db=db, conditions=(ConnectionConfig.key == "mailchimp_connection_config")
).first()
dataset_config = DatasetConfig.filter(
db=db,
conditions=(DatasetConfig.fides_key == "111"),
).first()

saas_config_fides_key = connection_config.saas_config["fides_key"]
dataset_fides_key = dataset_config.fides_key
embedded_dataset_fides_key = dataset_config.dataset["fides_key"]

assert saas_config_fides_key == dataset_fides_key == embedded_dataset_fides_key
dataset_config.delete(db)
connection_config.delete(db)

def test_instantiate_connection_from_template(
self, db, generate_auth_header, api_client, base_url
):
Expand Down Expand Up @@ -569,5 +606,11 @@ def test_instantiate_connection_from_template(
assert dataset_config.connection_config_id == connection_config.id
assert dataset_config.dataset is not None

saas_config_fides_key = connection_config.saas_config["fides_key"]
dataset_fides_key = dataset_config.fides_key
embedded_dataset_fides_key = dataset_config.dataset["fides_key"]

assert saas_config_fides_key == dataset_fides_key == embedded_dataset_fides_key

dataset_config.delete(db)
connection_config.delete(db)

0 comments on commit 28b6317

Please sign in to comment.