From c641e457fdd5147126b0523a17b6b98712ea1b2d Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Mon, 1 May 2023 20:25:47 -0700 Subject: [PATCH] Add initial commit --- src/internal/connector/exchange/api/contacts.go | 16 ++++++++++++++++ .../connector/exchange/service_restore.go | 8 ++++++++ src/internal/connector/graph/errors.go | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/internal/connector/exchange/api/contacts.go b/src/internal/connector/exchange/api/contacts.go index 78d6d7366..4ebfc9ac5 100644 --- a/src/internal/connector/exchange/api/contacts.go +++ b/src/internal/connector/exchange/api/contacts.go @@ -55,6 +55,22 @@ func (c Contacts) CreateContactFolder( return mdl, nil } +// CreateContactFolder makes a contact folder with the displayName of folderName. +// If successful, returns the created folder object. +func (c Contacts) GetContactFolders( + ctx context.Context, + user string, +) (models.ContactFolderCollectionResponseable, error) { + // TODO: Add pagination or just reuse EnumerateContainer logic + // with base id at root + mdl, err := c.Stable.Client().UsersById(user).ContactFolders().Get(ctx, nil) + if err != nil { + return nil, graph.Wrap(ctx, err, "creating contact folder") + } + + return mdl, nil +} + // DeleteContainer deletes the ContactFolder associated with the M365 ID if permissions are valid. func (c Contacts) DeleteContainer( ctx context.Context, diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index c9178e947..2656a3049 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -649,10 +649,18 @@ func establishContactsRestoreLocation( return cached, nil } + folders[0] = "Corso_Restore_02-May-2023_00:06:19" ctx = clues.Add(ctx, "is_new_cache", isNewCache) + // This is where destination folder gets created by corso in graph + // This is the POST operation which may fail if the folder exists temp, err := ac.Contacts().CreateContactFolder(ctx, user, folders[0]) if err != nil { + // TODO:: Add status code check too + if graph.IsErrFolderExists(err) { + result, _ := ac.Contacts().GetContactFolders(ctx, user) + //fmt.Println(result.GetValue()) + } return "", err } diff --git a/src/internal/connector/graph/errors.go b/src/internal/connector/graph/errors.go index 9f83a1c50..55d9aff70 100644 --- a/src/internal/connector/graph/errors.go +++ b/src/internal/connector/graph/errors.go @@ -41,6 +41,7 @@ const ( syncFolderNotFound errorCode = "ErrorSyncFolderNotFound" syncStateInvalid errorCode = "SyncStateInvalid" syncStateNotFound errorCode = "SyncStateNotFound" + folderExists errorCode = "ErrorFolderExists" ) const ( @@ -172,6 +173,10 @@ func IsMalwareResp(ctx context.Context, resp *http.Response) bool { return false } +func IsErrFolderExists(err error) bool { + return hasErrorCode(err, folderExists) +} + // --------------------------------------------------------------------------- // error parsers // ---------------------------------------------------------------------------