-
-
Notifications
You must be signed in to change notification settings - Fork 957
/
policy.go
42 lines (35 loc) · 1.22 KB
/
policy.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
package aws_helper
import "encoding/json"
// Policy - representation of the policy for AWS
type Policy struct {
Version string `json:"Version"`
Statement []Statement `json:"Statement"`
}
// Statement - AWS policy statement
// Action and Resource - can be string OR array of strings
// https://docs.aws.amazon.com/IAM//latest/UserGuide/reference_policies_elements_action.html
// https://docs.aws.amazon.com/IAM//latest/UserGuide/reference_policies_elements_resource.html
type Statement struct {
Sid string `json:"Sid"`
Effect string `json:"Effect"`
Principal interface{} `json:"Principal,omitempty"`
NotPrincipal interface{} `json:"NotPrincipal,omitempty"`
Action interface{} `json:"Action"`
Resource interface{} `json:"Resource"`
Condition *map[string]interface{} `json:"Condition,omitempty"`
}
func UnmarshalPolicy(policy string) (Policy, error) {
var p Policy
err := json.Unmarshal([]byte(policy), &p)
if err != nil {
return p, err
}
return p, nil
}
func MarshalPolicy(policy Policy) ([]byte, error) {
policyJson, err := json.Marshal(policy)
if err != nil {
return nil, err
}
return policyJson, nil
}