-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrole.go
67 lines (52 loc) · 1.11 KB
/
role.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"errors"
"regexp"
"time"
)
var (
roleArnRegex = regexp.MustCompile(`^arn:aws:iam::(\d+):role/([^:]+/)?([^:]+?)$`)
)
type roleArn struct {
value string
path string
name string
accountID string
}
func newRoleArn(value string) (roleArn, error) {
result := roleArnRegex.FindStringSubmatch(value)
if result == nil {
return roleArn{}, errors.New("invalid role ARN")
}
return roleArn{value, "/" + result[2], result[3], result[1]}, nil
}
func (r roleArn) RoleName() string {
return r.name
}
func (r roleArn) Path() string {
return r.path
}
func (r roleArn) AccountID() string {
return r.accountID
}
func (r roleArn) String() string {
return r.value
}
func (r roleArn) Empty() bool {
return len(r.value) == 0
}
func (r roleArn) Equals(other roleArn) bool {
return r.value == other.value
}
type roleCredentials struct {
AccessKey string
SecretKey string
Token string
Expiration time.Time
}
func (t *roleCredentials) ExpiredNow() bool {
return t.ExpiredAt(time.Now())
}
func (t *roleCredentials) ExpiredAt(at time.Time) bool {
return at.After(t.Expiration)
}