| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package azure_monitor |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "fmt" |
| 8 | |
| 9 | "github.com/Azure/azure-sdk-for-go/sdk/azcore" |
| 10 | "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" |
| 11 | azcloud "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" |
| 12 | "github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics" |
| 13 | "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph" |
| 14 | ) |
| 15 | |
| 16 | type resourceGraphClient interface { |
| 17 | Resources(ctx context.Context, query armresourcegraph.QueryRequest, options *armresourcegraph.ClientResourcesOptions) (armresourcegraph.ClientResourcesResponse, error) |
| 18 | } |
| 19 | |
| 20 | type metricsQueryClient interface { |
| 21 | QueryResources(ctx context.Context, subscriptionID string, metricNamespace string, metricNames []string, resourceIDs azmetrics.ResourceIDList, options *azmetrics.QueryResourcesOptions) (azmetrics.QueryResourcesResponse, error) |
| 22 | } |
| 23 | |
| 24 | type armClientOptions struct { |
| 25 | Cloud azcloud.Configuration |
| 26 | } |
| 27 | |
| 28 | func (a armClientOptions) toARM() *arm.ClientOptions { |
| 29 | return &arm.ClientOptions{ClientOptions: azcore.ClientOptions{Cloud: a.Cloud}} |
| 30 | } |
| 31 | |
| 32 | func cloudConfigFromName(name string) (azcloud.Configuration, error) { |
| 33 | switch stringsLowerTrim(name) { |
| 34 | case cloudPublic, "": |
| 35 | return azcloud.AzurePublic, nil |
| 36 | case cloudGovernment: |
| 37 | return azcloud.AzureGovernment, nil |
| 38 | case cloudChina: |
| 39 | return azcloud.AzureChina, nil |
| 40 | default: |
| 41 | return azcloud.Configuration{}, fmt.Errorf("unsupported cloud %q", name) |
| 42 | } |
| 43 | } |