Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the way to initialize AzureClients with provided TokenCredential #15

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading