diff --git a/src/internal/connector/graph/service_helper.go b/src/internal/connector/graph/service_helper.go index 23fad0274..94700b96a 100644 --- a/src/internal/connector/graph/service_helper.go +++ b/src/internal/connector/graph/service_helper.go @@ -41,6 +41,14 @@ func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt return nil, errors.Wrap(err, "creating new AzureIdentityAuthentication") } + httpClient := CreateHTTPClient() + + return msgraphsdk.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient( + auth, nil, nil, httpClient) +} + +// CreateHTTPClient creates the httpClient with middlewares and timeout configured +func CreateHTTPClient() *nethttp.Client { clientOptions := msgraphsdk.GetDefaultClientOptions() middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions) @@ -52,8 +60,7 @@ func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...) httpClient.Timeout = time.Second * 90 - return msgraphsdk.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient( - auth, nil, nil, httpClient) + return httpClient } // LoggingMiddleware can be used to log the http request sent by the graph client diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index e29a2ec9a..09cc2711c 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -5,8 +5,6 @@ import ( "io" "time" - msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" - msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/pkg/errors" @@ -88,11 +86,8 @@ func driveItemReader( downloadURL := item.GetAdditionalData()[downloadURLKey].(*string) - clientOptions := msgraphsdk.GetDefaultClientOptions() - middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions) - - httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...) - httpClient.Timeout = 0 // need infinite timeout for pulling large files + httpClient := graph.CreateHTTPClient() + httpClient.Timeout = 0 // infinite timeout for pulling large files resp, err := httpClient.Get(*downloadURL) if err != nil {