/
table_azure_app_service_web_app_slot.go
487 lines (454 loc) · 17.4 KB
/
table_azure_app_service_web_app_slot.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
package azure
import (
"context"
"strings"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2020-06-01/web"
"github.com/turbot/go-kit/types"
"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 tableAzureAppServiceWebAppSlot(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_app_service_web_app_slot",
Description: "Azure App Service Web App Slot",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "app_name", "resource_group"}),
Hydrate: getAppServiceWebAppSlot,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound"}),
},
},
List: &plugin.ListConfig{
ParentHydrate: listAppServiceWebApps,
Hydrate: listAppServiceWebAppSlots,
KeyColumns: []*plugin.KeyColumn{
{
Name: "app_name",
Require: plugin.Optional,
},
},
},
Columns: azureColumns([]*plugin.Column{
{
Name: "name",
Description: "Resource Name.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name").Transform(lastPathElement),
},
{
Name: "app_name",
Description: "The name of the application.",
Type: proto.ColumnType_STRING,
},
{
Name: "id",
Description: "Resource ID of the app slot.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "kind",
Description: "Contains the kind of the resource.",
Type: proto.ColumnType_STRING,
},
{
Name: "state",
Description: "Current state of the app.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.State"),
},
{
Name: "type",
Description: "Resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "last_modified_time_utc",
Description: "Last time the app was modified, in UTC.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("SiteProperties.LastModifiedTimeUtc.TIme"),
},
{
Name: "repository_site_name",
Description: "Name of the repository site.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.RepositorySiteName"),
},
{
Name: "usage_state",
Description: "State indicating whether the app has exceeded its quota usage. Read-only. Possible values include: 'UsageStateNormal', 'UsageStateExceeded'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.UsageState"),
},
{
Name: "enabled",
Description: "Indicates wheather the app is enabled.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.Enabled"),
},
{
Name: "availability_state",
Description: "Management information availability state for the app. Possible values include: 'Normal', 'Limited', 'DisasterRecoveryMode'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.AvailabilityState"),
},
{
Name: "server_farm_id",
Description: "Resource ID of the associated App Service plan, formatted as: '/subscriptions/{subscriptionID}/resourceGroups/{groupName}/providers/Microsoft.Web/serverfarms/{appServicePlanName}'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.ServerFarmID"),
},
{
Name: "reserved",
Description: "True if reserved; otherwise, false.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.Reserved"),
},
{
Name: "is_xenon",
Description: "Obsolete: Hyper-V sandbox.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.IsXenon"),
},
{
Name: "hyper_v",
Description: "Hyper-V sandbox.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.HyperV"),
},
{
Name: "scm_site_also_stopped",
Description: "True to stop SCM (KUDU) site when the app is stopped; otherwise, false. The default is false.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.ScmSiteAlsoStopped"),
},
{
Name: "target_swap_slot",
Description: "Specifies which deployment slot this app will swap into.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.TargetSwapSlot"),
},
{
Name: "client_affinity_enabled",
Description: "True to enable client affinity; false to stop sending session affinity cookies, which route client requests in the same session to the same instance. Default is true.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.ClientAffinityEnabled"),
},
{
Name: "client_cert_mode",
Description: "This composes with ClientCertEnabled setting. ClientCertEnabled: false means ClientCert is ignored. ClientCertEnabled: true and ClientCertMode: Required means ClientCert is required.ClientCertEnabled: true and ClientCertMode: Optional means ClientCert is optional or accepted. Possible values include: 'Required', 'Optional'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.ClientCertMode"),
},
{
Name: "client_cert_exclusion_paths",
Description: "Client certificate authentication comma-separated exclusion paths.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.ClientCertExclusionPaths"),
},
{
Name: "host_names_disabled",
Description: "True to disable the public hostnames of the app; otherwise, false. If true, the app is only accessible via API management process.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.HostNamesDisabled"),
},
{
Name: "custom_domain_verification_id",
Description: "Unique identifier that verifies the custom domains assigned to the app. The customer will add this ID to a text record for verification.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.CustomDomainVerificationID"),
},
{
Name: "outbound_ip_addresses",
Description: "List of IP addresses that the app uses for outbound connections (e.g. database access). Includes VIPs from tenants that site can be hosted with current settings.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.OutboundIPAddresses"),
},
{
Name: "possible_outbound_ip_addresses",
Description: "List of IP addresses that the app uses for outbound connections (e.g. database access). Includes VIPs from all tenants except dataComponent.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.PossibleOutboundIPAddresses"),
},
{
Name: "container_size",
Description: "Size of the function container.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("SiteProperties.ContainerSize"),
},
{
Name: "suspended_till",
Description: "App suspended till in case memory-time quota is exceeded.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("SiteProperties.SuspendedTill.Time"),
},
{
Name: "is_default_container",
Description: "True if the app is a default container; otherwise, false.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.IsDefaultContainer"),
},
{
Name: "default_host_name",
Description: "Default hostname of the app.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.DefaultHostName"),
},
{
Name: "https_only",
Description: "Configures a web site to accept only https requests.",
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("SiteProperties.HTTPSOnly"),
},
{
Name: "redundancy_mode",
Description: "Site redundancy mode. Possible values include: 'RedundancyModeNone', 'RedundancyModeManual', 'RedundancyModeFailover', 'RedundancyModeActiveActive', 'RedundancyModeGeoRedundant'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("SiteProperties.RedundancyMode"),
},
// JSON fields
{
Name: "identity",
Description: "Managed service identity.",
Type: proto.ColumnType_JSON,
Transform: transform.From(slotIdentity),
},
{
Name: "host_names",
Description: "Hostnames associated with the app.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.HostNames"),
},
{
Name: "enabled_host_names",
Description: "Enabled hostnames for the app. Hostnames need to be assigned (see HostNames) AND enabled. Otherwise, the app is not served on those hostnames.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.EnabledHostNames"),
},
{
Name: "host_name_ssl_states",
Description: "Hostname SSL states are used to manage the SSL bindings for app's hostnames.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.HostNameSslStates"),
},
{
Name: "site_config",
Description: "Configuration of the app.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.SiteConfig"),
},
{
Name: "traffic_manager_host_names",
Description: "Azure Traffic Manager hostnames associated with the app.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.TrafficManagerHostNames"),
},
{
Name: "hosting_environment_profile",
Description: "App Service Environment to use for the app.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.HostingEnvironmentProfile"),
},
{
Name: "slot_swap_status",
Description: "Status of the last deployment slot swap operation.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("SiteProperties.SlotSwapStatus"),
},
{
Name: "site_config_resource",
Description: "Configuration of an app, such as platform version and bitness, default documents, virtual applications, Always On, etc.",
Type: proto.ColumnType_JSON,
Hydrate: getConfigurationSlot,
Transform: transform.FromValue(),
},
// 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("SiteProperties.ResourceGroup").Transform(toLower),
},
}),
}
}
type SlotInfo struct {
SiteProperties *web.SiteProperties
Identity *web.ManagedServiceIdentity
ID *string
Name *string
AppName *string
Kind *string
Location *string
Type *string
Tags map[string]*string
}
//// LIST FUNCTION
func listAppServiceWebAppSlots(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
var appName, resourceGroupName string
if h.Item != nil {
data := h.Item.(web.Site)
appName = *data.Name
resourceGroupName = *data.ResourceGroup
} else {
return nil, nil
}
// Restrict the API call for other apps if the app name is specified in the query paramater
if d.EqualsQualString("app_name") != "" && d.EqualsQualString("app_name") != appName {
return nil, nil
}
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.listAppServiceWebAppSlots", "session_error", err)
return nil, err
}
subscriptionID := session.SubscriptionID
webClient := web.NewAppsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
webClient.Authorizer = session.Authorizer
result, err := webClient.ListSlots(ctx, resourceGroupName, appName)
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.listAppServiceWebAppSlots", "api_error", err)
return nil, err
}
for _, slot := range result.Values() {
d.StreamListItem(ctx, &SlotInfo{
SiteProperties: slot.SiteProperties,
Identity: slot.Identity,
ID: slot.ID,
Name: slot.Name,
AppName: &appName,
Kind: slot.Kind,
Location: slot.Location,
Type: slot.Type,
Tags: slot.Tags,
})
// 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 {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.listAppServiceWebAppSlots", "api_pagging_error", err)
return nil, err
}
for _, slot := range result.Values() {
d.StreamListItem(ctx, slot)
// 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, nil
}
//// HYDRATE FUNCTIONS
func getAppServiceWebAppSlot(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
appName := d.EqualsQuals["app_name"].GetStringValue()
resourceGroup := d.EqualsQuals["resource_group"].GetStringValue()
slotName := d.EqualsQuals["name"].GetStringValue()
// Error: pq: rpc error: code = Unknown desc = web.AppsClient#GetSlot: Invalid input: autorest/validation: validation failed: parameter=resourceGroupName
// constraint=MinLength value="" details: value length must be greater than or equal to 1
if len(resourceGroup) < 1 || len(appName) < 1 || len(slotName) < 1 {
return nil, nil
}
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.getAppServiceWebAppSlot", "session_error", err)
return nil, err
}
subscriptionID := session.SubscriptionID
webClient := web.NewAppsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
webClient.Authorizer = session.Authorizer
op, err := webClient.GetSlot(ctx, resourceGroup, appName, slotName)
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.getAppServiceWebAppSlot", "api_error", err)
return nil, err
}
// In some cases resource does not give any notFound error
// instead of notFound error, it returns empty data
if op.ID != nil {
return &SlotInfo{
SiteProperties: op.SiteProperties,
Identity: op.Identity,
ID: op.ID,
Name: op.Name,
AppName: &appName,
Kind: op.Kind,
Location: op.Location,
Type: op.Type,
Tags: op.Tags,
}, nil
}
return nil, nil
}
func getConfigurationSlot(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Debug("getConfigurationSlot")
data := h.Item.(*SlotInfo)
appName := *data.AppName
slotName := *data.Name
resourceGroupName := *data.SiteProperties.ResourceGroup
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.getConfigurationSlot", "session_error", err)
return nil, err
}
subscriptionID := session.SubscriptionID
webClient := web.NewAppsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
webClient.Authorizer = session.Authorizer
op, err := webClient.GetConfigurationSlot(ctx, resourceGroupName, appName, strings.Split(slotName, "/")[1])
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_web_app_slot.getConfigurationSlot", "api_error", err)
return nil, err
}
return *op.SiteConfig, nil
}
//// TRANSFORM FUNCTION
func slotIdentity(ctx context.Context, d *transform.TransformData) (interface{}, error) {
data := d.HydrateItem.(*SlotInfo)
objectMap := make(map[string]interface{})
if data.Identity != nil {
if types.SafeString(data.Identity.Type) != "" {
objectMap["Type"] = data.Identity.Type
}
if data.Identity.TenantID != nil {
objectMap["TenantID"] = data.Identity.TenantID
}
if data.Identity.PrincipalID != nil {
objectMap["PrincipalID"] = data.Identity.PrincipalID
}
if data.Identity.UserAssignedIdentities != nil {
objectMap["UserAssignedIdentities"] = data.Identity.UserAssignedIdentities
}
}
return objectMap, nil
}