From e9f658551b159ebc9f7e33daa8b1dcb96b9700eb Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 21 May 2024 15:45:57 +0100 Subject: [PATCH] Add the way to initialize AzureClients with provided TokenCredential --- initializer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/initializer.go b/initializer.go index 7e79fe0..3ad64fc 100644 --- a/initializer.go +++ b/initializer.go @@ -3,6 +3,7 @@ package azuremonitormetricsreceiver import ( "context" "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "strings" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" @@ -33,12 +34,17 @@ func (w *metricDefWrapper) List(ctx context.Context, resourceID string, options return response, nil } -// CreateAzureClients creates Azure clients. +// CreateAzureClients creates Azure clients with service principal credentials func CreateAzureClients(subscriptionID string, clientID string, clientSecret string, tenantID string) (*AzureClients, error) { credential, err := azidentity.NewClientSecretCredential(tenantID, clientID, clientSecret, nil) if err != nil { return nil, fmt.Errorf("error creating Azure client credential: %w", err) } + return CreateAzureClientsWithCreds(subscriptionID, credential) +} + +// CreateAzureClientsWithCreds creates Azure clients with provided TokenCredential +func CreateAzureClientsWithCreds(subscriptionID string, credential azcore.TokenCredential) (*AzureClients, error) { metricClient, err := armmonitor.NewMetricsClient(subscriptionID, credential, nil) if err != nil { return nil, fmt.Errorf("error creating Azure metric client: %w", err)