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

Added column firewall_rule in the table azure_postgresql_flexible_server Closes #851 #852

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
42 changes: 42 additions & 0 deletions azure/table_azure_postgresql_flexible_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ func tableAzurePostgreSqlFlexibleServer(_ context.Context) *plugin.Table {
Hydrate: listPostgreSQLFlexibleServersConfigurations,
Transform: transform.FromValue(),
},
{
Name: "firewall_rules",
Description: "The list of firewall rules in a server.",
Type: proto.ColumnType_JSON,
Hydrate: listPostgreSQLFlexibleServerFirewallRules,
Transform: transform.FromValue(),
},

// Steampipe standard columns
{
Expand Down Expand Up @@ -338,6 +345,41 @@ func listPostgreSQLFlexibleServersConfigurations(ctx context.Context, d *plugin.
return postgreSQLFlexibleServersConfigurations, nil
}

func listPostgreSQLFlexibleServerFirewallRules(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {

server := h.Item.(armmypostgresflexibleservers.Server)
resourceGroup := strings.Split(string(*server.ID), "/")[4]
serverName := *server.Name

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

client, err := armmypostgresflexibleservers.NewFirewallRulesClient(subscriptionID, session.Cred, session.ClientOptions)
if err != nil {
plugin.Logger(ctx).Error("azure_postgresql_flexible_server.listPostgreSQLFlexibleServerFirewallRules", "client_error", err)
return nil, err
}

var postgreSQLFlexibleServerFirewallRules []*armmypostgresflexibleservers.FirewallRule

input := &armmypostgresflexibleservers.FirewallRulesClientListByServerOptions{}
pager := client.NewListByServerPager(resourceGroup, serverName, input)

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("azure_postgresql_flexible_server.listPostgreSQLFlexibleServerFirewallRules", "api_error", err)
return nil, err
}
postgreSQLFlexibleServerFirewallRules = append(postgreSQLFlexibleServerFirewallRules, page.Value...)
}

return postgreSQLFlexibleServerFirewallRules, nil
}

//// TRANSFORM FUNCTION

// If we return the API response directly, the output will not provide the properties of Configurations
Expand Down
Loading