Adapter creation moved to graph package (#432)
CreateAdapter function exported to the `graph` package. This will be the same area that authentication and token refreshment will eventually go.
This commit is contained in:
parent
987980510c
commit
a4d99a74ed
23
src/internal/connector/graph/service_helper.go
Normal file
23
src/internal/connector/graph/service_helper.go
Normal file
@ -0,0 +1,23 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
az "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||
ka "github.com/microsoft/kiota-authentication-azure-go"
|
||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||
)
|
||||
|
||||
// CreateAdapter uses provided credentials to log into M365 using Kiota Azure Library
|
||||
// with Azure identity package.
|
||||
func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapter, error) {
|
||||
// Client Provider: Uses Secret for access to tenant-level data
|
||||
cred, err := az.NewClientSecretCredential(tenant, client, secret, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
auth, err := ka.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{"https://graph.microsoft.com/.default"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
adapter, err := msgraphsdk.NewGraphRequestAdapter(auth)
|
||||
return adapter, err
|
||||
}
|
||||
@ -8,8 +8,6 @@ import (
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
az "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||
ka "github.com/microsoft/kiota-authentication-azure-go"
|
||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
@ -17,6 +15,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/alcionai/corso/internal/connector/exchange"
|
||||
"github.com/alcionai/corso/internal/connector/graph"
|
||||
"github.com/alcionai/corso/internal/connector/support"
|
||||
"github.com/alcionai/corso/internal/data"
|
||||
"github.com/alcionai/corso/pkg/account"
|
||||
@ -83,23 +82,13 @@ func NewGraphConnector(acct account.Account) (*GraphConnector, error) {
|
||||
return &gc, nil
|
||||
}
|
||||
|
||||
func createAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapter, error) {
|
||||
// Client Provider: Uses Secret for access to tenant-level data
|
||||
cred, err := az.NewClientSecretCredential(tenant, client, secret, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
auth, err := ka.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{"https://graph.microsoft.com/.default"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
adapter, err := msgraphsdk.NewGraphRequestAdapter(auth)
|
||||
return adapter, err
|
||||
}
|
||||
|
||||
// createSubConnector private constructor method for subConnector
|
||||
// createService constructor for graphService component
|
||||
func (gc *GraphConnector) createService(shouldFailFast bool) (*graphService, error) {
|
||||
adapter, err := createAdapter(gc.credentials.TenantID, gc.credentials.ClientID, gc.credentials.ClientSecret)
|
||||
adapter, err := graph.CreateAdapter(
|
||||
gc.credentials.TenantID,
|
||||
gc.credentials.ClientID,
|
||||
gc.credentials.ClientSecret,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -110,6 +99,7 @@ func (gc *GraphConnector) createService(shouldFailFast bool) (*graphService, err
|
||||
}
|
||||
return &connector, err
|
||||
}
|
||||
|
||||
func (gs *graphService) EnableFailFast() {
|
||||
gs.failFast = true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user