2015-04-09 19:14:04 +00:00
|
|
|
package logical
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
// LeaseOptions is an embeddable struct to capture common lease
|
|
|
|
// settings between a Secret and Auth
|
|
|
|
type LeaseOptions struct {
|
|
|
|
// Lease is the duration that this secret is valid for. Vault
|
|
|
|
// will automatically revoke it after the duration + grace period.
|
2015-08-21 00:47:17 +00:00
|
|
|
Lease time.Duration `json:"lease,omitempty"`
|
|
|
|
TTL time.Duration `json:"ttl,omitempty"`
|
|
|
|
GracePeriod time.Duration `json:"grace_period"`
|
2015-04-09 19:14:04 +00:00
|
|
|
|
|
|
|
// Renewable, if true, means that this secret can be renewed.
|
|
|
|
Renewable bool `json:"renewable"`
|
|
|
|
|
|
|
|
// LeaseIncrement will be the lease increment that the user requested.
|
|
|
|
// This is only available on a Renew operation and has no effect
|
|
|
|
// when returning a response.
|
|
|
|
LeaseIncrement time.Duration `json:"-"`
|
|
|
|
|
|
|
|
// LeaseIssue is the time of issue for the original lease. This is
|
|
|
|
// only available on a Renew operation and has no effect when returning
|
|
|
|
// a response. It can be used to enforce maximum lease periods by
|
2015-04-11 03:49:17 +00:00
|
|
|
// a logical backend. This time will always be in UTC.
|
2015-04-09 19:14:04 +00:00
|
|
|
LeaseIssue time.Time `json:"-"`
|
|
|
|
}
|
2015-04-09 19:29:13 +00:00
|
|
|
|
|
|
|
// LeaseEnabled checks if leasing is enabled
|
|
|
|
func (l *LeaseOptions) LeaseEnabled() bool {
|
2015-08-21 00:47:17 +00:00
|
|
|
return l.TTL > 0
|
2015-04-09 19:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LeaseTotal is the total lease time including the grace period
|
|
|
|
func (l *LeaseOptions) LeaseTotal() time.Duration {
|
2015-08-21 00:47:17 +00:00
|
|
|
if l.TTL <= 0 {
|
2015-04-09 19:29:13 +00:00
|
|
|
return 0
|
|
|
|
}
|
2015-04-11 04:29:03 +00:00
|
|
|
|
2015-08-21 00:47:17 +00:00
|
|
|
if l.GracePeriod < 0 {
|
|
|
|
return l.TTL
|
2015-04-11 04:29:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 00:47:17 +00:00
|
|
|
return l.TTL + l.GracePeriod
|
2015-04-09 19:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExpirationTime computes the time until expiration including the grace period
|
|
|
|
func (l *LeaseOptions) ExpirationTime() time.Time {
|
|
|
|
var expireTime time.Time
|
2015-06-17 20:59:09 +00:00
|
|
|
if l.LeaseEnabled() {
|
|
|
|
expireTime = time.Now().UTC().Add(l.LeaseTotal())
|
2015-04-09 19:29:13 +00:00
|
|
|
}
|
|
|
|
return expireTime
|
|
|
|
}
|