Skip to content

Commit

Permalink
Update sync process to use msgraph client
Browse files Browse the repository at this point in the history
  • Loading branch information
mvbrock committed Dec 20, 2024
1 parent 636f203 commit b2512a9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/srv/discovery/fetchers/azure-sync/azure-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package azure_sync

import (
"context"
"github.com/gravitational/teleport/lib/msgraph"
"sync"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -66,6 +67,7 @@ type Fetcher struct {
lastDiscoveredResources uint64
lastResult *Resources

graphClient *msgraph.Client
roleAssignClient RoleAssignmentsClient
roleDefClient RoleDefinitionsClient
vmClient VirtualMachinesClient
Expand All @@ -80,6 +82,9 @@ func NewFetcher(cfg Config, ctx context.Context) (*Fetcher, error) {
}

// Create the clients
graphClient, err := msgraph.NewClient(msgraph.Config{
TokenProvider: cred,
})
roleAssignClient, err := azure.NewRoleAssignmentsClient(cfg.SubscriptionID, cred, nil)
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -97,6 +102,7 @@ func NewFetcher(cfg Config, ctx context.Context) (*Fetcher, error) {
return &Fetcher{
Config: cfg,
lastResult: &Resources{},
graphClient: graphClient,
roleAssignClient: roleAssignClient,
roleDefClient: roleDefClient,
vmClient: vmClient,
Expand Down Expand Up @@ -152,11 +158,7 @@ func (a *Fetcher) fetch(ctx context.Context, feats Features) (*Resources, error)
errsCh := make(chan error)
if feats.Principals {
eg.Go(func() error {
cred, err := a.CloudClients.GetAzureCredential()
if err != nil {
return trace.Wrap(err)
}
principals, err := fetchPrincipals(ctx, a.SubscriptionID, cred)
principals, err := fetchPrincipals(ctx, a.SubscriptionID, a.graphClient)
if err != nil {
errsCh <- err
return err
Expand Down

0 comments on commit b2512a9

Please sign in to comment.