add 10 day deadline to cli context (#2852)

Ensures all CLI usage has a context deadline so that we
don't bump into the graph api 100 second deadline.

---

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included

#### Type of change

- [x] 🐛 Bugfix

#### Test Plan

- [x] 💪 Manual
This commit is contained in:
Keepers 2023-03-17 17:48:13 -06:00 committed by GitHub
parent 91328d9898
commit 621e850531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix repo connect not working without a config file
- Fix item re-download on expired links silently being skipped
- Improved permissions backup and restore for OneDrive
- CLI calls default to a 10-day context deadline to avoid letting graph api restrict requests to a 100 second deadline.
### Known Issues
- Owner (Full control) or empty (Restricted View) roles cannot be restored for OneDrive

View File

@ -5,6 +5,7 @@ import (
"os"
"regexp"
"strings"
"time"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
@ -146,8 +147,12 @@ func BuildCommandTree(cmd *cobra.Command) {
// Handle builds and executes the cli processor.
func Handle() {
tenDays := time.Now().Add(time.Hour * 24 * 10)
//nolint:forbidigo
ctx := config.Seed(context.Background())
ctx, cancel := context.WithDeadline(context.Background(), tenDays)
defer cancel()
ctx = config.Seed(ctx)
ctx = print.SetRootCmd(ctx, corsoCmd)
observe.SeedWriter(ctx, print.StderrWriter(ctx), observe.PreloadFlags())

View File

@ -36,6 +36,7 @@ const (
rateLimitHeader = "RateLimit-Limit"
rateRemainingHeader = "RateLimit-Remaining"
rateResetHeader = "RateLimit-Reset"
defaultHTTPClientTimeout = 1 * time.Hour
)
// AllMetadataFileNames produces the standard set of filenames used to store graph
@ -199,7 +200,7 @@ func HTTPClient(opts ...option) *http.Client {
noOfRetries, minRetryDelay := clientconfig.applyMiddlewareConfig()
middlewares := GetKiotaMiddlewares(&clientOptions, noOfRetries, minRetryDelay)
httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
httpClient.Timeout = time.Minute * 3
httpClient.Timeout = defaultHTTPClientTimeout
clientconfig.apply(httpClient)

View File

@ -3,7 +3,6 @@ package graph
import (
"net/http"
"testing"
"time"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/assert"
@ -54,7 +53,7 @@ func (suite *GraphUnitSuite) TestHTTPClient() {
name: "no options",
opts: []option{},
check: func(t *testing.T, c *http.Client) {
assert.Equal(t, 3*time.Minute, c.Timeout, "default timeout")
assert.Equal(t, defaultHTTPClientTimeout, c.Timeout, "default timeout")
},
},
{