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

Fixed missing web_application_firewall_configuration details in table azure_application_gateway Closes #765 #770

Merged
merged 2 commits into from
Jun 10, 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
41 changes: 39 additions & 2 deletions azure/table_azure_application_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package azure

import (
"context"
"reflect"
"strings"

"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/profiles/latest/network/mgmt/network"
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"

Expand Down Expand Up @@ -241,11 +243,16 @@ func tableAzureApplicationGateway(_ context.Context) *plugin.Table {
Type: proto.ColumnType_JSON,
Transform: transform.From(extractGatewayURLPathMaps),
},
// The list/get API response contains a property called WebApplicationFirewallConfiguration.
// However, in all cases, we are receiving a null value for this property.
// The CLI command exhibits the same behavior as the API.
// Therefore, we have added a hydrate function to retrieve these details.
{
Name: "web_application_firewall_configuration",
Description: "Web application firewall configuration of the application gateway.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ApplicationGatewayPropertiesFormat.WebApplicationFirewallConfiguration"),
Hydrate: getWebApplicationFirewallConfiguration,
Transform: transform.FromValue(),
},
{
Name: "zones",
Expand Down Expand Up @@ -405,6 +412,36 @@ func listApplicationGatewayDiagnosticSettings(ctx context.Context, d *plugin.Que
return diagnosticSettings, nil
}

func getWebApplicationFirewallConfiguration(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
firewallPolicy := h.Item.(network.ApplicationGateway).FirewallPolicy

// Check for any WAF policy association
if firewallPolicy == nil {
return nil, nil
}
policyId := firewallPolicy.ID
resourceGroup := strings.Split(*policyId, "/")[4]
policyname := strings.Split(*policyId, "/")[len(strings.Split(*policyId, "/"))-1]

// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

client := network.NewWebApplicationFirewallPoliciesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.Get(ctx, resourceGroup, policyname)
if err != nil {
plugin.Logger(ctx).Error("azure_application_gateway.getWebApplicationFirewallConfiguration", "api_error", err)
return nil, err
}

return structToMap(reflect.ValueOf(*op.WebApplicationFirewallPolicyPropertiesFormat)), nil
}

//// TRANSFORM FUNCTIONS

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