forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlease.go
48 lines (39 loc) · 1.38 KB
/
lease.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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.
TTL time.Duration `json:"lease"`
// Renewable, if true, means that this secret can be renewed.
Renewable bool `json:"renewable"`
// Increment 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.
Increment time.Duration `json:"-"`
// IssueTime 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
// a logical backend.
IssueTime time.Time `json:"-"`
}
// LeaseEnabled checks if leasing is enabled
func (l *LeaseOptions) LeaseEnabled() bool {
return l.TTL > 0
}
// LeaseTotal is the lease duration with a guard against a negative TTL
func (l *LeaseOptions) LeaseTotal() time.Duration {
if l.TTL <= 0 {
return 0
}
return l.TTL
}
// ExpirationTime computes the time until expiration including the grace period
func (l *LeaseOptions) ExpirationTime() time.Time {
var expireTime time.Time
if l.LeaseEnabled() {
expireTime = time.Now().Add(l.LeaseTotal())
}
return expireTime
}