Skip to content

Commit

Permalink
Extract properties of apps column in table azure_app_service_plan closes
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI authored Nov 7, 2022
1 parent 71e221f commit 84b19e2
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions azure/table_azure_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,22 @@ func getAppServicePlan(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra
return op, nil
}

type AppServicePlanApp struct {
SiteProperties *web.SiteProperties
ID *string
Name *string
Kind *string
Location *string
Type *string
Tags map[string]*string
}

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
var apps []AppServicePlanApp

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
Expand All @@ -275,18 +285,57 @@ func getServicePlanApps(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr
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
}
app := &AppServicePlanApp{}
for _, data := range op.Values() {
if data.SiteProperties != nil {
app.SiteProperties = data.SiteProperties
}
if data.Name != nil {
app.Name = data.Name
}
if data.ID != nil {
app.ID = data.ID
}
if data.Kind != nil {
app.Kind = data.Kind
}
if data.Type != nil {
app.Type = data.Type
}
app.Tags = data.Tags
apps = append(apps, *app)
}

apps = append(apps, op.Values()...)
for op.NotDone() {
err = op.NextWithContext(ctx)
if err != nil {
return nil, err
}
apps = append(apps, op.Values()...)
for _, data := range op.Values() {
if data.SiteProperties != nil {
app.SiteProperties = data.SiteProperties
}
if data.Name != nil {
app.Name = data.Name
}
if data.ID != nil {
app.ID = data.ID
}
if data.Kind != nil {
app.Kind = data.Kind
}
if data.Type != nil {
app.Type = data.Type
}
app.Tags = data.Tags
apps = append(apps, *app)
}
}

return apps, nil
}

0 comments on commit 84b19e2

Please sign in to comment.