Skip to content

Commit 30b991e

Browse files
authored
Add webhook details in table azure_container_registry Closes #708 (#710)
1 parent c2d560c commit 30b991e

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
null
1+
[]

azure/table_azure_container_registry.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ func tableAzureContainerRegistry(_ context.Context) *plugin.Table {
181181
Hydrate: listContainerRegistryUsages,
182182
Transform: transform.FromValue(),
183183
},
184+
{
185+
Name: "webhooks",
186+
Description: "Webhooks in Azure Container Registry provide a way to trigger custom actions in response to events happening within the registry.",
187+
Type: proto.ColumnType_JSON,
188+
Hydrate: listContainerRegistryWebhooks,
189+
Transform: transform.FromValue(),
190+
},
184191

185192
// Steampipe standard columns
186193
{
@@ -321,6 +328,40 @@ func listContainerRegistryLoginCredentials(ctx context.Context, d *plugin.QueryD
321328
return op, nil
322329
}
323330

331+
func listContainerRegistryWebhooks(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
332+
// Create session
333+
session, err := GetNewSession(ctx, d, "MANAGEMENT")
334+
if err != nil {
335+
return nil, err
336+
}
337+
subscriptionID := session.SubscriptionID
338+
client := containerregistry.NewWebhooksClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
339+
client.Authorizer = session.Authorizer
340+
341+
data := h.Item.(containerregistry.Registry)
342+
resourceGroup := strings.Split(*data.ID, "/")[4]
343+
344+
op, err := client.List(ctx, resourceGroup, *data.Name)
345+
if err != nil {
346+
plugin.Logger(ctx).Error("azure_container_registry.listContainerRegistryWebhooks", "api_error", err)
347+
return nil, err
348+
}
349+
350+
webhooks := op.Values()
351+
352+
if op.NotDone() {
353+
err = op.NextWithContext(ctx)
354+
if err != nil {
355+
plugin.Logger(ctx).Error("azure_container_registry.listContainerRegistryWebhooks", "api_paging_error", err)
356+
return nil, err
357+
}
358+
359+
webhooks = append(webhooks, op.Values()...)
360+
}
361+
362+
return webhooks, nil
363+
}
364+
324365
func listContainerRegistryUsages(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
325366
plugin.Logger(ctx).Trace("listContainerRegistryUsages")
326367

docs/tables/azure_container_registry.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ from
6161
azure_container_registry;
6262
```
6363

64+
### Get webhook details of registries
65+
Webhooks in Azure Container Registry provide a way to trigger custom actions in response to events happening within the registry. These events can include the completion of Docker image pushes, or deletions in the container registry. When such an event occurs, Azure Container Registry sends an HTTP POST payload to the webhook's configured URL.
66+
67+
```sql+postgres
68+
select
69+
name,
70+
w ->> 'location' as webhook_location,
71+
w -> 'properties' -> 'actions' as actions,
72+
w -> 'properties' ->> 'scope' as scope,
73+
w -> 'properties' ->> 'status' as status
74+
from
75+
azure_container_registry,
76+
jsonb_array_elements(webhooks) as w;
77+
```
78+
79+
```sql+sqlite
80+
select
81+
name,
82+
json_extract(w.value, '$.location') as webhook_location,
83+
json_extract(w.value, '$.properties.actions') as actions,
84+
json_extract(w.value, '$.properties.scope') as scope,
85+
json_extract(w.value, '$.properties.status') as status
86+
from
87+
azure_container_registry,
88+
json_each(webhooks) as w;
89+
```
90+
6491
### List registries not configured with virtual network service endpoint
6592
Determine the areas in which registries are not configured with a virtual network service endpoint. This is useful in identifying potential security risks where network access is allowed without restrictions.
6693

0 commit comments

Comments
 (0)