1
1
package iamy
2
2
3
3
import (
4
- "bytes"
5
- "encoding/json"
6
4
"fmt"
7
- "net/url"
8
5
"regexp"
9
6
"strings"
10
-
11
- "github.com/mtibben/yamljsonmap"
12
7
)
13
8
14
- type PolicyDocument yamljsonmap.StringKeyMap
15
-
16
- func (p * PolicyDocument ) Encode () string {
17
- return url .QueryEscape (string (p .json ()))
18
- }
19
-
20
- func (p PolicyDocument ) json () []byte {
21
- jsonBytes , err := json .Marshal (yamljsonmap .StringKeyMap (p ))
22
- if err != nil {
23
- panic (err .Error ())
24
- }
25
- return jsonBytes
26
- }
27
-
28
- func (p * PolicyDocument ) JsonString () string {
29
- var out bytes.Buffer
30
- json .Indent (& out , p .json (), "" , " " )
31
- return out .String ()
32
- }
33
-
34
- func (m PolicyDocument ) MarshalJSON () ([]byte , error ) {
35
- return json .Marshal (yamljsonmap .StringKeyMap (m ))
36
- }
37
-
38
- func (m * PolicyDocument ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
39
- var n yamljsonmap.StringKeyMap
40
- if err := unmarshal (& n ); err != nil {
41
- return err
42
- }
43
- * m = PolicyDocument (n )
44
-
45
- return nil
46
- }
47
-
48
- func NewPolicyDocumentFromEncodedJson (encoded string ) (PolicyDocument , error ) {
49
- jsonString , err := url .QueryUnescape (encoded )
50
- if err != nil {
51
- return nil , err
52
- }
53
-
54
- var doc PolicyDocument
55
- if err = json .Unmarshal ([]byte (jsonString ), & doc ); err != nil {
56
- return nil , err
57
- }
58
-
59
- return doc , nil
60
- }
61
-
62
9
type Account struct {
63
10
Id string
64
11
Alias string
@@ -103,8 +50,8 @@ func Arn(r AwsResource, a *Account) string {
103
50
}
104
51
105
52
type iamService struct {
106
- Name string `yaml :"-"`
107
- Path string `yaml :"-"`
53
+ Name string `json :"-"`
54
+ Path string `json :"-"`
108
55
}
109
56
110
57
func (s iamService ) Service () string {
@@ -120,54 +67,54 @@ func (s iamService) ResourcePath() string {
120
67
}
121
68
122
69
type User struct {
123
- iamService `yaml :"-"`
124
- Groups []string `yaml :"Groups,omitempty"`
125
- InlinePolicies []InlinePolicy `yaml :"InlinePolicies,omitempty"`
126
- Policies []string `yaml :"Policies,omitempty"`
70
+ iamService `json :"-"`
71
+ Groups []string `json :"Groups,omitempty"`
72
+ InlinePolicies []InlinePolicy `json :"InlinePolicies,omitempty"`
73
+ Policies []string `json :"Policies,omitempty"`
127
74
}
128
75
129
76
func (u User ) ResourceType () string {
130
77
return "user"
131
78
}
132
79
133
80
type Group struct {
134
- iamService `yaml :"-"`
135
- InlinePolicies []InlinePolicy `yaml :"InlinePolicies,omitempty"`
136
- Policies []string `yaml :"Policies,omitempty"`
81
+ iamService `json :"-"`
82
+ InlinePolicies []InlinePolicy `json :"InlinePolicies,omitempty"`
83
+ Policies []string `json :"Policies,omitempty"`
137
84
}
138
85
139
86
func (g Group ) ResourceType () string {
140
87
return "group"
141
88
}
142
89
143
90
type InlinePolicy struct {
144
- Name string `yaml :"Name"`
145
- Policy PolicyDocument `yaml :"Policy"`
91
+ Name string `json :"Name"`
92
+ Policy * PolicyDocument `json :"Policy"`
146
93
}
147
94
148
95
type Policy struct {
149
- iamService `yaml :"-"`
150
- Policy PolicyDocument `yaml :"Policy"`
96
+ iamService `json :"-"`
97
+ Policy * PolicyDocument `json :"Policy"`
151
98
}
152
99
153
100
func (p Policy ) ResourceType () string {
154
101
return "policy"
155
102
}
156
103
157
104
type Role struct {
158
- iamService `yaml :"-"`
159
- AssumeRolePolicyDocument PolicyDocument `yaml :"AssumeRolePolicyDocument"`
160
- InlinePolicies []InlinePolicy `yaml :"InlinePolicies,omitempty"`
161
- Policies []string `yaml :"Policies,omitempty"`
105
+ iamService `json :"-"`
106
+ AssumeRolePolicyDocument * PolicyDocument `json :"AssumeRolePolicyDocument"`
107
+ InlinePolicies []InlinePolicy `json :"InlinePolicies,omitempty"`
108
+ Policies []string `json :"Policies,omitempty"`
162
109
}
163
110
164
111
func (r Role ) ResourceType () string {
165
112
return "role"
166
113
}
167
114
168
115
type BucketPolicy struct {
169
- BucketName string `yaml :"-"`
170
- Policy PolicyDocument `yaml :"Policy"`
116
+ BucketName string `json :"-"`
117
+ Policy * PolicyDocument `json :"Policy"`
171
118
}
172
119
173
120
func (u BucketPolicy ) Service () string {
0 commit comments