/
table_aws_fms_app_list.go
204 lines (178 loc) · 5.57 KB
/
table_aws_fms_app_list.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
package aws
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/fms"
"github.com/aws/aws-sdk-go-v2/service/fms/types"
fmsv1 "github.com/aws/aws-sdk-go/service/fms"
"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 tableAwsFMSAppList(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_fms_app_list",
Description: "AWS FMS App List",
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("list_id"),
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}),
},
Hydrate: getFmsAppList,
Tags: map[string]string{"service": "fms", "action": "GetAppsList"},
},
List: &plugin.ListConfig{
Hydrate: listFmsAppLists,
Tags: map[string]string{"service": "fms", "action": "ListAppsLists"},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: getFmsAppList,
Tags: map[string]string{"service": "fms", "action": "GetAppsList"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(fmsv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "list_name",
Description: "The name of the applications list.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ListName", "AppsList.ListName"),
},
{
Name: "list_id",
Description: "The ID of the applications list.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ListId", "AppsList.ListId"),
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the applications list.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ListArn", "AppsListArn"),
},
{
Name: "create_time",
Description: "The time that the Firewall Manager applications list was created.",
Type: proto.ColumnType_TIMESTAMP,
Hydrate: getFmsAppList,
},
{
Name: "last_update_time",
Description: "The time that the Firewall Manager applications list was last updated.",
Type: proto.ColumnType_TIMESTAMP,
Hydrate: getFmsAppList,
},
{
Name: "list_update_token",
Description: "A unique identifier for each update to the list. When you update the list, the update token must match the token of the current version of the application list.",
Type: proto.ColumnType_STRING,
Hydrate: getFmsAppList,
},
{
Name: "previous_apps_list",
Description: "A map of previous version numbers to their corresponding App object arrays.",
Type: proto.ColumnType_JSON,
Hydrate: getFmsAppList,
},
{
Name: "apps_list",
Description: "An array of applications in the Firewall Manager applications list.",
Type: proto.ColumnType_JSON,
Hydrate: getFmsAppList,
},
// Steampipe standard columns
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ListName", "AppsList.ListName"),
},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ListArn", "AppsListArn").Transform(transform.EnsureStringArray),
},
}),
}
}
//// LIST FUNCTION
func listFmsAppLists(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create Session
svc, err := FMSClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_fms_app_list.listFmsAppLists", "connection_error", err)
return nil, err
}
if svc == nil {
// Unsupported region, return no data
return nil, nil
}
// Reduce the basic request limit down if the user has only requested a small number of rows
maxItems := int32(100)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxItems {
maxItems = int32(limit)
}
}
input := fms.ListAppsListsInput{
MaxResults: aws.Int32(maxItems),
}
paginator := fms.NewListAppsListsPaginator(svc, &input, func(o *fms.ListAppsListsPaginatorOptions) {
o.Limit = maxItems
o.StopOnDuplicateToken = true
})
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_fms_app_list.listFmsAppLists", "api_error", err)
return nil, err
}
for _, app := range output.AppsLists {
d.StreamListItem(ctx, app)
// 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, nil
}
//// HYDRATE FUNCTIONS
func getFmsAppList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
listId := ""
if h.Item != nil {
data := h.Item.(types.AppsListDataSummary)
listId = *data.ListId
} else {
listId = d.EqualsQualString("list_id")
}
if listId == "" {
return nil, nil
}
// Create service
svc, err := FMSClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_fms_app_list.getFmsAppList", "connection_error", err)
return nil, err
}
if svc == nil {
// Unsupported region, return no data
return nil, nil
}
params := &fms.GetAppsListInput{
ListId: &listId,
}
op, err := svc.GetAppsList(ctx, params)
if err != nil {
plugin.Logger(ctx).Error("aws_fms_app_list.getFmsAppList", "api_error", err)
return nil, err
}
if op != nil {
return op, nil
}
return nil, nil
}