Skip to content

Commit

Permalink
Add way to initialize AzureClients with provided TokenCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
8naama authored Jun 4, 2024
2 parents f8bc146 + e9f6585 commit 5b1dbc3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5b1dbc3

Please sign in to comment.