forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 114
/
credentials.go
40 lines (33 loc) · 960 Bytes
/
credentials.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
package sls
import (
"time"
)
type Credentials struct {
AccessKeyID string
AccessKeySecret string
SecurityToken string
}
// Expirable credentials with an expiration.
type tempCredentials struct {
Credentials
Expiration time.Time // The time when the credentials expires, unix timestamp in millis
LastUpdateTime time.Time
}
func newTempCredentials(accessKeyId, accessKeySecret, securityToken string,
expiration time.Time, lastUpdateTime time.Time) *tempCredentials {
return &tempCredentials{
Credentials: Credentials{
AccessKeyID: accessKeyId,
AccessKeySecret: accessKeySecret,
SecurityToken: securityToken,
},
Expiration: expiration,
LastUpdateTime: lastUpdateTime,
}
}
func (t *tempCredentials) isExpired() bool {
return time.Now().After(t.Expiration)
}
func (t *tempCredentials) isValid() bool {
return t.Credentials.AccessKeyID != "" && t.Credentials.AccessKeySecret != "" && !t.Expiration.IsZero()
}