github.com/adrian-bl/terraform@v0.7.0-rc2.0.20160705220747-de0a34fc3517/builtin/providers/aws/iam_policy_model.go (about) 1 package aws 2 3 import ( 4 "encoding/json" 5 ) 6 7 type IAMPolicyDoc struct { 8 Id string `json:",omitempty"` 9 Version string `json:",omitempty"` 10 Statements []*IAMPolicyStatement `json:"Statement"` 11 } 12 13 type IAMPolicyStatement struct { 14 Sid string `json:",omitempty"` 15 Effect string `json:",omitempty"` 16 Actions []string `json:"Action,omitempty"` 17 NotActions []string `json:"NotAction,omitempty"` 18 Resources []string `json:"Resource,omitempty"` 19 NotResources []string `json:"NotResource,omitempty"` 20 Principals IAMPolicyStatementPrincipalSet `json:"Principal,omitempty"` 21 NotPrincipals IAMPolicyStatementPrincipalSet `json:"NotPrincipal,omitempty"` 22 Conditions IAMPolicyStatementConditionSet `json:"Condition,omitempty"` 23 } 24 25 type IAMPolicyStatementPrincipal struct { 26 Type string 27 Identifiers []string 28 } 29 30 type IAMPolicyStatementCondition struct { 31 Test string 32 Variable string 33 Values []string 34 } 35 36 type IAMPolicyStatementPrincipalSet []IAMPolicyStatementPrincipal 37 type IAMPolicyStatementConditionSet []IAMPolicyStatementCondition 38 39 func (ps IAMPolicyStatementPrincipalSet) MarshalJSON() ([]byte, error) { 40 raw := map[string][]string{} 41 42 for _, p := range ps { 43 if _, ok := raw[p.Type]; !ok { 44 raw[p.Type] = make([]string, 0, len(p.Identifiers)) 45 } 46 raw[p.Type] = append(raw[p.Type], p.Identifiers...) 47 } 48 49 return json.Marshal(&raw) 50 } 51 52 func (cs IAMPolicyStatementConditionSet) MarshalJSON() ([]byte, error) { 53 raw := map[string]map[string][]string{} 54 55 for _, c := range cs { 56 if _, ok := raw[c.Test]; !ok { 57 raw[c.Test] = map[string][]string{} 58 } 59 if _, ok := raw[c.Test][c.Variable]; !ok { 60 raw[c.Test][c.Variable] = make([]string, 0, len(c.Values)) 61 } 62 raw[c.Test][c.Variable] = append(raw[c.Test][c.Variable], c.Values...) 63 } 64 65 return json.Marshal(&raw) 66 } 67 68 func iamPolicyDecodeConfigStringList(lI []interface{}) []string { 69 ret := make([]string, len(lI)) 70 for i, vI := range lI { 71 ret[i] = vI.(string) 72 } 73 return ret 74 }