diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index 8f4a83e3..6287e77d 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -146,6 +146,13 @@ func tableAzureEventHubNamespace(_ context.Context) *plugin.Table { Hydrate: getNetworkRuleSet, Transform: transform.FromValue(), }, + { + Name: "private_endpoint_connections", + Description: "The private endpoint connections of the namespace.", + Type: proto.ColumnType_JSON, + Hydrate: listEventHubNamespacePrivateEndpointConnections, + Transform: transform.FromValue(), + }, // Steampipe standard columns { @@ -320,3 +327,72 @@ func listEventHubNamespaceDiagnosticSettings(ctx context.Context, d *plugin.Quer } return diagnosticSettings, nil } + +func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + plugin.Logger(ctx).Trace("listEventHubNamespacePrivateEndpointConnections") + + namespace := h.Item.(eventhub.EHNamespace) + 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 := eventhub.NewPrivateEndpointConnectionsClient(subscriptionID) + client.Authorizer = session.Authorizer + + op, err := client.List(ctx, resourceGroup, namespaceName) + if err != nil { + plugin.Logger(ctx).Error("listEventHubNamespacePrivateEndpointConnections", "list", err) + return nil, err + } + + var eventHubNamespacePrivateEndpointConnections []map[string]interface{} + + for _, i := range op.Values() { + eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, extractEventHubNamespacePrivateEndpointConnections(i)) + } + + for op.NotDone() { + err = op.NextWithContext(ctx) + if err != nil { + plugin.Logger(ctx).Error("listEventHubNamespacePrivateEndpointConnections", "list_paging", err) + return nil, err + } + for _, i := range op.Values() { + eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, extractEventHubNamespacePrivateEndpointConnections(i)) + } + } + + return eventHubNamespacePrivateEndpointConnections, nil +} + +// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections + +func extractEventHubNamespacePrivateEndpointConnections(i eventhub.PrivateEndpointConnection) map[string]interface{} { + eventHubNamespacePrivateEndpointConnection := make(map[string]interface{}) + if i.ID != nil { + eventHubNamespacePrivateEndpointConnection["id"] = *i.ID + } + if i.Name != nil { + eventHubNamespacePrivateEndpointConnection["name"] = *i.Name + } + if i.Type != nil { + eventHubNamespacePrivateEndpointConnection["type"] = *i.Type + } + if i.PrivateEndpointConnectionProperties != nil { + if len(i.PrivateEndpointConnectionProperties.ProvisioningState) > 0 { + eventHubNamespacePrivateEndpointConnection["provisioningState"] = i.PrivateEndpointConnectionProperties.ProvisioningState + } + if i.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState != nil { + eventHubNamespacePrivateEndpointConnection["privateLinkServiceConnectionState"] = i.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState + } + if i.PrivateEndpointConnectionProperties.PrivateEndpoint != nil && i.PrivateEndpointConnectionProperties.PrivateEndpoint.ID != nil { + eventHubNamespacePrivateEndpointConnection["privateEndpointPropertyID"] = i.PrivateEndpointConnectionProperties.PrivateEndpoint.ID + } + } + return eventHubNamespacePrivateEndpointConnection +} diff --git a/docs/tables/azure_eventhub_namespace.md b/docs/tables/azure_eventhub_namespace.md index b7a4806c..19eec8ad 100644 --- a/docs/tables/azure_eventhub_namespace.md +++ b/docs/tables/azure_eventhub_namespace.md @@ -58,3 +58,20 @@ from where not is_auto_inflate_enabled; ``` + +### 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_eventhub_namespace, + jsonb_array_elements(private_endpoint_connections) as connections; +```