1
0
Fork 0
mirror of https://github.com/Luzifer/yaml-vault.git synced 2024-12-20 20:11:16 +00:00

fix read tries when path has no current children

This commit is contained in:
Knut Ahlers 2016-07-11 18:37:50 +02:00
parent 0563f3b2d9
commit fe4d5ddc86
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

35
main.go
View file

@ -139,34 +139,35 @@ func exportFromVault(client *api.Client) error {
} }
func readRecurse(client *api.Client, path string, out *importFile) error { func readRecurse(client *api.Client, path string, out *importFile) error {
if strings.HasSuffix(path, "/") { if !strings.HasSuffix(path, "/") {
secret, err := client.Logical().List(path) secret, err := client.Logical().Read(path)
if err != nil { if err != nil {
return fmt.Errorf("Error reading %s: %s", path, err) return err
} }
if secret != nil && secret.Data["keys"] != nil { if secret == nil {
for _, k := range secret.Data["keys"].([]interface{}) { return fmt.Errorf("Unable to read %s: %#v", path, secret)
if err := readRecurse(client, path+k.(string), out); err != nil {
return err
}
}
return nil
} }
out.Keys[path] = secret.Data
debug("Successfully read data from key '%s'", path)
return nil
} }
secret, err := client.Logical().Read(path) secret, err := client.Logical().List(path)
if err != nil { if err != nil {
return err return fmt.Errorf("Error reading %s: %s", path, err)
} }
if secret == nil { if secret != nil && secret.Data["keys"] != nil {
return fmt.Errorf("Unable to read %s: %#v", path, secret) for _, k := range secret.Data["keys"].([]interface{}) {
if err := readRecurse(client, path+k.(string), out); err != nil {
return err
}
}
return nil
} }
out.Keys[path] = secret.Data
debug("Successfully read data from key '%s'", path)
return nil return nil
} }