diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e56c9a..c8c017a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [0.10.1] - 2024-08-14 + +### Changed +- Fixed a bug that caused Summon to not properly handle a situation where a secret + to be fetched did not exist (CNJR-6093) + ## [0.10.0] - 2024-07-29 ### Added diff --git a/acceptance/features/fetching_secrets.feature b/acceptance/features/fetching_secrets.feature index 4b82a15..00e14ea 100644 --- a/acceptance/features/fetching_secrets.feature +++ b/acceptance/features/fetching_secrets.feature @@ -14,3 +14,14 @@ Feature: fetching secrets And a secret "very/secret/db-password" with "notSoSecret" When I successfully run `summon -p ./provider env` Then the output should contain "DB_PASSWORD=notSoSecret" + + Scenario: Fetching a database username and non existent password + Given a file named "secrets.yml" with: + """ + DB_USERNAME: !var very/secret/db-username + DB_PASSWORD: !var very/secret/db-password-non-existent + """ + And a secret "very/secret/db-username" with "secretUsername" + And a non-existent secret "very/secret/db-password-non-existent" + When I run `summon -p ./provider env` + Then the output should contain "Error fetching variable DB_PASSWORD" diff --git a/acceptance/features/step_definitions/secret_steps.rb b/acceptance/features/step_definitions/secret_steps.rb index c11e428..18b314a 100644 --- a/acceptance/features/step_definitions/secret_steps.rb +++ b/acceptance/features/step_definitions/secret_steps.rb @@ -35,3 +35,15 @@ """ } end + +Given(/^a non-existent secret "([^"]*)"$/) do |name| + steps %{ + Given I append to "provider" with: + """ + if [ "$1" == "#{name}" ]; then + echo "Error fetching variable #{name}" >&2 + exit 1 + fi + """ + } +end \ No newline at end of file diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 5bb7153..ec8984f 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -113,9 +113,20 @@ func CallInteractiveMode(provider string, secrets secretsyml.SecretsMap) (chan R ctxCancel() } } + stderrPipe, err := cmd.StderrPipe() + if err != nil { + errorsCh <- err + return resultsCh, errorsCh, func() { + stdinPipe.Close() + stdoutPipe.Close() + ctxCancel() + } + } + cleanup := func() { stdinPipe.Close() stdoutPipe.Close() + stderrPipe.Close() ctxCancel() } @@ -145,16 +156,10 @@ func CallInteractiveMode(provider string, secrets secretsyml.SecretsMap) (chan R go func() { defer close(resultsCh) scanner := bufio.NewScanner(stdoutPipe) - index := 0 for scanner.Scan() { - line := scanner.Text() - if err != nil { - errorsCh <- ErrInteractiveModeNotSupported - break - } decoded, err := base64.StdEncoding.DecodeString(line) @@ -179,6 +184,13 @@ func CallInteractiveMode(provider string, secrets secretsyml.SecretsMap) (chan R } }() + go func() { + scanner := bufio.NewScanner(stderrPipe) + for scanner.Scan() { + line := scanner.Text() + errorsCh <- fmt.Errorf(line) + } + }() return resultsCh, errorsCh, cleanup }