/
table_azure_search_service.go
276 lines (250 loc) · 9.52 KB
/
table_azure_search_service.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
package azure
import (
"context"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-08-01/search"
"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 tableAzureSearchService(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_search_service",
Description: "Azure Search Service",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getSearchService,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "404"}),
},
},
List: &plugin.ListConfig{
Hydrate: listSearchServices,
},
Columns: azureColumns([]*plugin.Column{
{
Name: "name",
Type: proto.ColumnType_STRING,
Description: "The name of the resource.",
},
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "Fully qualified resource ID for the resource.",
Transform: transform.FromGo(),
},
{
Name: "provisioning_state",
Type: proto.ColumnType_STRING,
Description: "The state of the last provisioning operation performed on the search service.",
Transform: transform.FromField("ServiceProperties.ProvisioningState"),
},
{
Name: "status",
Type: proto.ColumnType_STRING,
Description: "The status of the search service. Possible values include: 'running', deleting', 'provisioning', 'degraded', 'disabled', 'error' etc.",
Transform: transform.FromField("ServiceProperties.Status"),
},
{
Name: "status_details",
Type: proto.ColumnType_STRING,
Description: "The details of the search service status.",
Transform: transform.FromField("ServiceProperties.StatusDetails"),
},
{
Name: "type",
Type: proto.ColumnType_STRING,
Description: "The type of the resource.",
},
{
Name: "hosting_mode",
Type: proto.ColumnType_STRING,
Description: "Applicable only for the standard3 SKU. You can set this property to enable up to 3 high density partitions that allow up to 1000 indexes, which is much higher than the maximum indexes allowed for any other SKU. For the standard3 SKU, the value is either 'default' or 'highDensity'. For all other SKUs, this value must be 'default'. Possible values include: 'Default', 'HighDensity'.",
Transform: transform.FromField("ServiceProperties.HostingMode"),
},
{
Name: "partition_count",
Type: proto.ColumnType_INT,
Description: "The number of partitions in the search service; if specified, it can be 1, 2, 3, 4, 6, or 12. Values greater than 1 are only valid for standard SKUs. For 'standard3' services with hostingMode set to 'highDensity', the allowed values are between 1 and 3.",
Transform: transform.FromField("ServiceProperties.PartitionCount"),
},
{
Name: "public_network_access",
Type: proto.ColumnType_STRING,
Description: "This value can be set to 'enabled' to avoid breaking changes on existing customer resources and templates. If set to 'disabled', traffic over public interface is not allowed, and private endpoint connections would be the exclusive access method. Possible values include: 'Enabled', 'Disabled'.",
Transform: transform.FromField("ServiceProperties.PublicNetworkAccess"),
},
{
Name: "replica_count",
Type: proto.ColumnType_INT,
Description: "The number of replicas in the search service. If specified, it must be a value between 1 and 12 inclusive for standard SKUs or between 1 and 3 inclusive for basic SKU.",
Transform: transform.FromField("ServiceProperties.ReplicaCount"),
},
{
Name: "sku_name",
Type: proto.ColumnType_STRING,
Description: "The SKU of the Search Service, which determines price tier and capacity limits. This property is required when creating a new search service.",
Transform: transform.FromField("Sku.Name"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the search service.",
Type: proto.ColumnType_JSON,
Hydrate: listSearchServiceDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "identity",
Type: proto.ColumnType_JSON,
Description: "The identity of the resource.",
},
{
Name: "network_rule_set",
Type: proto.ColumnType_JSON,
Description: "Network specific rules that determine how the azure cognitive search service may be reached.",
Transform: transform.FromField("ServiceProperties.NetworkRuleSet"),
},
{
Name: "private_endpoint_connections",
Type: proto.ColumnType_JSON,
Description: "The list of private endpoint connections to the azure cognitive search service.",
Transform: transform.FromField("ServiceProperties.PrivateEndpointConnections"),
},
{
Name: "shared_private_link_resources",
Type: proto.ColumnType_JSON,
Description: "The list of shared private link resources managed by the azure cognitive search service.",
Transform: transform.FromField("ServiceProperties.SharedPrivateLinkResources"),
},
// 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).Transform(toLower),
},
}),
}
}
//// LIST FUNCTION
func listSearchServices(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, nil
}
subscriptionID := session.SubscriptionID
searchClient := search.NewServicesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
searchClient.Authorizer = session.Authorizer
result, err := searchClient.ListBySubscription(ctx, nil)
if err != nil {
return nil, err
}
for _, service := range result.Values() {
d.StreamListItem(ctx, service)
// 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 _, service := range result.Values() {
d.StreamListItem(ctx, service)
// 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 getSearchService(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getSearchService")
name := d.EqualsQuals["name"].GetStringValue()
resourceGroup := d.EqualsQuals["resource_group"].GetStringValue()
if name == "" || resourceGroup == "" {
return nil, nil
}
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
searchClient := search.NewServicesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
searchClient.Authorizer = session.Authorizer
op, err := searchClient.Get(ctx, resourceGroup, name, nil)
if err != nil {
return nil, err
}
if op.ID != nil {
return op, nil
}
return nil, nil
}
func listSearchServiceDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listSearchServiceDiagnosticSettings")
id := h.Item.(search.Service).ID
// 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
}