Skip to content

Commit

Permalink
adds the --dry flag to the apply command
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas La Piana committed Aug 24, 2021
1 parent 468f4ff commit 5b86489
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
2 changes: 0 additions & 2 deletions fidesctl/data/sample/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ system:
dataQualifier: "identified_data"
dataSubjects:
- "customer"
datasetReferences:
- "sample_db_dataset.Email"
systemDependencies: []
8 changes: 7 additions & 1 deletion fidesctl/src/fidesctl/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ def show(ctx: click.Context, object_type: str) -> None:
########################
@click.command()
@click.pass_context
@click.option(
"--dry",
is_flag=True,
help="Runs the apply command without any side-effects.",
)
@click.argument("manifest_dir", type=click.Path())
def apply(ctx: click.Context, manifest_dir: str) -> None:
def apply(ctx: click.Context, dry: bool, manifest_dir: str) -> None:
"""
Send the manifest files to the server.
"""
Expand All @@ -119,6 +124,7 @@ def apply(ctx: click.Context, manifest_dir: str) -> None:
url=config.cli.server_url,
manifests_dir=manifest_dir,
headers=config.user.request_headers,
dry=dry,
)


Expand Down
37 changes: 24 additions & 13 deletions fidesctl/src/fidesctl/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def get_server_objects(
return server_object_list


def apply(url: str, manifests_dir: str, headers: Dict[str, str]) -> None:
def apply(
url: str, manifests_dir: str, headers: Dict[str, str], dry: bool = False
) -> None:
"""
Apply the current manifest file state to the server.
Excludes systems and registries.
Expand All @@ -118,7 +120,6 @@ def apply(url: str, manifests_dir: str, headers: Dict[str, str]) -> None:
for object_type, object_list in ingested_manifests.items()
}

# Loop through each type of object and check for operations
for object_type, manifest_object_list in parsed_manifests.items():

existing_keys = [
Expand All @@ -133,15 +134,25 @@ def apply(url: str, manifests_dir: str, headers: Dict[str, str]) -> None:
manifest_object_list,
server_object_list,
)
execute_create_update_unchanged(
url,
headers,
object_type,
create_list,
update_list,
unchanged_list,
)

echo_green(f"Created {len(create_list)} {object_type} objects.")
echo_green(f"Updated {len(update_list)} {object_type} objects.")
echo_green(f"Skipped {len(unchanged_list)} unchanged {object_type} objects.")
if dry:
echo_green(f"Would Create {len(create_list)} {object_type} objects.")
echo_green(f"Would Update {len(update_list)} {object_type} objects.")
echo_green(
f"Would Skip {len(unchanged_list)} unchanged {object_type} objects."
)
else:
execute_create_update_unchanged(
url,
headers,
object_type,
create_list,
update_list,
unchanged_list,
)

echo_green(f"Created {len(create_list)} {object_type} objects.")
echo_green(f"Updated {len(update_list)} {object_type} objects.")
echo_green(
f"Skipped {len(unchanged_list)} unchanged {object_type} objects."
)
23 changes: 19 additions & 4 deletions fidesctl/tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ def test_apply(test_config_path: str, test_cli_runner: CliRunner):
assert result.exit_code == 0


@pytest.mark.integration
def test_dry_apply(test_config_path: str, test_cli_runner: CliRunner):
result = test_cli_runner.invoke(
cli, ["-f", test_config_path, "apply", "data/sample/", "--dry"]
)
print(result.output)
assert result.exit_code == 0


@pytest.mark.integration
def test_find(test_config_path: str, test_cli_runner: CliRunner):
result = test_cli_runner.invoke(
cli, ["-f", test_config_path, "find", "system", "demoPassingSystem"]
cli, ["-f", test_config_path, "find", "system", "dataAnalyticsSystem"]
)
print(result.output)
assert result.exit_code == 0
Expand Down Expand Up @@ -77,7 +86,7 @@ def test_dry_evaluate_registry_success(
def test_dry_evaluate_system_success(test_config_path: str, test_cli_runner: CliRunner):
result = test_cli_runner.invoke(
cli,
["-f", test_config_path, "dry-evaluate", "data/sample/", "demoPassingSystem"],
["-f", test_config_path, "dry-evaluate", "data/sample/", "dataAnalyticsSystem"],
)
print(result.output)
assert result.exit_code == 0
Expand All @@ -87,7 +96,13 @@ def test_dry_evaluate_system_success(test_config_path: str, test_cli_runner: Cli
def test_dry_evaluate_system_failing(test_config_path: str, test_cli_runner: CliRunner):
result = test_cli_runner.invoke(
cli,
["-f", test_config_path, "dry-evaluate", "data/sample/", "demoFailingSystem"],
[
"-f",
test_config_path,
"dry-evaluate",
"data/sample/",
"customerDataSharingSystem",
],
)
print(result.output)
assert result.exit_code == 1
Expand Down Expand Up @@ -117,7 +132,7 @@ def test_evaluate_system_success(test_config_path: str, test_cli_runner: CliRunn
def test_evaluate_system_failing(test_config_path: str, test_cli_runner: CliRunner):
result = test_cli_runner.invoke(
cli,
["-f", test_config_path, "evaluate", "system", "demoFailingSystem"],
["-f", test_config_path, "evaluate", "system", "customerDataSharingSystem"],
)
print(result.output)
assert result.exit_code == 1

0 comments on commit 5b86489

Please sign in to comment.