Refactor http client creation for onedrive file download (#1736)
## Description This way we are able to use any middlewares added in both places. ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [x] 🐹 Trivial/Minor ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [ ] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
ca5f197067
commit
4ee66c3d3d
@ -41,6 +41,14 @@ func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt
|
|||||||
return nil, errors.Wrap(err, "creating new AzureIdentityAuthentication")
|
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()
|
clientOptions := msgraphsdk.GetDefaultClientOptions()
|
||||||
middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions)
|
middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions)
|
||||||
|
|
||||||
@ -52,8 +60,7 @@ func CreateAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt
|
|||||||
httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
|
httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
|
||||||
httpClient.Timeout = time.Second * 90
|
httpClient.Timeout = time.Second * 90
|
||||||
|
|
||||||
return msgraphsdk.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(
|
return httpClient
|
||||||
auth, nil, nil, httpClient)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoggingMiddleware can be used to log the http request sent by the graph client
|
// LoggingMiddleware can be used to log the http request sent by the graph client
|
||||||
|
|||||||
@ -5,8 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"time"
|
"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/microsoftgraph/msgraph-sdk-go/models"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
@ -88,11 +86,8 @@ func driveItemReader(
|
|||||||
|
|
||||||
downloadURL := item.GetAdditionalData()[downloadURLKey].(*string)
|
downloadURL := item.GetAdditionalData()[downloadURLKey].(*string)
|
||||||
|
|
||||||
clientOptions := msgraphsdk.GetDefaultClientOptions()
|
httpClient := graph.CreateHTTPClient()
|
||||||
middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions)
|
httpClient.Timeout = 0 // infinite timeout for pulling large files
|
||||||
|
|
||||||
httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
|
|
||||||
httpClient.Timeout = 0 // need infinite timeout for pulling large files
|
|
||||||
|
|
||||||
resp, err := httpClient.Get(*downloadURL)
|
resp, err := httpClient.Get(*downloadURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user