Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Private Endpoint Connection details in table azure_servicebus_namespace. Closes #295 #334

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
```