mirror of
https://github.com/Luzifer/yaml-vault.git
synced 2024-12-30 00:31:21 +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
11
main.go
11
main.go
|
@ -38,6 +38,7 @@ type importFile struct {
|
|||
|
||||
type importField struct {
|
||||
Key string
|
||||
State string
|
||||
Values map[string]interface{}
|
||||
}
|
||||
|
||||
|
@ -204,6 +205,15 @@ func importToVault(client *api.Client) error {
|
|||
}
|
||||
|
||||
for _, field := range keys.Keys {
|
||||
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
|
||||
}
|
||||
} 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)
|
||||
|
@ -213,6 +223,7 @@ func importToVault(client *api.Client) error {
|
|||
}
|
||||
debug("Successfully wrote data to key '%s'", field.Key)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue