Skip to content

Commit

Permalink
Add columns apps in table azure_app_service_plan closes #535 (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI authored Nov 7, 2022
1 parent 3aa5411 commit 71e221f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions azure/table_azure_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azure

import (
"context"
"strings"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2020-06-01/web"
"github.com/turbot/go-kit/types"
Expand Down Expand Up @@ -138,6 +139,13 @@ func tableAzureAppServicePlan(_ context.Context) *plugin.Table {
Type: proto.ColumnType_STRING,
Transform: transform.FromField("AppServicePlanProperties.Status").Transform(transform.ToString),
},
{
Name: "apps",
Description: "Site a web app, a mobile app backend, or an API app.",
Type: proto.ColumnType_JSON,
Hydrate: getServicePlanApps,
Transform: transform.FromValue(),
},

// Steampipe standard columns
{
Expand Down Expand Up @@ -248,3 +256,37 @@ func getAppServicePlan(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra
}
return op, nil
}

func getServicePlanApps(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
servicePlan := h.Item.(web.AppServicePlan)

resourceGroupName := strings.Split(string(*servicePlan.ID), "/")[4]

var apps []web.Site

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_plan.getServicePlanApps", "session_error", err)
return nil, err
}
subscriptionID := session.SubscriptionID

webClient := web.NewAppServicePlansClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
webClient.Authorizer = session.Authorizer

op, err := webClient.ListWebApps(ctx, resourceGroupName, *servicePlan.Name, "", "", "")
if err != nil {
plugin.Logger(ctx).Error("azure_app_service_plan.getServicePlanApps", "api_error", err)
return nil, err
}

apps = append(apps, op.Values()...)
for op.NotDone() {
err = op.NextWithContext(ctx)
if err != nil {
return nil, err
}
apps = append(apps, op.Values()...)
}
return apps, nil
}

0 comments on commit 71e221f

Please sign in to comment.