mirror of
https://github.com/Luzifer/git-credential-vault.git
synced 2024-11-09 23:00:13 +00:00
Handle missing credentials gracefully
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
854aa81304
commit
89eff35a3a
2 changed files with 14 additions and 2 deletions
12
main.go
12
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 {
|
||||
|
|
4
vault.go
4
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{}
|
||||
|
|
Loading…
Reference in a new issue