skip-permissions flag to stop restoring of permissions of Onedrive (#4313)

<!-- PR description-->

add `skip-permissions` flag for permission restore

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

- [ ]  Yes, it's included

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* https://github.com/alcionai/corso/issues/3854

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
neha_gupta 2023-09-22 12:21:00 +05:30 committed by GitHub
parent 496b725035
commit 8ce6dc4217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 43 additions and 54 deletions

View File

@ -251,7 +251,7 @@ jobs:
service: onedrive service: onedrive
kind: initial kind: initial
backup-args: '--user "${{ env.TEST_USER }}"' backup-args: '--user "${{ env.TEST_USER }}"'
restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }} --restore-permissions' restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}'
test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}' test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}'
log-dir: ${{ env.CORSO_LOG_DIR }} log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true with-export: true
@ -274,7 +274,7 @@ jobs:
service: onedrive service: onedrive
kind: incremental kind: incremental
backup-args: '--user "${{ env.TEST_USER }}"' backup-args: '--user "${{ env.TEST_USER }}"'
restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }} --restore-permissions' restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}'
test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}' test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-onedrive.outputs.result }}'
log-dir: ${{ env.CORSO_LOG_DIR }} log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true with-export: true
@ -307,7 +307,7 @@ jobs:
service: sharepoint service: sharepoint
kind: initial kind: initial
backup-args: '--site "${{ secrets.CORSO_M365_TEST_SITE_URL }}"' backup-args: '--site "${{ secrets.CORSO_M365_TEST_SITE_URL }}"'
restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }} --restore-permissions' restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}'
test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}' test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}'
log-dir: ${{ env.CORSO_LOG_DIR }} log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true with-export: true
@ -331,7 +331,7 @@ jobs:
service: sharepoint service: sharepoint
kind: incremental kind: incremental
backup-args: '--site "${{ secrets.CORSO_M365_TEST_SITE_URL }}"' backup-args: '--site "${{ secrets.CORSO_M365_TEST_SITE_URL }}"'
restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }} --restore-permissions' restore-args: '--folder ${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}'
test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}' test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-sharepoint.outputs.result }}'
log-dir: ${{ env.CORSO_LOG_DIR }} log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true with-export: true

View File

@ -16,7 +16,7 @@ const (
FetchParallelismFN = "fetch-parallelism" FetchParallelismFN = "fetch-parallelism"
NoStatsFN = "no-stats" NoStatsFN = "no-stats"
RecoveredErrorsFN = "recovered-errors" RecoveredErrorsFN = "recovered-errors"
RestorePermissionsFN = "restore-permissions" NoPermissionsFN = "no-permissions"
RunModeFN = "run-mode" RunModeFN = "run-mode"
SkippedItemsFN = "skipped-items" SkippedItemsFN = "skipped-items"
SkipReduceFN = "skip-reduce" SkipReduceFN = "skip-reduce"
@ -37,9 +37,9 @@ var (
NoStatsFV bool NoStatsFV bool
// RunMode describes the type of run, such as: // RunMode describes the type of run, such as:
// flagtest, dry, run. Should default to 'run'. // flagtest, dry, run. Should default to 'run'.
RunModeFV string RunModeFV string
RestorePermissionsFV bool NoPermissionsFV bool
SkipReduceFV bool SkipReduceFV bool
) )
// well-known flag values // well-known flag values
@ -62,10 +62,10 @@ func AddFailFastFlag(cmd *cobra.Command) {
cobra.CheckErr(fs.MarkHidden(FailFastFN)) cobra.CheckErr(fs.MarkHidden(FailFastFN))
} }
// AddRestorePermissionsFlag adds OneDrive flag for restoring permissions // AddSkipPermissionsFlag adds OneDrive flag for skipping restoring permissions
func AddRestorePermissionsFlag(cmd *cobra.Command) { func AddSkipPermissionsFlag(cmd *cobra.Command) {
fs := cmd.Flags() fs := cmd.Flags()
fs.BoolVar(&RestorePermissionsFV, RestorePermissionsFN, false, "Restore permissions for files and folders") fs.BoolVar(&NoPermissionsFV, NoPermissionsFN, false, "don't restore file and folder permissions")
} }
// AddSkipReduceFlag adds a hidden flag that allows callers to skip the selector // AddSkipReduceFlag adds a hidden flag that allows callers to skip the selector

View File

