/
policies.go
86 lines (78 loc) · 1.74 KB
/
policies.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package api
import (
"encoding/json"
"fmt"
"github.com/YaleSpinup/aws-go/services/iam"
)
// moverCreatePolicy returns the IAM inline policy for creating a mover
func (s *server) moverCreatePolicy() (string, error) {
policy := &iam.PolicyDocument{
Version: "2012-10-17",
Statement: []iam.StatementEntry{
{
Sid: "CreateRole",
Effect: "Allow",
Action: []string{
"iam:CreateRole",
"iam:GetRole",
"iam:GetRolePolicy",
"iam:ListAttachedRolePolicies",
"iam:ListRolePolicies",
"iam:AttachRolePolicy",
"iam:PutRolePolicy",
"iam:TagRole",
"iam:UntagRole",
},
Resource: []string{
fmt.Sprintf("arn:aws:iam::*:role/spinup/%s/*", s.org),
},
},
{
Sid: "DeleteRole",
Effect: "Allow",
Action: []string{
"iam:DeleteRole",
"iam:DetachRolePolicy",
"iam:DeleteRolePolicy",
},
Resource: []string{
fmt.Sprintf("arn:aws:iam::*:role/spinup/%s/*", s.org),
},
},
},
}
j, err := json.Marshal(policy)
if err != nil {
return "", err
}
return string(j), nil
}
// moverDeletePolicy returns the IAM inline policy for deleting a mover
func (s *server) moverDeletePolicy() (string, error) {
policy := &iam.PolicyDocument{
Version: "2012-10-17",
Statement: []iam.StatementEntry{
{
Sid: "DeleteRole",
Effect: "Allow",
Action: []string{
"iam:DeleteRole",
"iam:GetRole",
"iam:GetRolePolicy",
"iam:ListAttachedRolePolicies",
"iam:ListRolePolicies",
"iam:DetachRolePolicy",
"iam:DeleteRolePolicy",
},
Resource: []string{
fmt.Sprintf("arn:aws:iam::*:role/spinup/%s/*", s.org),
},
},
},
}
j, err := json.Marshal(policy)
if err != nil {
return "", err
}
return string(j), nil
}