Update /connector/graph package
Change to Beta library.
This commit is contained in:
parent
b82a6349f4
commit
4952b81333
@ -1,7 +1,7 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors"
|
"github.com/microsoftgraph/msgraph-beta-sdk-go/models/odataerrors"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
||||||
beta "github.com/microsoftgraph/msgraph-beta-sdk-go"
|
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
|
||||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
@ -46,28 +45,6 @@ func (s Service) Client() *msgraphsdk.GraphServiceClient {
|
|||||||
return s.client
|
return s.client
|
||||||
}
|
}
|
||||||
|
|
||||||
// BetaService provides access to API Calls that are present solely in the Beta library.
|
|
||||||
// Does not fulfill the interface as the base libraries vary.
|
|
||||||
type BetaService struct {
|
|
||||||
adapter *beta.GraphRequestAdapter
|
|
||||||
client *beta.GraphBaseServiceClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bs BetaService) Adapter() *beta.GraphRequestAdapter {
|
|
||||||
return bs.adapter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bs BetaService) Client() *beta.GraphBaseServiceClient {
|
|
||||||
return bs.client
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBetaService(adapter *beta.GraphRequestAdapter) *BetaService {
|
|
||||||
return &BetaService{
|
|
||||||
adapter: adapter,
|
|
||||||
client: beta.NewGraphBaseServiceClient(adapter),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seraialize writes an M365 parsable object into a byte array using the built-in
|
// Seraialize writes an M365 parsable object into a byte array using the built-in
|
||||||
// application/json writer within the adapter.
|
// application/json writer within the adapter.
|
||||||
func (s Service) Serialize(object absser.Parsable) ([]byte, error) {
|
func (s Service) Serialize(object absser.Parsable) ([]byte, error) {
|
||||||
|
|||||||
@ -10,8 +10,7 @@ import (
|
|||||||
az "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
az "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||||
ka "github.com/microsoft/kiota-authentication-azure-go"
|
ka "github.com/microsoft/kiota-authentication-azure-go"
|
||||||
khttp "github.com/microsoft/kiota-http-go"
|
khttp "github.com/microsoft/kiota-http-go"
|
||||||
beta "github.com/microsoftgraph/msgraph-beta-sdk-go"
|
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
|
||||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
|
||||||
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
|
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
@ -47,28 +46,6 @@ func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt
|
|||||||
auth, nil, nil, httpClient)
|
auth, nil, nil, httpClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateBetaAdapter uses the provided credentials with the Kiota Azure Libraries.
|
|
||||||
// Used to access msgraph-beta-sdk-go specific functionality
|
|
||||||
func CreateBetaAdapter(tenant, client, secret string) (*beta.GraphRequestAdapter, error) {
|
|
||||||
cred, err := az.NewClientSecretCredential(tenant, client, secret, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "creating beta m365 client credentials")
|
|
||||||
}
|
|
||||||
|
|
||||||
auth, err := ka.NewAzureIdentityAuthenticationProviderWithScopes(
|
|
||||||
cred,
|
|
||||||
[]string{"https://graph.microsoft.com/.default"},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "creating beta auth token")
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient := CreateHTTPClient()
|
|
||||||
|
|
||||||
return beta.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(
|
|
||||||
auth, nil, nil, httpClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateHTTPClient creates the httpClient with middlewares and timeout configured
|
// CreateHTTPClient creates the httpClient with middlewares and timeout configured
|
||||||
func CreateHTTPClient() *http.Client {
|
func CreateHTTPClient() *http.Client {
|
||||||
clientOptions := msgraphsdk.GetDefaultClientOptions()
|
clientOptions := msgraphsdk.GetDefaultClientOptions()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package graph_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -43,21 +43,6 @@ func (suite *GraphUnitSuite) TestCreateAdapter() {
|
|||||||
assert.NotNil(t, adpt)
|
assert.NotNil(t, adpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *GraphUnitSuite) TestBetaService() {
|
|
||||||
t := suite.T()
|
|
||||||
adpt, err := graph.CreateBetaAdapter(
|
|
||||||
suite.credentials.AzureTenantID,
|
|
||||||
suite.credentials.AzureClientID,
|
|
||||||
suite.credentials.AzureClientSecret,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
require.NotNil(t, adpt)
|
|
||||||
|
|
||||||
serv := graph.NewBetaService(adpt)
|
|
||||||
assert.NotNil(t, serv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *GraphUnitSuite) TestSerializationEndPoint() {
|
func (suite *GraphUnitSuite) TestSerializationEndPoint() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
adpt, err := graph.CreateAdapter(
|
adpt, err := graph.CreateAdapter(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user