SetExpiration sets the expiration IsExpired will check when called. If window is greater than 0 the expiration time will be reduced by the window value. Using a window is helpful to trigger credentials to expire sooner than the expiration time given to ensure no requests are made with expired toke
(expiration time.Time, window time.Duration)
| 117 | // the expiration time given to ensure no requests are made with expired |
| 118 | // tokens. |
| 119 | func (e *Expiry) SetExpiration(expiration time.Time, window time.Duration) { |
| 120 | if e.CurrentTime == nil { |
| 121 | e.CurrentTime = time.Now |
| 122 | } |
| 123 | cut := window |
| 124 | if cut < 0 { |
| 125 | expireIn := expiration.Sub(e.CurrentTime()) |
| 126 | cut = time.Duration(float64(expireIn) * (1 - defaultExpiryWindow)) |
| 127 | } |
| 128 | e.expiration = expiration.Add(-cut) |
| 129 | } |
| 130 | |
| 131 | // IsExpired returns if the credentials are expired. |
| 132 | func (e *Expiry) IsExpired() bool { |
no test coverage detected