Skip to content

Commit

Permalink
Add private_endpoint_connections column in azure_servicebus_namespace…
Browse files Browse the repository at this point in the history
… table. Closes #295 (#334)
  • Loading branch information
c0d3r-arnab authored Sep 28, 2021
1 parent 191cd37 commit fce5668
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
75 changes: 75 additions & 0 deletions azure/table_azure_servicebus_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func tableAzureServiceBusNamespace(_ context.Context) *plugin.Table {
Hydrate: getServiceBusNamespaceNetworkRuleSet,
Transform: transform.FromValue(),
},
{
Name: "private_endpoint_connections",
Description: "The private endpoint connections of the namespace.",
Type: proto.ColumnType_JSON,
Hydrate: listServiceBusNamespacePrivateEndpointConnections,
Transform: transform.FromValue(),
},

// Steampipe standard columns
{
Expand Down Expand Up @@ -291,3 +298,71 @@ func listServiceBusNamespaceDiagnosticSettings(ctx context.Context, d *plugin.Qu
}
return diagnosticSettings, nil
}

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

namespace := h.Item.(servicebus.SBNamespace)
resourceGroup := strings.Split(string(*namespace.ID), "/")[4]
namespaceName := *namespace.Name

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

client := servicebus.NewPrivateEndpointConnectionsClient(subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.List(ctx, resourceGroup, namespaceName)
if err != nil {
plugin.Logger(ctx).Error("listServiceBusNamespacePrivateEndpointConnections", "list", err)
return nil, err
}

var serviceBusNamespacePrivateEndpointConnections []map[string]interface{}

for _, i := range op.Values() {
serviceBusNamespacePrivateEndpointConnections = append(serviceBusNamespacePrivateEndpointConnections, extractServiceBusNamespacePrivateEndpointConnection(i))
}

for op.NotDone() {
err = op.NextWithContext(ctx)
if err != nil {
plugin.Logger(ctx).Error("listServiceBusNamespacePrivateEndpointConnections", "list_paging", err)
return nil, err
}
for _, i := range op.Values() {
serviceBusNamespacePrivateEndpointConnections = append(serviceBusNamespacePrivateEndpointConnections, extractServiceBusNamespacePrivateEndpointConnection(i))
}
}

return serviceBusNamespacePrivateEndpointConnections, nil
}

// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections
func extractServiceBusNamespacePrivateEndpointConnection(i servicebus.PrivateEndpointConnection) map[string]interface{} {
serviceBusNamespacePrivateEndpointConnection := make(map[string]interface{})
if i.ID != nil {
serviceBusNamespacePrivateEndpointConnection["id"] = *i.ID
}
if i.Name != nil {
serviceBusNamespacePrivateEndpointConnection["name"] = *i.Name
}
if i.Type != nil {
serviceBusNamespacePrivateEndpointConnection["type"] = *i.Type
}
if i.PrivateEndpointConnectionProperties != nil {
if len(i.PrivateEndpointConnectionProperties.ProvisioningState) > 0 {
serviceBusNamespacePrivateEndpointConnection["provisioningState"] = i.PrivateEndpointConnectionProperties.ProvisioningState
}
if i.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState != nil {
serviceBusNamespacePrivateEndpointConnection["privateLinkServiceConnectionState"] = i.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState
}
if i.PrivateEndpointConnectionProperties.PrivateEndpoint != nil && i.PrivateEndpointConnectionProperties.PrivateEndpoint.ID != nil {
serviceBusNamespacePrivateEndpointConnection["privateEndpointPropertyID"] = i.PrivateEndpointConnectionProperties.PrivateEndpoint.ID
}
}
return serviceBusNamespacePrivateEndpointConnection
}
17 changes: 17 additions & 0 deletions docs/tables/azure_servicebus_namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,20 @@ where
)
);
```

### List private endpoint connection details

```sql
select
name,
id,
connections ->> 'id' as connection_id,
connections ->> 'name' as connection_name,
connections ->> 'privateEndpointPropertyID' as property_private_endpoint_id,
connections ->> 'provisioningState' as property_provisioning_state,
jsonb_pretty(connections -> 'privateLinkServiceConnectionState') as property_private_link_service_connection_state,
connections ->> 'type' as connection_type
from
azure_servicebus_namespace,
jsonb_array_elements(private_endpoint_connections) as connections;
```

0 comments on commit fce5668

Please sign in to comment.