Skip to content

Commit

Permalink
Add server keys details in table azure_postgresql_server closes #287
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI committed Sep 7, 2021
1 parent 34f9d17 commit 03fbd56
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions azure/table_azure_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ func tableAzurePostgreSqlServer(_ context.Context) *plugin.Table {
Hydrate: getPostgreSQLServerConfigurations,
Transform: transform.FromValue(),
},
{
Name: "server_keys",
Description: "A list of server keys for a server.",
Type: proto.ColumnType_JSON,
Hydrate: getPostgreSQLServerKeys,
Transform: transform.FromValue(),
},

// Steampipe standard columns
{
Expand Down Expand Up @@ -350,6 +357,32 @@ func getPostgreSQLServerFirewallRules(ctx context.Context, d *plugin.QueryData,
return firewallRules, nil
}

func getPostgreSQLServerKeys(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getPostgreSQLServerKeys")
server := h.Item.(postgresql.Server)

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID
resourceGroupName := strings.Split(string(*server.ID), "/")[4]

client := postgresql.NewServerKeysClient(subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.List(ctx, resourceGroupName, *server.Name)
if err != nil {
return nil, err
}

var serverKeys []postgresql.ServerKey
for _, key := range op.Values() {
serverKeys = append(serverKeys, key)
}
return serverKeys, nil
}

func getPostgreSQLServerAdministrator(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getPostgreSQLServerAdministrator")
server := h.Item.(postgresql.Server)
Expand Down

0 comments on commit 03fbd56

Please sign in to comment.