@@ -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
2223func (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-
4441func (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