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

Fix private_endpoint_connections column for table azure_postgresql_server. Closes #309 #339

Merged
merged 1 commit 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
39 changes: 38 additions & 1 deletion azure/table_azure_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func tableAzurePostgreSqlServer(_ context.Context) *plugin.Table {
Name: "private_endpoint_connections",
Description: "A list of private endpoint connections on a server.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ServerProperties.PrivateEndpointConnections"),
Transform: transform.From(extractPostgreSqlServerPrivateEndpointConnections),
},
{
Name: "firewall_rules",
Expand Down Expand Up @@ -521,3 +521,40 @@ func postgreSqlServerkeyMap(key postgresql.ServerKey) ServerKeyInfo {

return serverKey
}

// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections
func extractPostgreSqlServerPrivateEndpointConnections(ctx context.Context, d *transform.TransformData) (interface{}, error) {
server := d.HydrateItem.(postgresql.Server)
var properties []map[string]interface{}

if server.ServerProperties.PrivateEndpointConnections != nil {
for _, i := range *server.ServerProperties.PrivateEndpointConnections {
objectMap := make(map[string]interface{})
if i.ID != nil {
objectMap["id"] = i.ID
}
if i.Properties != nil {
if i.Properties.PrivateEndpoint != nil {
objectMap["privateEndpointPropertyId"] = i.Properties.PrivateEndpoint.ID
}
if i.Properties.PrivateLinkServiceConnectionState != nil {
if len(i.Properties.PrivateLinkServiceConnectionState.ActionsRequired) > 0 {
objectMap["privateLinkServiceConnectionStateActionsRequired"] = i.Properties.PrivateLinkServiceConnectionState.ActionsRequired
}
if len(i.Properties.PrivateLinkServiceConnectionState.Status) > 0 {
objectMap["privateLinkServiceConnectionStateStatus"] = i.Properties.PrivateLinkServiceConnectionState.Status
}
if i.Properties.PrivateLinkServiceConnectionState.Description != nil {
objectMap["privateLinkServiceConnectionStateDescription"] = i.Properties.PrivateLinkServiceConnectionState.Description
}
}
if len(i.Properties.ProvisioningState) > 0 {
objectMap["provisioningState"] = i.Properties.ProvisioningState
}
}
properties = append(properties, objectMap)
}
}

return properties, nil
}
17 changes: 17 additions & 0 deletions docs/tables/azure_postgresql_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,20 @@ from
where
geo_redundant_backup = 'Disabled';
```

### List private endpoint connection details

```sql
select
name as server_name,
id as server_id,
connections ->> 'id' as connection_id,
connections ->> 'privateEndpointPropertyId' as connection_private_endpoint_property_id,
connections ->> 'privateLinkServiceConnectionStateActionsRequired' as connection_actions_required,
connections ->> 'privateLinkServiceConnectionStateDescription' as connection_description,
connections ->> 'privateLinkServiceConnectionStateStatus' as connection_status,
connections ->> 'provisioningState' as connection_provisioning_state
from
azure_postgresql_server,
jsonb_array_elements(private_endpoint_connections) as connections;
```