From 593e5f90888fcd48bed2477f1f22407187e1845b Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Tue, 24 Sep 2024 18:50:28 +0100 Subject: [PATCH] Reinstates missing PR (#1241) Fixes # ## Proposed Changes * Reinstates https://github.com/kapicorp/kapitan/pull/1189 ## Docs and Tests * [x] Tests added * [x] Updated documentation --- kapitan/cli.py | 2 +- tests/test_compile.py | 8 ++++++++ .../inventory/targets/reveal-output.yml | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/test_resources/inventory/targets/reveal-output.yml diff --git a/kapitan/cli.py b/kapitan/cli.py index db6bc477a..951af3199 100644 --- a/kapitan/cli.py +++ b/kapitan/cli.py @@ -261,7 +261,7 @@ def build_parser(): compile_parser.add_argument( "--reveal", help="reveal refs (warning: this will potentially write sensitive data)", - action="store_true", + action=argparse.BooleanOptionalAction, default=from_dot_kapitan("compile", "reveal", False), ) compile_parser.add_argument( diff --git a/tests/test_compile.py b/tests/test_compile.py index 61a0abc62..02d99b302 100644 --- a/tests/test_compile.py +++ b/tests/test_compile.py @@ -39,6 +39,14 @@ def setUp(self): reset_cache() os.chdir(TEST_RESOURCES_PATH) + def test_compile_no_reveal(self): + # check if the --no-reveal flag takes precedence over --reveal when passed together + sys.argv = ["kapitan", "compile", "-t", "reveal-output", "--reveal", "--no-reveal"] + main() + + with open("compiled/reveal-output/main.json") as f: + self.assertTrue("?{gpg:" in f.read()) + def test_single_target_compile(self): sys.argv = ["kapitan", "compile", "-t", "test-objects"] main() diff --git a/tests/test_resources/inventory/targets/reveal-output.yml b/tests/test_resources/inventory/targets/reveal-output.yml new file mode 100644 index 000000000..17d2dfeb2 --- /dev/null +++ b/tests/test_resources/inventory/targets/reveal-output.yml @@ -0,0 +1,12 @@ +parameters: + input: $?{gpg:targets/nginx-ingress/electionID||randomstr|base64} + kapitan: + vars: + target: reveal-output + compile: + - name: generate-toml-jsonnet + input_type: jsonnet + output_path: . + output_type: json + input_paths: + - components/input-to-output/main.jsonnet \ No newline at end of file