/
table_aws_eks_addon_version.go
208 lines (178 loc) · 5.67 KB
/
table_aws_eks_addon_version.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package aws
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/aws/aws-sdk-go-v2/service/eks/types"
eksv1 "github.com/aws/aws-sdk-go/service/eks"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
//// TABLE DEFINITION
func tableAwsEksAddonVersion(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_eks_addon_version",
Description: "AWS EKS Addon Version",
List: &plugin.ListConfig{
Hydrate: listEksAddonVersions,
Tags: map[string]string{"service": "eks", "action": "DescribeAddonVersions"},
KeyColumns: []*plugin.KeyColumn{
{Name: "addon_name", Require: plugin.Optional},
},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: getEksAddonConfiguration,
Tags: map[string]string{"service": "eks", "action": "DescribeAddonConfiguration"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(eksv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "addon_name",
Description: "The name of the add-on.",
Type: proto.ColumnType_STRING,
},
{
Name: "addon_version",
Description: "The version of the add-on.",
Type: proto.ColumnType_STRING,
},
{
Name: "type",
Description: "The type of the add-on.",
Type: proto.ColumnType_STRING,
},
{
Name: "addon_configuration",
Description: "The configuration for the add-on.",
Hydrate: getEksAddonConfiguration,
Type: proto.ColumnType_JSON,
Transform: transform.FromValue(),
},
{
Name: "architecture",
Description: "The architectures that the version supports.",
Type: proto.ColumnType_JSON,
},
{
Name: "compatibilities",
Description: "An object that represents the compatibilities of a version.",
Type: proto.ColumnType_JSON,
},
// Steampipe standard columns
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("AddonVersion"),
},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Hydrate: getAddonVersionAkas,
Transform: transform.FromValue(),
},
}),
}
}
type addonVersion struct {
AddonName *string
AddonVersion *string
Architecture []string
Compatibilities []types.Compatibility
Type *string
}
//// LIST FUNCTION
func listEksAddonVersions(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create service
svc, err := EKSClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_eks_addon_version.listEksAddonVersions", "get_client_error", err)
return nil, err
}
if svc == nil {
// Unsupported region check
return nil, nil
}
input := &eks.DescribeAddonVersionsInput{
MaxResults: aws.Int32(100),
}
equalQuals := d.EqualsQuals
if equalQuals["addon_name"] != nil {
input.AddonName = aws.String(equalQuals["addon_name"].GetStringValue())
}
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < *input.MaxResults {
if limit < 1 {
input.MaxResults = aws.Int32(1)
} else {
input.MaxResults = aws.Int32(limit)
}
}
}
paginator := eks.NewDescribeAddonVersionsPaginator(svc, input, func(o *eks.DescribeAddonVersionsPaginatorOptions) {
o.Limit = *input.MaxResults
o.StopOnDuplicateToken = true
})
for paginator.HasMorePages() {
// apply rate limiting
d.WaitForListRateLimit(ctx)
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_eks_addon_version.listEksAddonVersions", "api_error", err)
return nil, err
}
for _, addon := range output.Addons {
for _, version := range addon.AddonVersions {
d.StreamListItem(ctx, addonVersion{addon.AddonName, version.AddonVersion, version.Architecture, version.Compatibilities, addon.Type})
// Context may get cancelled due to manual cancellation or if the limit has been reached
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
}
return nil, err
}
//// HYDRATE FUNCTIONS
func getEksAddonConfiguration(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
data := h.Item.(addonVersion)
version := data.AddonVersion
addonName := data.AddonName
// create service
svc, err := EKSClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_eks_addon_version.getEksAddonConfiguration", "connection_error", err)
return nil, err
}
if svc == nil {
// Unsupported region check
return nil, nil
}
params := &eks.DescribeAddonConfigurationInput{
AddonName: addonName,
AddonVersion: version,
}
op, err := svc.DescribeAddonConfiguration(ctx, params)
if err != nil {
plugin.Logger(ctx).Error("aws_eks_addon_version.getEksAddonConfiguration", "api_error", err)
return nil, err
}
return op.ConfigurationSchema, nil
}
func getAddonVersionAkas(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
region := d.EqualsQualString(matrixKeyRegion)
version := h.Item.(addonVersion)
commonData, err := getCommonColumns(ctx, d, h)
if err != nil {
plugin.Logger(ctx).Error("aws_eks_addon_version.getAddonVersionAkas", "api_error", err)
return nil, err
}
commonColumnData := commonData.(*awsCommonColumnData)
akas := []string{"arn:" + commonColumnData.Partition + ":eks:" + region + ":" + commonColumnData.AccountId + ":addonversion/" + *version.AddonName + "/" + *version.AddonVersion}
return akas, nil
}