@ -27,7 +27,7 @@ func addGroupsCommands(cmd *cobra.Command) *cobra.Command {
fs.SortFlags = false fs.SortFlags = false
flags.AddBackupIDFlag(c, true) flags.AddBackupIDFlag(c, true)
flags.AddRestorePermissionsFlag(c) flags.AddSkipPermissionsFlag(c)
flags.AddSharePointDetailsAndRestoreFlags(c) // for sp restores flags.AddSharePointDetailsAndRestoreFlags(c) // for sp restores
flags.AddSiteIDFlag(c) flags.AddSiteIDFlag(c)
flags.AddRestoreConfigFlags(c) flags.AddRestoreConfigFlags(c)
@ -48,8 +48,8 @@ const (
groupsServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Marketing's last backup (1234abcd...) groupsServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Marketing's last backup (1234abcd...)
corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef
# Restore the file with ID 98765abcdef along with its associated permissions # Restore the file with ID 98765abcdef without its associated permissions
corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef --restore-permissions corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef --skip-permissions
# Restore all files named "FY2021 Planning.xlsx" # Restore all files named "FY2021 Planning.xlsx"
corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file "FY2021 Planning.xlsx" corso restore groups --backup 1234abcd-12ab-cd34-56de-1234abcd --file "FY2021 Planning.xlsx"

View File

@ -87,9 +87,6 @@ func (suite *GroupsUnitSuite) TestAddGroupsCommands() {
"--" + flags.AzureClientSecretFN, testdata.AzureClientSecret, "--" + flags.AzureClientSecretFN, testdata.AzureClientSecret,
"--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase, "--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase,
// bool flags
"--" + flags.RestorePermissionsFN,
}) })
cmd.SetOut(new(bytes.Buffer)) // drop output cmd.SetOut(new(bytes.Buffer)) // drop output
@ -121,7 +118,7 @@ func (suite *GroupsUnitSuite) TestAddGroupsCommands() {
assert.Equal(t, testdata.AzureClientSecret, flags.AzureClientSecretFV) assert.Equal(t, testdata.AzureClientSecret, flags.AzureClientSecretFV)
assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV) assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV)
assert.True(t, flags.RestorePermissionsFV) assert.False(t, flags.NoPermissionsFV)
}) })
} }
} }

View File

@ -28,7 +28,7 @@ func addOneDriveCommands(cmd *cobra.Command) *cobra.Command {
flags.AddBackupIDFlag(c, true) flags.AddBackupIDFlag(c, true)
flags.AddOneDriveDetailsAndRestoreFlags(c) flags.AddOneDriveDetailsAndRestoreFlags(c)
flags.AddRestorePermissionsFlag(c) flags.AddSkipPermissionsFlag(c)
flags.AddRestoreConfigFlags(c) flags.AddRestoreConfigFlags(c)
flags.AddFailFastFlag(c) flags.AddFailFastFlag(c)
flags.AddCorsoPassphaseFlags(c) flags.AddCorsoPassphaseFlags(c)
@ -46,8 +46,8 @@ const (
oneDriveServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Bob's last backup (1234abcd...) oneDriveServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Bob's last backup (1234abcd...)
corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef
# Restore the file with ID 98765abcdef along with its associated permissions # Restore the file with ID 98765abcdef without its associated permissions
corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef --restore-permissions corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef --no-permissions
# Restore files named "FY2021 Planning.xlsx" in "Documents/Finance Reports" # Restore files named "FY2021 Planning.xlsx" in "Documents/Finance Reports"
corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd \ corso restore onedrive --backup 1234abcd-12ab-cd34-56de-1234abcd \

View File

@ -81,9 +81,6 @@ func (suite *OneDriveUnitSuite) TestAddOneDriveCommands() {
"--" + flags.AzureClientSecretFN, testdata.AzureClientSecret, "--" + flags.AzureClientSecretFN, testdata.AzureClientSecret,
"--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase, "--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase,
// bool flags
"--" + flags.RestorePermissionsFN,
}) })
cmd.SetOut(new(bytes.Buffer)) // drop output cmd.SetOut(new(bytes.Buffer)) // drop output
@ -114,7 +111,6 @@ func (suite *OneDriveUnitSuite) TestAddOneDriveCommands() {
assert.Equal(t, testdata.AzureClientSecret, flags.AzureClientSecretFV) assert.Equal(t, testdata.AzureClientSecret, flags.AzureClientSecretFV)
assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV) assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV)
assert.True(t, flags.RestorePermissionsFV)
}) })
} }
} }

View File

