/
table_azure_data_lake_store.go
349 lines (322 loc) · 11.7 KB
/
table_azure_data_lake_store.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package azure
import (
"context"
"strings"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)
//// TABLE DEFINITION
func tableAzureDataLakeStore(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_data_lake_store",
Description: "Azure Data Lake Store",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getDataLakeStore,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "400"}),
},
},
List: &plugin.ListConfig{
Hydrate: listDataLakeStores,
},
Columns: azureColumns([]*plugin.Column{
{
Name: "name",
Description: "The resource name.",
Type: proto.ColumnType_STRING,
},
{
Name: "id",
Description: "The resource identifier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "type",
Description: "The resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "account_id",
Description: "The unique identifier associated with this data lake store account.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.AccountID", "DataLakeStoreAccountProperties.AccountID"),
},
{
Name: "creation_time",
Description: "The account creation time.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.CreationTime", "DataLakeStoreAccountProperties.CreationTime").Transform(convertDateToTime),
},
{
Name: "current_tier",
Description: "The commitment tier in use for current month.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.CurrentTier"),
},
{
Name: "default_group",
Description: "The default owner group for all new folders and files created in the data lake store account.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.DefaultGroup"),
},
{
Name: "encryption_state",
Description: "The current state of encryption for this data lake store account.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.EncryptionState"),
},
{
Name: "encryption_provisioning_state",
Description: "The current state of encryption provisioning for this data lake store account.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.EncryptionProvisioningState"),
},
{
Name: "endpoint",
Description: "The full cname endpoint for this account.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.Endpoint", "DataLakeStoreAccountProperties.Endpoint"),
},
{
Name: "firewall_state",
Description: "The current state of the IP address firewall for this data lake store account.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.FirewallState"),
},
{
Name: "last_modified_time",
Description: "The account last modified time.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.LastModifiedTime", "DataLakeStoreAccountProperties.LastModifiedTime").Transform(convertDateToTime),
},
{
Name: "new_tier",
Description: "The commitment tier to use for next month.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.NewTier"),
},
{
Name: "provisioning_state",
Description: "The provisioning status of the data lake store account.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.ProvisioningState", "DataLakeStoreAccountProperties.ProvisioningState"),
},
{
Name: "state",
Description: "The state of the data lake store account.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DataLakeStoreAccountPropertiesBasic.State", "DataLakeStoreAccountProperties.State"),
},
{
Name: "trusted_id_provider_state",
Description: "The current state of the trusted identity provider feature for this data lake store account.",
Type: proto.ColumnType_STRING,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.TrustedIDProviderState"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the data lake store.",
Type: proto.ColumnType_JSON,
Hydrate: listDataLakeStoreDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "encryption_config",
Description: "The key vault encryption configuration.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.EncryptionConfig"),
},
{
Name: "firewall_allow_azure_ips",
Description: "The current state of allowing or disallowing IPs originating within azure through the firewall. If the firewall is disabled, this is not enforced.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.FirewallAllowAzureIps"),
},
{
Name: "firewall_rules",
Description: "The list of firewall rules associated with this data lake store account.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.FirewallRules"),
},
{
Name: "identity",
Description: "The key vault encryption identity, if any.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
},
{
Name: "trusted_id_providers",
Description: "The list of trusted identity providers associated with this data lake store account.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.TrustedIDProviders"),
},
{
Name: "virtual_network_rules",
Description: "The list of virtual network rules associated with this data lake store account.",
Type: proto.ColumnType_JSON,
Hydrate: getDataLakeStore,
Transform: transform.FromField("DataLakeStoreAccountProperties.VirtualNetworkRules"),
},
// Steampipe standard columns
{
Name: "title",
Description: ColumnDescriptionTitle,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "tags",
Description: ColumnDescriptionTags,
Type: proto.ColumnType_JSON,
},
{
Name: "akas",
Description: ColumnDescriptionAkas,
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ID").Transform(idToAkas),
},
// Azure standard columns
{
Name: "region",
Description: ColumnDescriptionRegion,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(toLower),
},
{
Name: "resource_group",
Description: ColumnDescriptionResourceGroup,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(extractResourceGroupFromID),
},
}),
}
}
//// LIST FUNCTION
func listDataLakeStores(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
accountClient := account.NewAccountsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
accountClient.Authorizer = session.Authorizer
result, err := accountClient.List(ctx, "", nil, nil, "", "", nil)
if err != nil {
return nil, err
}
for _, account := range result.Values() {
d.StreamListItem(ctx, account)
// Check if context has been cancelled or if the limit has been hit (if specified)
// if there is a limit, it will return the number of rows required to reach this limit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
for result.NotDone() {
err = result.NextWithContext(ctx)
if err != nil {
return nil, err
}
for _, account := range result.Values() {
d.StreamListItem(ctx, account)
// Check if context has been cancelled or if the limit has been hit (if specified)
// if there is a limit, it will return the number of rows required to reach this limit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, err
}
//// HYDRATE FUNCTIONS
func getDataLakeStore(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getDataLakeStore")
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
accountClient := account.NewAccountsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
accountClient.Authorizer = session.Authorizer
var name, resourceGroup string
if h.Item != nil {
data := h.Item.(account.DataLakeStoreAccountBasic)
splitID := strings.Split(*data.ID, "/")
name = *data.Name
resourceGroup = splitID[4]
} else {
name = d.EqualsQuals["name"].GetStringValue()
resourceGroup = d.EqualsQuals["resource_group"].GetStringValue()
}
// Return nil, if no input provide
if name == "" || resourceGroup == "" {
return nil, nil
}
op, err := accountClient.Get(ctx, resourceGroup, name)
if err != nil {
return nil, err
}
return op, nil
}
func listDataLakeStoreDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listDataLakeStoreDiagnosticSettings")
id := getLakeStoreID(h.Item)
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
client := insights.NewDiagnosticSettingsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer
op, err := client.List(ctx, id)
if err != nil {
return nil, err
}
// If we return the API response directly, the output only gives
// the contents of DiagnosticSettings
var diagnosticSettings []map[string]interface{}
for _, i := range *op.Value {
objectMap := make(map[string]interface{})
if i.ID != nil {
objectMap["id"] = i.ID
}
if i.Name != nil {
objectMap["name"] = i.Name
}
if i.Type != nil {
objectMap["type"] = i.Type
}
if i.DiagnosticSettings != nil {
objectMap["properties"] = i.DiagnosticSettings
}
diagnosticSettings = append(diagnosticSettings, objectMap)
}
return diagnosticSettings, nil
}
func getLakeStoreID(item interface{}) string {
switch item := item.(type) {
case account.DataLakeStoreAccountBasic:
return *item.ID
case account.DataLakeStoreAccount:
return *item.ID
}
return ""
}