mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
Use mapstructure for decoding vault data
This commit is contained in:
parent
aa97366020
commit
f40fb577fe
@ -3,7 +3,6 @@ package ca
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -82,28 +81,25 @@ func (v *VaultProvider) Configure(cfg ProviderConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var renewable bool
|
||||
if v, ok := secret.Data["renewable"]; ok {
|
||||
renewable, _ = v.(bool)
|
||||
var token struct {
|
||||
Renewable bool
|
||||
TTL int
|
||||
}
|
||||
var increment int64
|
||||
if v, ok := secret.Data["ttl"]; ok {
|
||||
if n, ok := v.(json.Number); ok {
|
||||
increment, _ = n.Int64()
|
||||
}
|
||||
if err := mapstructure.Decode(secret.Data, &token); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set up a renewer to renew the token automatically, if supported.
|
||||
if renewable {
|
||||
if token.Renewable {
|
||||
renewer, err := client.NewRenewer(&vaultapi.RenewerInput{
|
||||
Secret: &vaultapi.Secret{
|
||||
Auth: &vaultapi.SecretAuth{
|
||||
ClientToken: config.Token,
|
||||
Renewable: renewable,
|
||||
Renewable: token.Renewable,
|
||||
LeaseDuration: secret.LeaseDuration,
|
||||
},
|
||||
},
|
||||
Increment: int(increment),
|
||||
Increment: int(token.TTL),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error beginning Vault provider token renewal: %v", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user