1
0
Fork 0
mirror of https://github.com/Luzifer/git-credential-vault.git synced 2024-12-23 03:01:17 +00:00

Handle missing credentials gracefully

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-04-01 15:05:58 +02:00
parent 854aa81304
commit 89eff35a3a
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 14 additions and 2 deletions

12
main.go
View file

@ -86,8 +86,18 @@ func handleGetAction() {
} }
vaultValues, err := getCredentialSetFromVault(values["host"]) 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") log.WithError(err).Fatal("Unable to retrieve values from Vault")
} }
for k, v := range vaultValues { for k, v := range vaultValues {

View file

@ -7,6 +7,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var errNoData = errors.New("Found no data")
func getCredentialSetFromVault(host string) (map[string]string, error) { func getCredentialSetFromVault(host string) (map[string]string, error) {
client, err := api.NewClient(nil) client, err := api.NewClient(nil)
if err != nil { if err != nil {
@ -19,7 +21,7 @@ func getCredentialSetFromVault(host string) (map[string]string, error) {
} }
if secret == nil || secret.Data == nil { if secret == nil || secret.Data == nil {
return nil, errors.New("Found no data") return nil, errNoData
} }
var out = map[string]string{} var out = map[string]string{}