From 619bcd6eb80c2c27d23806101de1bf077e51d841 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Fri, 28 Apr 2023 16:06:10 -0700 Subject: [PATCH] Check for new and older content URLs (#3263) Some requests appear to be returning an older version of the content URL key. This was causing corso backup failures. This commit expands the logic to check for both the new and old keys for the URL. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * closes #3262 #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/connector/onedrive/item.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index c33c3755d..bdc64b068 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -20,11 +20,11 @@ import ( "github.com/alcionai/corso/src/pkg/logger" ) -const ( - // downloadUrlKey is used to find the download URL in a - // DriveItem response - downloadURLKey = "@microsoft.graph.downloadUrl" -) +// downloadUrlKeys is used to find the download URL in a DriveItem response. +var downloadURLKeys = []string{ + "@microsoft.graph.downloadUrl", + "@content.downloadUrl", +} // sharePointItemReader will return a io.ReadCloser for the specified item // It crafts this by querying M365 for a download URL for the item @@ -135,12 +135,21 @@ func downloadItem( client graph.Requester, item models.DriveItemable, ) (*http.Response, error) { - url, ok := item.GetAdditionalData()[downloadURLKey].(*string) - if !ok { + var url string + + for _, key := range downloadURLKeys { + tmp, ok := item.GetAdditionalData()[key].(*string) + if ok { + url = ptr.Val(tmp) + break + } + } + + if len(url) == 0 { return nil, clues.New("extracting file url").With("item_id", ptr.Val(item.GetId())) } - resp, err := client.Request(ctx, http.MethodGet, ptr.Val(url), nil, nil) + resp, err := client.Request(ctx, http.MethodGet, url, nil, nil) if err != nil { return nil, err }