Skip to content

Commit

Permalink
Add webhook details in table azure_container_registry Closes #708 (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI authored Jan 3, 2024
1 parent c2d560c commit 30b991e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
null
[]
41 changes: 41 additions & 0 deletions azure/table_azure_container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ func tableAzureContainerRegistry(_ context.Context) *plugin.Table {
Hydrate: listContainerRegistryUsages,
Transform: transform.FromValue(),
},
{
Name: "webhooks",
Description: "Webhooks in Azure Container Registry provide a way to trigger custom actions in response to events happening within the registry.",
Type: proto.ColumnType_JSON,
Hydrate: listContainerRegistryWebhooks,
Transform: transform.FromValue(),
},

// Steampipe standard columns
{
Expand Down Expand Up @@ -321,6 +328,40 @@ func listContainerRegistryLoginCredentials(ctx context.Context, d *plugin.QueryD
return op, nil
}

func listContainerRegistryWebhooks(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
client := containerregistry.NewWebhooksClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

data := h.Item.(containerregistry.Registry)
resourceGroup := strings.Split(*data.ID, "/")[4]

op, err := client.List(ctx, resourceGroup, *data.Name)
if err != nil {
plugin.Logger(ctx).Error("azure_container_registry.listContainerRegistryWebhooks", "api_error", err)
return nil, err
}

webhooks := op.Values()

if op.NotDone() {
err = op.NextWithContext(ctx)
if err != nil {
plugin.Logger(ctx).Error("azure_container_registry.listContainerRegistryWebhooks", "api_paging_error", err)
return nil, err
}

webhooks = append(webhooks, op.Values()...)
}

return webhooks, nil
}

func listContainerRegistryUsages(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listContainerRegistryUsages")

Expand Down
27 changes: 27 additions & 0 deletions docs/tables/azure_container_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ from
azure_container_registry;
```

### Get webhook details of registries
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.

```sql+postgres
select
name,
w ->> 'location' as webhook_location,
w -> 'properties' -> 'actions' as actions,
w -> 'properties' ->> 'scope' as scope,
w -> 'properties' ->> 'status' as status
from
azure_container_registry,
jsonb_array_elements(webhooks) as w;
```

```sql+sqlite
select
name,
json_extract(w.value, '$.location') as webhook_location,
json_extract(w.value, '$.properties.actions') as actions,
json_extract(w.value, '$.properties.scope') as scope,
json_extract(w.value, '$.properties.status') as status
from
azure_container_registry,
json_each(webhooks) as w;
```

### List registries not configured with virtual network service endpoint
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.

Expand Down

0 comments on commit 30b991e

Please sign in to comment.