diff --git a/fidesctl/data/sample/system.yml b/fidesctl/data/sample/system.yml index 5c30532336..f7291c1a3f 100644 --- a/fidesctl/data/sample/system.yml +++ b/fidesctl/data/sample/system.yml @@ -29,6 +29,4 @@ system: dataQualifier: "identified_data" dataSubjects: - "customer" - datasetReferences: - - "sample_db_dataset.Email" systemDependencies: [] diff --git a/fidesctl/src/fidesctl/cli/cli.py b/fidesctl/src/fidesctl/cli/cli.py index 19bb0e2461..e0c6995d09 100644 --- a/fidesctl/src/fidesctl/cli/cli.py +++ b/fidesctl/src/fidesctl/cli/cli.py @@ -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. """ @@ -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, ) diff --git a/fidesctl/src/fidesctl/core/apply.py b/fidesctl/src/fidesctl/core/apply.py index c9720e7d9b..280bd2035f 100644 --- a/fidesctl/src/fidesctl/core/apply.py +++ b/fidesctl/src/fidesctl/core/apply.py @@ -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. @@ -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 = [ @@ -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." + ) diff --git a/fidesctl/tests/cli/test_cli.py b/fidesctl/tests/cli/test_cli.py index 9b4980fa88..c9cec01f7c 100644 --- a/fidesctl/tests/cli/test_cli.py +++ b/fidesctl/tests/cli/test_cli.py @@ -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 @@ -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 @@ -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 @@ -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