X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sms-service%2Fsrc%2Fsms%2Fbackend%2Fvault.go;h=bfc3367e0bf6fc7666c2ebf97a9f984baad4b3e5;hb=2272f46277dfaebe05a9781ae2e629a1c0c49194;hp=7fc17474ba9a5ad4f5d623a5923111a728a48e55;hpb=e3d682c5f14994c2b85ff26ddf6ae3148b499de3;p=aaf%2Fsms.git diff --git a/sms-service/src/sms/backend/vault.go b/sms-service/src/sms/backend/vault.go index 7fc1747..bfc3367 100644 --- a/sms-service/src/sms/backend/vault.go +++ b/sms-service/src/sms/backend/vault.go @@ -105,7 +105,7 @@ func (v *Vault) GetSecret(dom string, name string) (Secret, error) { sec, err := v.vaultClient.Logical().Read(dom + "/" + name) if err != nil { - return Secret{}, errors.New("unable to read Secret at provided path") + return Secret{}, errors.New("Unable to read Secret at provided path") } // sec and err are nil in the case where a path does not exist @@ -116,6 +116,39 @@ func (v *Vault) GetSecret(dom string, name string) (Secret, error) { return Secret{Name: name, Values: sec.Data}, nil } +// ListSecret returns a list of secret names on a particular domain +// The values of the secret are not returned +func (v *Vault) ListSecret(dom string) ([]string, error) { + err := v.checkToken() + if err != nil { + return nil, errors.New("Token check returned error: " + err.Error()) + } + + dom = v.vaultMount + "/" + dom + + sec, err := v.vaultClient.Logical().List(dom) + if err != nil { + return nil, errors.New("Unable to read Secret at provided path") + } + + // sec and err are nil in the case where a path does not exist + if sec == nil { + return nil, errors.New("Secret not found at the provided path") + } + + val, ok := sec.Data["keys"].([]interface{}) + if !ok { + return nil, errors.New("Secret not found at the provided path") + } + + retval := make([]string, len(val)) + for i, v := range val { + retval[i] = fmt.Sprint(v) + } + + return retval, nil +} + // CreateSecretDomain mounts the kv backend on a path with the given name func (v *Vault) CreateSecretDomain(name string) (SecretDomain, error) { // Check if token is still valid