From 95542d29cb77231b9897a3ce68fdf7f0210a8f14 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 11 Jan 2022 14:39:18 -0700 Subject: [PATCH 1/4] returning stderr Signed-off-by: Richard Jones --- plan/task/inputsecretexec.go | 5 +++ tests/plan.bats | 17 ++++------ .../secrets/invalid_command_options.cue | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tests/plan/inputs/secrets/invalid_command_options.cue diff --git a/plan/task/inputsecretexec.go b/plan/task/inputsecretexec.go index 33fb8f63..7d3f6244 100644 --- a/plan/task/inputsecretexec.go +++ b/plan/task/inputsecretexec.go @@ -2,6 +2,7 @@ package task import ( "context" + "errors" "fmt" "os" "os/exec" @@ -49,6 +50,10 @@ func (c *inputSecretExecTask) Run(ctx context.Context, pctx *plancontext.Context // sec audited by @aluzzardi and @mrjones out, err := cmd.Output() if err != nil { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + return nil, errors.New(string(exitErr.Stderr)) + } return nil, err } diff --git a/tests/plan.bats b/tests/plan.bats index f6aaaec0..e81a2afc 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -65,21 +65,18 @@ setup() { assert_output --partial 'conflicting values "local directory" and "local dfsadf"' } -@test "plan/inputs/secrets exec" { +@test "plan/inputs/secrets" { cd "$TESTDIR" "$DAGGER" --europa up ./plan/inputs/secrets/exec.cue -} - -@test "plan/inputs/secrets exec relative" { - cd "$TESTDIR" - "$DAGGER" --europa up ./plan/inputs/secrets/exec.cue -} - -@test "plan/inputs/secrets invalid command" { - cd "$TESTDIR" + "$DAGGER" --europa up ./plan/inputs/secrets/exec_relative.cue + run "$DAGGER" --europa up ./plan/inputs/secrets/invalid_command.cue assert_failure assert_output --partial 'failed: exec: "rtyet": executable file not found' + + run "$DAGGER" --europa up ./plan/inputs/secrets/invalid_command_options.cue + assert_failure + assert_output --partial 'illegal option' } @test "plan/with" { diff --git a/tests/plan/inputs/secrets/invalid_command_options.cue b/tests/plan/inputs/secrets/invalid_command_options.cue new file mode 100644 index 00000000..ae8c21a1 --- /dev/null +++ b/tests/plan/inputs/secrets/invalid_command_options.cue @@ -0,0 +1,34 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + inputs: secrets: echo: command: { + name: "cat" + args: ["--sfgjkhf"] // // should fail because invalid option + } + + actions: { + + image: engine.#Pull & { + source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" + } + + verify: engine.#Exec & { + input: image.output + mounts: secret: { + dest: "/run/secrets/test" + contents: inputs.secrets.echo.contents + } + args: [ + "sh", "-c", + #""" + test "$(cat /run/secrets/test)" = "hello europa" + ls -l /run/secrets/test | grep -- "-r--------" + """#, + ] + } + } +} From 9180878cf1732b2e9040ed3a24e1d239408f5380 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 11 Jan 2022 15:28:43 -0700 Subject: [PATCH 2/4] fix test Signed-off-by: Richard Jones --- tests/plan.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plan.bats b/tests/plan.bats index e81a2afc..f7f962f3 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -76,7 +76,7 @@ setup() { run "$DAGGER" --europa up ./plan/inputs/secrets/invalid_command_options.cue assert_failure - assert_output --partial 'illegal option' + assert_output --partial 'option' } @test "plan/with" { From af2c4793de1ba19ab5cf3f3888ae43466a0c0ae3 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 11 Jan 2022 15:58:46 -0700 Subject: [PATCH 3/4] logging stderr returning err Signed-off-by: Richard Jones --- plan/task/inputsecretexec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plan/task/inputsecretexec.go b/plan/task/inputsecretexec.go index 7d3f6244..a8022588 100644 --- a/plan/task/inputsecretexec.go +++ b/plan/task/inputsecretexec.go @@ -52,7 +52,7 @@ func (c *inputSecretExecTask) Run(ctx context.Context, pctx *plancontext.Context if err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { - return nil, errors.New(string(exitErr.Stderr)) + lg.Err(err).Msg(string(exitErr.Stderr)) } return nil, err } From ff40451ad70bcf06e89e7cd0d0f918f88555e021 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 12 Jan 2022 10:42:06 -0700 Subject: [PATCH 4/4] update to dagger.io/dagger Signed-off-by: Richard Jones --- tests/plan/inputs/secrets/invalid_command_options.cue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plan/inputs/secrets/invalid_command_options.cue b/tests/plan/inputs/secrets/invalid_command_options.cue index ae8c21a1..1ada80df 100644 --- a/tests/plan/inputs/secrets/invalid_command_options.cue +++ b/tests/plan/inputs/secrets/invalid_command_options.cue @@ -1,7 +1,7 @@ package main import ( - "alpha.dagger.io/europa/dagger/engine" + "dagger.io/dagger/engine" ) engine.#Plan & {