From aeee22ed5da7e4d8c516e4b329a1d6e4ec041889 Mon Sep 17 00:00:00 2001 From: Arnab Ghosh Date: Thu, 23 Sep 2021 15:24:41 +0530 Subject: [PATCH 1/5] Add Private Endpoint Connection details in table azure_eventhub_namespace --- azure/table_azure_eventhub_namespace.go | 93 +++++++++++++++++++++++++ docs/tables/azure_eventhub_namespace.md | 17 +++++ 2 files changed, 110 insertions(+) diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index 8f4a83e3..d94ca364 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: "Private endpoint connections to the instance.", + Type: proto.ColumnType_JSON, + Hydrate: listEventHubNamespacePrivateEndpointConnections, + Transform: transform.FromValue(), + }, // Steampipe standard columns { @@ -320,3 +327,89 @@ 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() { + 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 + } + } + + eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, eventHubNamespacePrivateEndpointConnection) + } + + 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() { + 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 + } + } + + eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, eventHubNamespacePrivateEndpointConnection) + } + } + + return eventHubNamespacePrivateEndpointConnections, nil +} 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; +``` From 7d30092b8cb3bbd11f472df7a924ce2ff35c47d4 Mon Sep 17 00:00:00 2001 From: Arnab Ghosh Date: Thu, 23 Sep 2021 17:12:31 +0530 Subject: [PATCH 2/5] fix typo --- azure/table_azure_eventhub_namespace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index d94ca364..8d2356d8 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -148,7 +148,7 @@ func tableAzureEventHubNamespace(_ context.Context) *plugin.Table { }, { Name: "private_endpoint_connections", - Description: "Private endpoint connections to the instance.", + Description: "The private endpoint connections of the namespace.", Type: proto.ColumnType_JSON, Hydrate: listEventHubNamespacePrivateEndpointConnections, Transform: transform.FromValue(), From 8ec0ceafe81fb1e698385c24a3dad4ae99ddf4c9 Mon Sep 17 00:00:00 2001 From: Arnab Ghosh Date: Thu, 23 Sep 2021 18:26:17 +0530 Subject: [PATCH 3/5] add comment --- azure/table_azure_eventhub_namespace.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index 8d2356d8..d0df616a 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -328,6 +328,7 @@ func listEventHubNamespaceDiagnosticSettings(ctx context.Context, d *plugin.Quer return diagnosticSettings, nil } +// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { plugin.Logger(ctx).Trace("listEventHubNamespacePrivateEndpointConnections") From 9a511925d1927a4e500afb3d589e29be97b242d3 Mon Sep 17 00:00:00 2001 From: sourav Date: Tue, 28 Sep 2021 13:44:10 +0530 Subject: [PATCH 4/5] update structute for endpoint connections --- azure/table_azure_eventhub_namespace.go | 77 ++++++++++--------------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index d0df616a..c0e54519 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -328,7 +328,6 @@ func listEventHubNamespaceDiagnosticSettings(ctx context.Context, d *plugin.Quer return diagnosticSettings, nil } -// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { plugin.Logger(ctx).Trace("listEventHubNamespacePrivateEndpointConnections") @@ -354,29 +353,7 @@ func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plu var eventHubNamespacePrivateEndpointConnections []map[string]interface{} for _, i := range op.Values() { - 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 - } - } - - eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, eventHubNamespacePrivateEndpointConnection) + eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, extractEventHubNamespacePrivateEndpointConnections(i)) } for op.NotDone() { @@ -386,31 +363,37 @@ func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plu return nil, err } for _, i := range op.Values() { - 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 - } - } - - eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, eventHubNamespacePrivateEndpointConnection) + + 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 +} From fcbf0a8a9008941ccc00cde77d5255d4fede4ecf Mon Sep 17 00:00:00 2001 From: Arnab Ghosh Date: Tue, 28 Sep 2021 14:48:28 +0530 Subject: [PATCH 5/5] remove white space --- azure/table_azure_eventhub_namespace.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index c0e54519..6287e77d 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -363,7 +363,6 @@ func listEventHubNamespacePrivateEndpointConnections(ctx context.Context, d *plu return nil, err } for _, i := range op.Values() { - eventHubNamespacePrivateEndpointConnections = append(eventHubNamespacePrivateEndpointConnections, extractEventHubNamespacePrivateEndpointConnections(i)) } }