Skip to content

Commit 5466259

Browse files
authored
🐛 armresources has not returned properties for cosmo pg service (#5685)
1 parent 9147a61 commit 5466259

4 files changed

Lines changed: 50 additions & 11 deletions

File tree

providers/azure/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ require (
5858
github.com/99designs/keyring v1.2.2 // indirect
5959
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 // indirect
6060
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
61+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql v1.1.0 // indirect
6162
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0 // indirect
6263
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 // indirect
6364
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect

providers/azure/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontai
102102
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 v2.4.0/go.mod h1:U5gpsREQZE6SLk1t/cFfc1eMhYAlYpEzvaYXuDfefy8=
103103
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos v1.0.0 h1:Fv8iibGn1eSw0lt2V3cTsuokBEnOP+M//n8OiMcCgTM=
104104
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos v1.0.0/go.mod h1:Qpe/qN9d5IQ7WPtTXMRCd6+BWTnhi3sxXVys6oJ5Vho=
105+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql v1.1.0 h1:TyXI0pf9V67/vn7Vo2BebOz4B/fLj9Kt3UcrQBXMrvE=
106+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql v1.1.0/go.mod h1:s//ycXE53yRslaDdkNrCEANgvrdSOaUuqcBCJg5VEX0=
105107
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E=
106108
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk=
107109
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do=

providers/azure/resources/azure.lr.go

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/azure/resources/cosmosdb.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
1818
cosmosdb "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos"
1919
armresources "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
20+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql"
2021
)
2122

2223
func (a *mqlAzureSubscriptionCosmosDbService) id() (string, error) {
@@ -37,10 +38,6 @@ func initAzureSubscriptionCosmosDbService(runtime *plugin.Runtime, args map[stri
3738
return args, nil, nil
3839
}
3940

40-
func (a *mqlAzureSubscriptionCosmosDbServiceAccount) id() (string, error) {
41-
return a.Id.Data, nil
42-
}
43-
4441
func (a *mqlAzureSubscriptionCosmosDbService) accounts() ([]interface{}, error) {
4542
conn := a.MqlRuntime.Connection.(*connection.AzureConnection)
4643
ctx := context.Background()
@@ -61,7 +58,7 @@ func (a *mqlAzureSubscriptionCosmosDbService) accounts() ([]interface{}, error)
6158
}
6259
res = append(res, mongoAccounts...)
6360

64-
postgresAccounts, err := fetchDbAccountsByType(ctx, a.MqlRuntime, conn, subId, "Microsoft.DBforPostgreSQL/serverGroupsv2")
61+
postgresAccounts, err := fetchCosmosForPostgres(ctx, a.MqlRuntime, conn, subId)
6562
if err != nil {
6663
return nil, err
6764
}
@@ -93,6 +90,7 @@ func fetchCosmosDBAccounts(ctx context.Context, runtime *plugin.Runtime, conn *c
9390

9491
mqlCosmosDbAccount, err := CreateResource(runtime, "azure.subscription.cosmosDbService.account",
9592
map[string]*llx.RawData{
93+
"__id": llx.StringDataPtr(account.ID),
9694
"id": llx.StringDataPtr(account.ID),
9795
"name": llx.StringDataPtr(account.Name),
9896
"tags": llx.MapData(convert.PtrMapStrToInterface(account.Tags), types.String),
@@ -136,6 +134,7 @@ func fetchDbAccountsByType(ctx context.Context, runtime *plugin.Runtime, conn *c
136134

137135
mqlResource, err := CreateResource(runtime, "azure.subscription.cosmosDbService.account",
138136
map[string]*llx.RawData{
137+
"__id": llx.StringDataPtr(account.ID),
139138
"id": llx.StringDataPtr(account.ID),
140139
"name": llx.StringDataPtr(account.Name),
141140
"tags": llx.MapData(convert.PtrMapStrToInterface(account.Tags), types.String),
@@ -152,3 +151,45 @@ func fetchDbAccountsByType(ctx context.Context, runtime *plugin.Runtime, conn *c
152151
}
153152
return res, nil
154153
}
154+
155+
// fetches resources of type "Microsoft.DBforPostgreSQL/serverGroupsv2"
156+
func fetchCosmosForPostgres(ctx context.Context, runtime *plugin.Runtime, conn *connection.AzureConnection, subId string) ([]interface{}, error) {
157+
resClient, err := armcosmosforpostgresql.NewClustersClient(subId, conn.Token(), &arm.ClientOptions{
158+
ClientOptions: conn.ClientOptions(),
159+
})
160+
if err != nil {
161+
return nil, err
162+
}
163+
164+
res := []interface{}{}
165+
pager := resClient.NewListPager(&armcosmosforpostgresql.ClustersClientListOptions{})
166+
for pager.More() {
167+
page, err := pager.NextPage(ctx)
168+
if err != nil {
169+
return nil, err
170+
}
171+
for _, account := range page.Value {
172+
properties, err := convert.JsonToDict(account.Properties)
173+
if err != nil {
174+
return nil, err
175+
}
176+
177+
mqlResource, err := CreateResource(runtime, "azure.subscription.cosmosDbService.account",
178+
map[string]*llx.RawData{
179+
"__id": llx.StringDataPtr(account.ID),
180+
"id": llx.StringDataPtr(account.ID),
181+
"name": llx.StringDataPtr(account.Name),
182+
"tags": llx.MapData(convert.PtrMapStrToInterface(account.Tags), types.String),
183+
"location": llx.StringDataPtr(account.Location),
184+
"kind": llx.StringDataPtr(nil),
185+
"type": llx.StringDataPtr(account.Type),
186+
"properties": llx.DictData(properties),
187+
})
188+
if err != nil {
189+
return nil, err
190+
}
191+
res = append(res, mqlResource)
192+
}
193+
}
194+
return res, nil
195+
}

0 commit comments

Comments
 (0)