From 89eff35a3abc2ddd1e5324d3cebbe2c9a2725e23 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 1 Apr 2020 15:05:58 +0200 Subject: [PATCH] Handle missing credentials gracefully Signed-off-by: Knut Ahlers --- main.go | 12 +++++++++++- vault.go | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c7e39a1..e10227f 100644 --- a/main.go +++ b/main.go @@ -86,8 +86,18 @@ func handleGetAction() { } vaultValues, err := getCredentialSetFromVault(values["host"]) - if err != nil { + switch err { + + case nil: + // Fine + + case errNoData: + // Return empty, git will handle the rest + return + + default: log.WithError(err).Fatal("Unable to retrieve values from Vault") + } for k, v := range vaultValues { diff --git a/vault.go b/vault.go index 1c53676..1b18922 100644 --- a/vault.go +++ b/vault.go @@ -7,6 +7,8 @@ import ( "github.com/pkg/errors" ) +var errNoData = errors.New("Found no data") + func getCredentialSetFromVault(host string) (map[string]string, error) { client, err := api.NewClient(nil) if err != nil { @@ -19,7 +21,7 @@ func getCredentialSetFromVault(host string) (map[string]string, error) { } if secret == nil || secret.Data == nil { - return nil, errors.New("Found no data") + return nil, errNoData } var out = map[string]string{}