forked from coinbase/fenrir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.go
54 lines (43 loc) · 869 Bytes
/
iam.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
package iam
import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/coinbase/fenrir/aws"
)
//////
// ROLE
//////
type Role struct {
Arn *string
Tags map[string]*string
}
func (r *Role) ProjectName() *string {
return r.Tags["ProjectName"]
}
func (r *Role) ConfigName() *string {
return r.Tags["ConfigName"]
}
func (r *Role) ServiceName() *string {
return r.Tags["ServiceName"]
}
// RoleExists returns whether profile exists
func GetRole(iamc aws.IAMAPI, roleName *string) (*Role, error) {
out, err := iamc.GetRole(&iam.GetRoleInput{
RoleName: roleName,
})
if err != nil {
return nil, err
}
outRole := Role{
Arn: out.Role.Arn,
Tags: map[string]*string{},
}
if out.Role.Tags != nil {
for _, tag := range out.Role.Tags {
if tag.Key == nil {
continue
}
outRole.Tags[*tag.Key] = tag.Value
}
}
return &outRole, nil
}