mirror of
https://github.com/Luzifer/yaml-vault.git
synced 2024-12-20 12:01:18 +00:00
Add state "absent" to delete keys
This commit is contained in:
parent
471deae427
commit
142c3abea4
1 changed files with 17 additions and 6 deletions
23
main.go
23
main.go
|
@ -38,6 +38,7 @@ type importFile struct {
|
|||
|
||||
type importField struct {
|
||||
Key string
|
||||
State string
|
||||
Values map[string]interface{}
|
||||
}
|
||||
|
||||
|
@ -204,14 +205,24 @@ func importToVault(client *api.Client) error {
|
|||
}
|
||||
|
||||
for _, field := range keys.Keys {
|
||||
if _, err := client.Logical().Write(field.Key, field.Values); err != nil {
|
||||
if cfg.IgnoreErrors {
|
||||
info("Error while writing data to key '%s': %s", field.Key, err)
|
||||
continue
|
||||
if field.State == "absent" {
|
||||
if _, err := client.Logical().Delete(field.Key); err != nil {
|
||||
if cfg.IgnoreErrors {
|
||||
info("Error while deleting key '%s': %s", field.Key, err)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
if _, err := client.Logical().Write(field.Key, field.Values); err != nil {
|
||||
if cfg.IgnoreErrors {
|
||||
info("Error while writing data to key '%s': %s", field.Key, err)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
debug("Successfully wrote data to key '%s'", field.Key)
|
||||
}
|
||||
debug("Successfully wrote data to key '%s'", field.Key)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue