This commit is contained in:
Alex Dadgar 2017-01-14 15:05:26 -08:00
parent f93f2249e9
commit 11f8e942eb
6 changed files with 14 additions and 27 deletions

View file

@ -1,8 +1,10 @@
package dependency
import "time"
var (
// VaultDefaultLeaseDuration is the default lease duration in seconds.
VaultDefaultLeaseDuration = 5 * 60
VaultDefaultLeaseDuration = 5 * time.Minute
)
// Secret is a vault secret.
@ -20,7 +22,7 @@ type Secret struct {
// leaseDurationOrDefault returns a value or the default lease duration.
func leaseDurationOrDefault(d int) int {
if d == 0 {
return VaultDefaultLeaseDuration
return int(VaultDefaultLeaseDuration.Nanoseconds() / 1000000000)
}
return d
}

View file

@ -20,8 +20,7 @@ var (
type VaultListQuery struct {
stopCh chan struct{}
path string
secret *Secret
path string
}
// NewVaultListQuery creates a new datacenter dependency.
@ -50,11 +49,7 @@ func (d *VaultListQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfac
// If this is not the first query, poll to simulate blocking-queries.
if opts.WaitIndex != 0 {
dur := time.Duration(d.secret.LeaseDuration/2.0) * time.Second
if dur == 0 {
dur = time.Duration(VaultDefaultLeaseDuration)
}
dur := VaultDefaultLeaseDuration
log.Printf("[TRACE] %s: long polling for %s", d, dur)
select {
@ -101,14 +96,6 @@ func (d *VaultListQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfac
}
sort.Strings(result)
d.secret = &Secret{
RequestID: secret.RequestID,
LeaseID: secret.LeaseID,
LeaseDuration: secret.LeaseDuration,
Renewable: secret.Renewable,
Data: secret.Data,
}
log.Printf("[TRACE] %s: returned %d results", d, len(result))
return respWithMetadata(result)

View file

@ -52,7 +52,7 @@ func (d *VaultReadQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfac
if opts.WaitIndex != 0 && d.secret != nil && d.secret.LeaseDuration != 0 {
dur := time.Duration(d.secret.LeaseDuration/2.0) * time.Second
if dur == 0 {
dur = time.Duration(VaultDefaultLeaseDuration)
dur = VaultDefaultLeaseDuration
}
log.Printf("[TRACE] %s: long polling for %s", d, dur)
@ -105,8 +105,7 @@ func (d *VaultReadQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfac
// The secret could be nil if it does not exist.
if vaultSecret == nil {
log.Printf("[WARN] %s: returned nil (does the secret exist?)", d)
return respWithMetadata(nil)
return nil, nil, fmt.Errorf("%s: no secret exists at %s", d, d.path)
}
// Print any warnings.

View file

@ -48,7 +48,7 @@ func (d *VaultTokenQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfa
if opts.WaitIndex != 0 && d.leaseDuration != 0 {
dur := time.Duration(d.leaseDuration/2.0) * time.Second
if dur == 0 {
dur = time.Duration(VaultDefaultLeaseDuration)
dur = VaultDefaultLeaseDuration
}
log.Printf("[TRACE] %s: long polling for %s", d, dur)

View file

@ -59,7 +59,7 @@ func (d *VaultWriteQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfa
if opts.WaitIndex != 0 && d.secret != nil && d.secret.LeaseDuration != 0 {
dur := time.Duration(d.secret.LeaseDuration/2.0) * time.Second
if dur == 0 {
dur = time.Duration(VaultDefaultLeaseDuration)
dur = VaultDefaultLeaseDuration
}
log.Printf("[TRACE] %s: long polling for %s", d, dur)
@ -113,8 +113,7 @@ func (d *VaultWriteQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interfa
// The secret could be nil if it does not exist.
if vaultSecret == nil {
log.Printf("[WARN] %s: returned nil (does the secret exist?)", d)
return respWithMetadata(nil)
return nil, nil, fmt.Errorf("%s: no secret exists at %s", d, d.path)
}
// Print any warnings.

6
vendor/vendor.json vendored
View file

@ -513,10 +513,10 @@
"revisionTime": "2017-01-13T23:20:51Z"
},
{
"checksumSHA1": "1ioVPkGIVei92yBS2M07A3rBxPI=",
"checksumSHA1": "DtjuCLwZmI1QjzsRGWZU+tnedC8=",
"path": "github.com/hashicorp/consul-template/dependency",
"revision": "81e8f468004caef5755e1073fe39ff48203a89b6",
"revisionTime": "2017-01-13T23:20:51Z"
"revision": "d6391c0e0c526ad3596401cda740531f17f7ad3a",
"revisionTime": "2017-01-14T21:20:18Z"
},
{
"checksumSHA1": "efWxWe8blQflfYZFU1WSIks2Tbw=",