@ -28,7 +28,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
flags.AddBackupIDFlag(c, true) flags.AddBackupIDFlag(c, true)
flags.AddSharePointDetailsAndRestoreFlags(c) flags.AddSharePointDetailsAndRestoreFlags(c)
flags.AddRestorePermissionsFlag(c) flags.AddSkipPermissionsFlag(c)
flags.AddRestoreConfigFlags(c) flags.AddRestoreConfigFlags(c)
flags.AddFailFastFlag(c) flags.AddFailFastFlag(c)
flags.AddCorsoPassphaseFlags(c) flags.AddCorsoPassphaseFlags(c)
@ -47,9 +47,9 @@ const (
sharePointServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Bob's latest backup (1234abcd...) sharePointServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Bob's latest backup (1234abcd...)
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef
# Restore the file with ID 98765abcdef along with its associated permissions # Restore the file with ID 98765abcdef without its associated permissions
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \ corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \
--file 98765abcdef --restore-permissions --file 98765abcdef --no-permissions
# Restore files named "ServerRenderTemplate.xsl" in the folder "Display Templates/Style Sheets". # Restore files named "ServerRenderTemplate.xsl" in the folder "Display Templates/Style Sheets".
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \ corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \

View File

@ -86,9 +86,6 @@ func (suite *SharePointUnitSuite) TestAddSharePointCommands() {
"--" + flags.AzureClientSecretFN, testdata.AzureClientSecret, "--" + flags.AzureClientSecretFN, testdata.AzureClientSecret,
"--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase, "--" + flags.CorsoPassphraseFN, testdata.CorsoPassphrase,
// bool flags
"--" + flags.RestorePermissionsFN,
}) })
cmd.SetOut(new(bytes.Buffer)) // drop output cmd.SetOut(new(bytes.Buffer)) // drop output
@ -128,7 +125,7 @@ func (suite *SharePointUnitSuite) TestAddSharePointCommands() {
assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV) assert.Equal(t, testdata.CorsoPassphrase, flags.CorsoPassphraseFV)
// bool flags // bool flags
assert.True(t, flags.RestorePermissionsFV) assert.False(t, flags.NoPermissionsFV)
}) })
} }
} }

View File

