This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
app_workflows.go
332 lines (323 loc) · 12.1 KB
/
app_workflows.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
package logic
import (
"context"
"encoding/json"
"github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2019-05-01/logic"
"github.com/cloudquery/cq-provider-azure/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func LogicAppWorkflows() *schema.Table {
return &schema.Table{
Name: "azure_logic_app_workflows",
Description: "Azure Logic App Workflow",
Resolver: fetchLogicAppWorkflows,
Multiplex: client.SubscriptionMultiplex,
DeleteFilter: client.DeleteSubscriptionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"subscription_id", "id"}},
Columns: []schema.Column{
{
Name: "subscription_id",
Description: "Azure subscription id",
Type: schema.TypeString,
Resolver: client.ResolveAzureSubscription,
},
{
Name: "provisioning_state",
Description: "Gets the provisioning state. Possible values include: 'WorkflowProvisioningStateNotSpecified', 'WorkflowProvisioningStateAccepted', 'WorkflowProvisioningStateRunning', 'WorkflowProvisioningStateReady', 'WorkflowProvisioningStateCreating', 'WorkflowProvisioningStateCreated', 'WorkflowProvisioningStateDeleting', 'WorkflowProvisioningStateDeleted', 'WorkflowProvisioningStateCanceled', 'WorkflowProvisioningStateFailed', 'WorkflowProvisioningStateSucceeded', 'WorkflowProvisioningStateMoving', 'WorkflowProvisioningStateUpdating', 'WorkflowProvisioningStateRegistering', 'WorkflowProvisioningStateRegistered', 'WorkflowProvisioningStateUnregistering', 'WorkflowProvisioningStateUnregistered', 'WorkflowProvisioningStateCompleted', 'WorkflowProvisioningStateRenewing', 'WorkflowProvisioningStatePending', 'WorkflowProvisioningStateWaiting', 'WorkflowProvisioningStateInProgress'",
Type: schema.TypeString,
Resolver: schema.PathResolver("ProvisioningState"),
},
{
Name: "created_time",
Description: "Gets the created time.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("CreatedTime.Time"),
},
{
Name: "changed_time",
Description: "Gets the changed time.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("ChangedTime.Time"),
},
{
Name: "state",
Description: "The state. Possible values include: 'WorkflowStateNotSpecified', 'WorkflowStateCompleted', 'WorkflowStateEnabled', 'WorkflowStateDisabled', 'WorkflowStateDeleted', 'WorkflowStateSuspended'",
Type: schema.TypeString,
Resolver: schema.PathResolver("State"),
},
{
Name: "version",
Description: "Gets the version.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Version"),
},
{
Name: "access_endpoint",
Description: "Gets the access endpoint.",
Type: schema.TypeString,
Resolver: schema.PathResolver("AccessEndpoint"),
},
{
Name: "endpoints_configuration",
Description: "The endpoints configuration.",
Type: schema.TypeJSON,
Resolver: endpointsConfigurationResolver,
},
{
Name: "access_control",
Description: "The access control configuration.",
Type: schema.TypeJSON,
Resolver: accessControlResolver,
IgnoreInTests: true,
},
{
Name: "sku_name",
Description: "The sku name. Possible values include: 'SkuNameNotSpecified', 'SkuNameFree', 'SkuNameShared', 'SkuNameBasic', 'SkuNameStandard', 'SkuNamePremium'",
Type: schema.TypeString,
Resolver: schema.PathResolver("Sku.Name"),
},
{
Name: "sku_plan_id",
Description: "The reference to plan resource id.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Sku.Plan.ID"),
IgnoreInTests: true,
},
{
Name: "sku_plan_name",
Description: "The reference to plan resource name.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Sku.Plan.Name"),
IgnoreInTests: true,
},
{
Name: "sku_plan_type",
Description: "The reference to plan resource type.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Sku.Plan.Type"),
IgnoreInTests: true,
},
{
Name: "integration_account_id",
Description: "The integration account id.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationAccount.ID"),
IgnoreInTests: true,
},
{
Name: "integration_account_name",
Description: "The integration account name.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationAccount.Name"),
IgnoreInTests: true,
},
{
Name: "integration_account_type",
Description: "The integration account type.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationAccount.Type"),
IgnoreInTests: true,
},
{
Name: "integration_service_environment_id",
Description: "The integration service environment id.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationServiceEnvironment.ID"),
IgnoreInTests: true,
},
{
Name: "integration_service_environment_name",
Description: "The integration service environment name.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationServiceEnvironment.Name"),
IgnoreInTests: true,
},
{
Name: "integration_service_environment_type",
Description: "The integration service environment type.",
Type: schema.TypeString,
Resolver: schema.PathResolver("IntegrationServiceEnvironment.Type"),
IgnoreInTests: true,
},
{
Name: "definition",
Description: "The definition.",
Type: schema.TypeJSON,
Resolver: definitionResolver,
},
{
Name: "parameters",
Description: "The parameters.",
Type: schema.TypeJSON,
Resolver: parametersResolver,
},
{
Name: "identity_type",
Description: "Type of managed service identity. The type 'SystemAssigned' includes an implicitly created identity. The type 'None' will remove any identities from the resource. Possible values include: 'ManagedServiceIdentityTypeSystemAssigned', 'ManagedServiceIdentityTypeUserAssigned', 'ManagedServiceIdentityTypeNone'",
Type: schema.TypeString,
Resolver: schema.PathResolver("Identity.Type"),
},
{
Name: "identity_tenant_id",
Description: "Tenant of managed service identity.",
Type: schema.TypeUUID,
Resolver: schema.PathResolver("Identity.TenantID"),
IgnoreInTests: true,
},
{
Name: "identity_principal_id",
Description: "Principal Id of managed service identity.",
Type: schema.TypeUUID,
Resolver: schema.PathResolver("Identity.PrincipalID"),
IgnoreInTests: true,
},
{
Name: "identity_user_assigned_identities",
Description: "The list of user assigned identities associated with the resource. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}",
Type: schema.TypeJSON,
Resolver: identityUserAssignedIdentitiesResolver,
IgnoreInTests: true,
},
{
Name: "id",
Description: "Fully qualified resource ID for the resource",
Type: schema.TypeString,
Resolver: schema.PathResolver("ID"),
},
{
Name: "name",
Description: "The name of the resource.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Name"),
},
{
Name: "type",
Description: "The type of the resource.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Type"),
},
{
Name: "location",
Description: "The geo-location where the resource lives",
Type: schema.TypeString,
Resolver: schema.PathResolver("Location"),
},
{
Name: "tags",
Description: "Resource tags.",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Tags"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the workflow.",
Type: schema.TypeJSON,
Resolver: fetchDiagnosticSettingsResolver,
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchLogicAppWorkflows(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
svc := meta.(*client.Client).Services().Logic.Workflows
var top int32 = 100
response, err := svc.ListBySubscription(ctx, &top, "")
if err != nil {
return diag.WrapError(err)
}
for response.NotDone() {
res <- response.Values()
if err = response.NextWithContext(ctx); err != nil {
return diag.WrapError(err)
}
}
return nil
}
func endpointsConfigurationResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
workflow := resource.Item.(logic.Workflow)
if workflow.EndpointsConfiguration == nil {
return nil
}
b, err := json.Marshal(*workflow.EndpointsConfiguration)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}
func accessControlResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
workflow := resource.Item.(logic.Workflow)
if workflow.AccessControl == nil {
return nil
}
b, err := json.Marshal(*workflow.AccessControl)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}
func definitionResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
definition := resource.Item.(logic.Workflow).Definition
if definition == nil {
definition = make(map[string]interface{})
}
b, err := json.Marshal(definition)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}
func parametersResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
workflow := resource.Item.(logic.Workflow)
if workflow.Parameters == nil {
return nil
}
b, err := json.Marshal(workflow.Parameters)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}
func identityUserAssignedIdentitiesResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
workflow := resource.Item.(logic.Workflow)
if workflow.Identity == nil || workflow.Identity.UserAssignedIdentities == nil {
return nil
}
b, err := json.Marshal(workflow.Identity.UserAssignedIdentities)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}
func fetchDiagnosticSettingsResolver(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
id := *resource.Item.(logic.Workflow).ID
svc := meta.(*client.Client).Services().Logic.DiagnosticSettings
response, err := svc.List(ctx, id)
if err != nil {
return diag.WrapError(err)
}
diagnosticSettings := []map[string]interface{}{}
for _, v := range *response.Value {
diagnosticSetting := make(map[string]interface{})
if v.ID != nil {
diagnosticSetting["id"] = v.ID
}
if v.Name != nil {
diagnosticSetting["name"] = v.Name
}
if v.Type != nil {
diagnosticSetting["type"] = v.Type
}
if v.DiagnosticSettings != nil {
diagnosticSetting["properties"] = v.DiagnosticSettings
}
diagnosticSettings = append(diagnosticSettings, diagnosticSetting)
}
b, err := json.Marshal(diagnosticSettings)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, b))
}