1
1
package aws
2
2
3
3
import (
4
- "github.com/aws/aws-sdk-go/service/ec2"
5
- "github.com/aws/aws-sdk-go/service/elasticache"
6
- "github.com/aws/aws-sdk-go/service/iam"
7
- "github.com/aws/aws-sdk-go/service/rds"
4
+ "context"
5
+
6
+ "github.com/aws/aws-sdk-go-v2/service/ec2"
7
+ "github.com/aws/aws-sdk-go-v2/service/elasticache"
8
+ "github.com/aws/aws-sdk-go-v2/service/iam"
9
+ "github.com/aws/aws-sdk-go-v2/service/rds"
8
10
)
9
11
12
+ // Client is an interface for API client.
13
+ // This is primarily used for mock clients.
14
+ type Client interface {
15
+ DescribeSecurityGroups () (map [string ]bool , error )
16
+ DescribeSubnets () (map [string ]bool , error )
17
+ DescribeDBSubnetGroups () (map [string ]bool , error )
18
+ DescribeOptionGroups () (map [string ]bool , error )
19
+ DescribeDBParameterGroups () (map [string ]bool , error )
20
+ DescribeCacheParameterGroups () (map [string ]bool , error )
21
+ DescribeCacheSubnetGroups () (map [string ]bool , error )
22
+ DescribeInstances () (map [string ]bool , error )
23
+ DescribeImages (* ec2.DescribeImagesInput ) (map [string ]bool , error )
24
+ ListInstanceProfiles () (map [string ]bool , error )
25
+ DescribeKeyPairs () (map [string ]bool , error )
26
+ DescribeEgressOnlyInternetGateways () (map [string ]bool , error )
27
+ DescribeInternetGateways () (map [string ]bool , error )
28
+ DescribeNatGateways () (map [string ]bool , error )
29
+ DescribeNetworkInterfaces () (map [string ]bool , error )
30
+ DescribeRouteTables () (map [string ]bool , error )
31
+ DescribeVpcPeeringConnections () (map [string ]bool , error )
32
+ }
33
+
10
34
// DescribeSecurityGroups is a wrapper of DescribeSecurityGroups
11
- func (c * Client ) DescribeSecurityGroups () (map [string ]bool , error ) {
35
+ func (c * AwsClient ) DescribeSecurityGroups () (map [string ]bool , error ) {
12
36
ret := map [string ]bool {}
13
- resp , err := c .EC2 .DescribeSecurityGroups (& ec2.DescribeSecurityGroupsInput {})
37
+ resp , err := c .EC2 .DescribeSecurityGroups (context . Background (), & ec2.DescribeSecurityGroupsInput {})
14
38
if err != nil {
15
39
return ret , err
16
40
}
@@ -21,9 +45,9 @@ func (c *Client) DescribeSecurityGroups() (map[string]bool, error) {
21
45
}
22
46
23
47
// DescribeSubnets is a wrapper of DescribeSubnets
24
- func (c * Client ) DescribeSubnets () (map [string ]bool , error ) {
48
+ func (c * AwsClient ) DescribeSubnets () (map [string ]bool , error ) {
25
49
ret := map [string ]bool {}
26
- resp , err := c .EC2 .DescribeSubnets (& ec2.DescribeSubnetsInput {})
50
+ resp , err := c .EC2 .DescribeSubnets (context . Background (), & ec2.DescribeSubnetsInput {})
27
51
if err != nil {
28
52
return ret , err
29
53
}
@@ -34,9 +58,9 @@ func (c *Client) DescribeSubnets() (map[string]bool, error) {
34
58
}
35
59
36
60
// DescribeDBSubnetGroups is a wrapper of DescribeDBSubnetGroups
37
- func (c * Client ) DescribeDBSubnetGroups () (map [string ]bool , error ) {
61
+ func (c * AwsClient ) DescribeDBSubnetGroups () (map [string ]bool , error ) {
38
62
ret := map [string ]bool {}
39
- resp , err := c .RDS .DescribeDBSubnetGroups (& rds.DescribeDBSubnetGroupsInput {})
63
+ resp , err := c .RDS .DescribeDBSubnetGroups (context . Background (), & rds.DescribeDBSubnetGroupsInput {})
40
64
if err != nil {
41
65
return ret , err
42
66
}
@@ -47,9 +71,9 @@ func (c *Client) DescribeDBSubnetGroups() (map[string]bool, error) {
47
71
}
48
72
49
73
// DescribeOptionGroups is a wrapper of DescribeOptionGroups
50
- func (c * Client ) DescribeOptionGroups () (map [string ]bool , error ) {
74
+ func (c * AwsClient ) DescribeOptionGroups () (map [string ]bool , error ) {
51
75
ret := map [string ]bool {}
52
- resp , err := c .RDS .DescribeOptionGroups (& rds.DescribeOptionGroupsInput {})
76
+ resp , err := c .RDS .DescribeOptionGroups (context . Background (), & rds.DescribeOptionGroupsInput {})
53
77
if err != nil {
54
78
return ret , err
55
79
}
@@ -60,9 +84,9 @@ func (c *Client) DescribeOptionGroups() (map[string]bool, error) {
60
84
}
61
85
62
86
// DescribeDBParameterGroups is a wrapper of DescribeDBParameterGroups
63
- func (c * Client ) DescribeDBParameterGroups () (map [string ]bool , error ) {
87
+ func (c * AwsClient ) DescribeDBParameterGroups () (map [string ]bool , error ) {
64
88
ret := map [string ]bool {}
65
- resp , err := c .RDS .DescribeDBParameterGroups (& rds.DescribeDBParameterGroupsInput {})
89
+ resp , err := c .RDS .DescribeDBParameterGroups (context . Background (), & rds.DescribeDBParameterGroupsInput {})
66
90
if err != nil {
67
91
return ret , err
68
92
}
@@ -73,9 +97,9 @@ func (c *Client) DescribeDBParameterGroups() (map[string]bool, error) {
73
97
}
74
98
75
99
// DescribeCacheParameterGroups is a wrapper of DescribeCacheParameterGroups
76
- func (c * Client ) DescribeCacheParameterGroups () (map [string ]bool , error ) {
100
+ func (c * AwsClient ) DescribeCacheParameterGroups () (map [string ]bool , error ) {
77
101
ret := map [string ]bool {}
78
- resp , err := c .ElastiCache .DescribeCacheParameterGroups (& elasticache.DescribeCacheParameterGroupsInput {})
102
+ resp , err := c .ElastiCache .DescribeCacheParameterGroups (context . Background (), & elasticache.DescribeCacheParameterGroupsInput {})
79
103
if err != nil {
80
104
return ret , err
81
105
}
@@ -86,9 +110,9 @@ func (c *Client) DescribeCacheParameterGroups() (map[string]bool, error) {
86
110
}
87
111
88
112
// DescribeCacheSubnetGroups is a wrapper of DescribeCacheSubnetGroups
89
- func (c * Client ) DescribeCacheSubnetGroups () (map [string ]bool , error ) {
113
+ func (c * AwsClient ) DescribeCacheSubnetGroups () (map [string ]bool , error ) {
90
114
ret := map [string ]bool {}
91
- resp , err := c .ElastiCache .DescribeCacheSubnetGroups (& elasticache.DescribeCacheSubnetGroupsInput {})
115
+ resp , err := c .ElastiCache .DescribeCacheSubnetGroups (context . Background (), & elasticache.DescribeCacheSubnetGroupsInput {})
92
116
if err != nil {
93
117
return ret , err
94
118
}
@@ -99,9 +123,9 @@ func (c *Client) DescribeCacheSubnetGroups() (map[string]bool, error) {
99
123
}
100
124
101
125
// DescribeInstances is a wrapper of DescribeInstances
102
- func (c * Client ) DescribeInstances () (map [string ]bool , error ) {
126
+ func (c * AwsClient ) DescribeInstances () (map [string ]bool , error ) {
103
127
ret := map [string ]bool {}
104
- resp , err := c .EC2 .DescribeInstances (& ec2.DescribeInstancesInput {})
128
+ resp , err := c .EC2 .DescribeInstances (context . Background (), & ec2.DescribeInstancesInput {})
105
129
if err != nil {
106
130
return ret , err
107
131
}
@@ -113,10 +137,23 @@ func (c *Client) DescribeInstances() (map[string]bool, error) {
113
137
return ret , err
114
138
}
115
139
140
+ // DescribeImages is a wrapper of DescribeImages
141
+ func (c * AwsClient ) DescribeImages (in * ec2.DescribeImagesInput ) (map [string ]bool , error ) {
142
+ ret := map [string ]bool {}
143
+ resp , err := c .EC2 .DescribeImages (context .Background (), in )
144
+ if err != nil {
145
+ return ret , err
146
+ }
147
+ for _ , image := range resp .Images {
148
+ ret [* image .ImageId ] = true
149
+ }
150
+ return ret , err
151
+ }
152
+
116
153
// ListInstanceProfiles is a wrapper of ListInstanceProfiles
117
- func (c * Client ) ListInstanceProfiles () (map [string ]bool , error ) {
154
+ func (c * AwsClient ) ListInstanceProfiles () (map [string ]bool , error ) {
118
155
ret := map [string ]bool {}
119
- resp , err := c .IAM .ListInstanceProfiles (& iam.ListInstanceProfilesInput {})
156
+ resp , err := c .IAM .ListInstanceProfiles (context . Background (), & iam.ListInstanceProfilesInput {})
120
157
if err != nil {
121
158
return ret , err
122
159
}
@@ -127,9 +164,9 @@ func (c *Client) ListInstanceProfiles() (map[string]bool, error) {
127
164
}
128
165
129
166
// DescribeKeyPairs is a wrapper of DescribeKeyPairs
130
- func (c * Client ) DescribeKeyPairs () (map [string ]bool , error ) {
167
+ func (c * AwsClient ) DescribeKeyPairs () (map [string ]bool , error ) {
131
168
ret := map [string ]bool {}
132
- resp , err := c .EC2 .DescribeKeyPairs (& ec2.DescribeKeyPairsInput {})
169
+ resp , err := c .EC2 .DescribeKeyPairs (context . Background (), & ec2.DescribeKeyPairsInput {})
133
170
if err != nil {
134
171
return ret , err
135
172
}
@@ -140,9 +177,9 @@ func (c *Client) DescribeKeyPairs() (map[string]bool, error) {
140
177
}
141
178
142
179
// DescribeEgressOnlyInternetGateways is wrapper of DescribeEgressOnlyInternetGateways
143
- func (c * Client ) DescribeEgressOnlyInternetGateways () (map [string ]bool , error ) {
180
+ func (c * AwsClient ) DescribeEgressOnlyInternetGateways () (map [string ]bool , error ) {
144
181
ret := map [string ]bool {}
145
- resp , err := c .EC2 .DescribeEgressOnlyInternetGateways (& ec2.DescribeEgressOnlyInternetGatewaysInput {})
182
+ resp , err := c .EC2 .DescribeEgressOnlyInternetGateways (context . Background (), & ec2.DescribeEgressOnlyInternetGatewaysInput {})
146
183
if err != nil {
147
184
return ret , err
148
185
}
@@ -153,9 +190,9 @@ func (c *Client) DescribeEgressOnlyInternetGateways() (map[string]bool, error) {
153
190
}
154
191
155
192
// DescribeInternetGateways is a wrapper of DescribeInternetGateways
156
- func (c * Client ) DescribeInternetGateways () (map [string ]bool , error ) {
193
+ func (c * AwsClient ) DescribeInternetGateways () (map [string ]bool , error ) {
157
194
ret := map [string ]bool {}
158
- resp , err := c .EC2 .DescribeInternetGateways (& ec2.DescribeInternetGatewaysInput {})
195
+ resp , err := c .EC2 .DescribeInternetGateways (context . Background (), & ec2.DescribeInternetGatewaysInput {})
159
196
if err != nil {
160
197
return ret , err
161
198
}
@@ -166,9 +203,9 @@ func (c *Client) DescribeInternetGateways() (map[string]bool, error) {
166
203
}
167
204
168
205
// DescribeNatGateways is a wrapper of DescribeNatGateways
169
- func (c * Client ) DescribeNatGateways () (map [string ]bool , error ) {
206
+ func (c * AwsClient ) DescribeNatGateways () (map [string ]bool , error ) {
170
207
ret := map [string ]bool {}
171
- resp , err := c .EC2 .DescribeNatGateways (& ec2.DescribeNatGatewaysInput {})
208
+ resp , err := c .EC2 .DescribeNatGateways (context . Background (), & ec2.DescribeNatGatewaysInput {})
172
209
if err != nil {
173
210
return ret , err
174
211
}
@@ -179,9 +216,9 @@ func (c *Client) DescribeNatGateways() (map[string]bool, error) {
179
216
}
180
217
181
218
// DescribeNetworkInterfaces is a wrapper of DescribeNetworkInterfaces
182
- func (c * Client ) DescribeNetworkInterfaces () (map [string ]bool , error ) {
219
+ func (c * AwsClient ) DescribeNetworkInterfaces () (map [string ]bool , error ) {
183
220
ret := map [string ]bool {}
184
- resp , err := c .EC2 .DescribeNetworkInterfaces (& ec2.DescribeNetworkInterfacesInput {})
221
+ resp , err := c .EC2 .DescribeNetworkInterfaces (context . Background (), & ec2.DescribeNetworkInterfacesInput {})
185
222
if err != nil {
186
223
return ret , err
187
224
}
@@ -192,9 +229,9 @@ func (c *Client) DescribeNetworkInterfaces() (map[string]bool, error) {
192
229
}
193
230
194
231
// DescribeRouteTables is a wrapper of DescribeRouteTables
195
- func (c * Client ) DescribeRouteTables () (map [string ]bool , error ) {
232
+ func (c * AwsClient ) DescribeRouteTables () (map [string ]bool , error ) {
196
233
ret := map [string ]bool {}
197
- resp , err := c .EC2 .DescribeRouteTables (& ec2.DescribeRouteTablesInput {})
234
+ resp , err := c .EC2 .DescribeRouteTables (context . Background (), & ec2.DescribeRouteTablesInput {})
198
235
if err != nil {
199
236
return ret , err
200
237
}
@@ -205,9 +242,9 @@ func (c *Client) DescribeRouteTables() (map[string]bool, error) {
205
242
}
206
243
207
244
// DescribeVpcPeeringConnections is a wrapper of DescribeVpcPeeringConnections
208
- func (c * Client ) DescribeVpcPeeringConnections () (map [string ]bool , error ) {
245
+ func (c * AwsClient ) DescribeVpcPeeringConnections () (map [string ]bool , error ) {
209
246
ret := map [string ]bool {}
210
- resp , err := c .EC2 .DescribeVpcPeeringConnections (& ec2.DescribeVpcPeeringConnectionsInput {})
247
+ resp , err := c .EC2 .DescribeVpcPeeringConnections (context . Background (), & ec2.DescribeVpcPeeringConnectionsInput {})
211
248
if err != nil {
212
249
return ret , err
213
250
}
0 commit comments