@ -32,7 +32,7 @@ func (suite *OptionsUnitSuite) TestAddExchangeCommands() {
assert.True(t, flags.ForceItemDataDownloadFV, flags.ForceItemDataDownloadFN) assert.True(t, flags.ForceItemDataDownloadFV, flags.ForceItemDataDownloadFN)
assert.True(t, flags.DisableDeltaFV, flags.DisableDeltaFN) assert.True(t, flags.DisableDeltaFV, flags.DisableDeltaFN)
assert.True(t, flags.NoStatsFV, flags.NoStatsFN) assert.True(t, flags.NoStatsFV, flags.NoStatsFN)
assert.True(t, flags.RestorePermissionsFV, flags.RestorePermissionsFN) assert.True(t, flags.NoPermissionsFV, flags.NoPermissionsFN)
assert.True(t, flags.SkipReduceFV, flags.SkipReduceFN) assert.True(t, flags.SkipReduceFV, flags.SkipReduceFN)
assert.Equal(t, 2, flags.FetchParallelismFV, flags.FetchParallelismFN) assert.Equal(t, 2, flags.FetchParallelismFV, flags.FetchParallelismFN)
assert.True(t, flags.DisableConcurrencyLimiterFV, flags.DisableConcurrencyLimiterFN) assert.True(t, flags.DisableConcurrencyLimiterFV, flags.DisableConcurrencyLimiterFN)
@ -47,7 +47,7 @@ func (suite *OptionsUnitSuite) TestAddExchangeCommands() {
flags.AddDisableIncrementalsFlag(cmd) flags.AddDisableIncrementalsFlag(cmd)
flags.AddForceItemDataDownloadFlag(cmd) flags.AddForceItemDataDownloadFlag(cmd)
flags.AddDisableDeltaFlag(cmd) flags.AddDisableDeltaFlag(cmd)
flags.AddRestorePermissionsFlag(cmd) flags.AddSkipPermissionsFlag(cmd)
flags.AddSkipReduceFlag(cmd) flags.AddSkipReduceFlag(cmd)
flags.AddFetchParallelismFlag(cmd) flags.AddFetchParallelismFlag(cmd)
flags.AddDisableConcurrencyLimiterFlag(cmd) flags.AddDisableConcurrencyLimiterFlag(cmd)
@ -61,7 +61,7 @@ func (suite *OptionsUnitSuite) TestAddExchangeCommands() {
"--" + flags.ForceItemDataDownloadFN, "--" + flags.ForceItemDataDownloadFN,
"--" + flags.DisableDeltaFN, "--" + flags.DisableDeltaFN,
"--" + flags.NoStatsFN, "--" + flags.NoStatsFN,
"--" + flags.RestorePermissionsFN, "--" + flags.NoPermissionsFN,
"--" + flags.SkipReduceFN, "--" + flags.SkipReduceFN,
"--" + flags.FetchParallelismFN, "2", "--" + flags.FetchParallelismFN, "2",
"--" + flags.DisableConcurrencyLimiterFN, "--" + flags.DisableConcurrencyLimiterFN,

View File

@ -19,20 +19,20 @@ type RestoreCfgOpts struct {
// DTTMFormat is the timestamp format appended // DTTMFormat is the timestamp format appended
// to the default folder name. Defaults to // to the default folder name. Defaults to
// dttm.HumanReadable. // dttm.HumanReadable.
DTTMFormat dttm.TimeFormat DTTMFormat dttm.TimeFormat
ProtectedResource string ProtectedResource string
RestorePermissions bool SkipPermissions bool
Populated flags.PopulatedFlags Populated flags.PopulatedFlags
} }
func makeRestoreCfgOpts(cmd *cobra.Command) RestoreCfgOpts { func makeRestoreCfgOpts(cmd *cobra.Command) RestoreCfgOpts {
return RestoreCfgOpts{ return RestoreCfgOpts{
Collisions: flags.CollisionsFV, Collisions: flags.CollisionsFV,
Destination: flags.DestinationFV, Destination: flags.DestinationFV,
DTTMFormat: dttm.HumanReadable, DTTMFormat: dttm.HumanReadable,
ProtectedResource: flags.ToResourceFV, ProtectedResource: flags.ToResourceFV,
RestorePermissions: flags.RestorePermissionsFV, SkipPermissions: flags.NoPermissionsFV,
// populated contains the list of flags that appear in the // populated contains the list of flags that appear in the
// command, according to pflags. Use this to differentiate // command, according to pflags. Use this to differentiate
@ -72,7 +72,7 @@ func MakeRestoreConfig(
} }
restoreCfg.ProtectedResource = opts.ProtectedResource restoreCfg.ProtectedResource = opts.ProtectedResource
restoreCfg.IncludePermissions = opts.RestorePermissions restoreCfg.IncludePermissions = !opts.SkipPermissions
Infof(ctx, "Restoring to folder %s", restoreCfg.Location) Infof(ctx, "Restoring to folder %s", restoreCfg.Location)

View File

@ -126,11 +126,11 @@ func (suite *RestoreCfgUnitSuite) TestMakeRestoreConfig() {
}, },
}, },
{ {
name: "with restore permissions", name: "without restore permissions",
rco: &RestoreCfgOpts{ rco: &RestoreCfgOpts{
Collisions: "collisions", Collisions: "collisions",
Destination: "destination", Destination: "destination",
RestorePermissions: true, SkipPermissions: flags.NoPermissionsFV,
}, },
populated: flags.PopulatedFlags{ populated: flags.PopulatedFlags{
flags.CollisionsFN: {}, flags.CollisionsFN: {},
@ -139,7 +139,7 @@ func (suite *RestoreCfgUnitSuite) TestMakeRestoreConfig() {
expect: control.RestoreConfig{ expect: control.RestoreConfig{
OnCollision: control.CollisionPolicy("collisions"), OnCollision: control.CollisionPolicy("collisions"),
Location: "destination", Location: "destination",
IncludePermissions: true, IncludePermissions: false,
}, },
}, },
} }
@ -156,7 +156,6 @@ func (suite *RestoreCfgUnitSuite) TestMakeRestoreConfig() {
result := MakeRestoreConfig(ctx, opts) result := MakeRestoreConfig(ctx, opts)
assert.Equal(t, test.expect.OnCollision, result.OnCollision) assert.Equal(t, test.expect.OnCollision, result.OnCollision)
assert.Contains(t, result.Location, test.expect.Location) assert.Contains(t, result.Location, test.expect.Location)
assert.Equal(t, test.expect.IncludePermissions, result.IncludePermissions)
}) })
} }
} }

View File

@ -44,10 +44,10 @@ var (
PageFolderInput = []string{"pageFolder1", "pageFolder2"} PageFolderInput = []string{"pageFolder1", "pageFolder2"}
PageInput = []string{"page1", "page2"} PageInput = []string{"page1", "page2"}
Collisions = "collisions" Collisions = "collisions"
Destination = "destination" Destination = "destination"
ToResource = "toResource" ToResource = "toResource"
RestorePermissions = true SkipPermissions = false
DeltaPageSize = "deltaPageSize" DeltaPageSize = "deltaPageSize"