filesystem update command
This commit is contained in:
parent
1ee148554d
commit
bf50ed0192
@ -38,6 +38,11 @@ func addFilesystemCommands(cmd *cobra.Command) *cobra.Command {
|
||||
|
||||
case connectCommand:
|
||||
c, _ = utils.AddCommand(cmd, filesystemConnectCmd())
|
||||
|
||||
case updateCommand:
|
||||
update := filesystemUpdateCmd()
|
||||
flags.AddCorsoUpdatePassphraseFlags(update)
|
||||
c, _ = utils.AddCommand(cmd, update)
|
||||
}
|
||||
|
||||
c.Use = c.Use + " " + fsProviderCmdUseSuffix
|
||||
@ -229,3 +234,65 @@ func connectFilesystemCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
// Update
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
// `corso repo update filesystem [<flag>...]`
|
||||
func filesystemUpdateCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: fsProviderCommand,
|
||||
Short: "Update to a filesystem repository",
|
||||
Long: `Update to an existing repository on local or network storage.`,
|
||||
RunE: updateFilesystemCmd,
|
||||
Args: cobra.NoArgs,
|
||||
Example: fsProviderCmdConnectExamples,
|
||||
}
|
||||
}
|
||||
|
||||
// updates to an existing filesystem repo.
|
||||
func updateFilesystemCmd(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
overrides := flags.FilesystemFlagOverrides(cmd)
|
||||
|
||||
// TODO(pandeyabs): Move filepath conversion to FilesystemConfig scope.
|
||||
abs, err := utils.MakeAbsoluteFilePath(overrides[flags.FilesystemPathFN])
|
||||
if err != nil {
|
||||
return Only(ctx, clues.Wrap(err, "getting absolute repo path"))
|
||||
}
|
||||
|
||||
overrides[flags.FilesystemPathFN] = abs
|
||||
|
||||
cfg, err := config.GetConfigRepoDetails(
|
||||
ctx,
|
||||
storage.ProviderFilesystem,
|
||||
true,
|
||||
true,
|
||||
overrides)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
opts := utils.ControlWithConfig(cfg)
|
||||
|
||||
r, err := repository.New(
|
||||
ctx,
|
||||
cfg.Account,
|
||||
cfg.Storage,
|
||||
opts,
|
||||
cfg.RepoID)
|
||||
if err != nil {
|
||||
return Only(ctx, clues.Wrap(err, "Failed to create a repository controller"))
|
||||
}
|
||||
|
||||
if err := r.UpdatePassword(ctx, flags.UpdateCorsoPhasephraseFV); err != nil {
|
||||
return Only(ctx, clues.Wrap(err, "Failed to update s3"))
|
||||
}
|
||||
|
||||
defer utils.CloseRepo(ctx, r)
|
||||
|
||||
Infof(ctx, "Updated repo password.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -153,3 +153,81 @@ func (suite *FilesystemE2ESuite) TestConnectFilesystemCmd() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *FilesystemE2ESuite) TestUpdateFilesystemCmd() {
|
||||
t := suite.T()
|
||||
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
st := storeTD.NewFilesystemStorage(t)
|
||||
cfg, err := st.ToFilesystemConfig()
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
force := map[string]string{
|
||||
tconfig.TestCfgAccountProvider: account.ProviderM365.String(),
|
||||
tconfig.TestCfgStorageProvider: storage.ProviderFilesystem.String(),
|
||||
tconfig.TestCfgFilesystemPath: cfg.Path,
|
||||
}
|
||||
vpr, configFP := tconfig.MakeTempTestConfigClone(t, force)
|
||||
|
||||
ctx = config.SetViper(ctx, vpr)
|
||||
|
||||
// init the repo first
|
||||
r, err := repository.New(
|
||||
ctx,
|
||||
tconfig.NewM365Account(t),
|
||||
st,
|
||||
control.DefaultOptions(),
|
||||
repository.NewRepoID)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
err = r.Initialize(ctx, repository.InitConfig{})
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
// then connect it
|
||||
cmd := cliTD.StubRootCmd(
|
||||
"repo", "connect", "filesystem",
|
||||
"--config-file", configFP,
|
||||
"--path", cfg.Path)
|
||||
cli.BuildCommandTree(cmd)
|
||||
|
||||
// run the command
|
||||
err = cmd.ExecuteContext(ctx)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
// test update
|
||||
cmd = cliTD.StubRootCmd(
|
||||
"repo", "update", "filesystem",
|
||||
"--config-file", configFP,
|
||||
"--path", cfg.Path,
|
||||
"--update-passphrase", "newpass")
|
||||
cli.BuildCommandTree(cmd)
|
||||
|
||||
// run the command
|
||||
err = cmd.ExecuteContext(ctx)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
// try connecting with new password
|
||||
cmd = cliTD.StubRootCmd(
|
||||
"repo", "connect", "filesystem",
|
||||
"--config-file", configFP,
|
||||
"--path", cfg.Path,
|
||||
"--passphrase", "newpass")
|
||||
cli.BuildCommandTree(cmd)
|
||||
|
||||
// run the command
|
||||
err = cmd.ExecuteContext(ctx)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
// try connecting with old password
|
||||
cmd = cliTD.StubRootCmd(
|
||||
"repo", "connect", "filesystem",
|
||||
"--config-file", configFP,
|
||||
"--path", cfg.Path)
|
||||
cli.BuildCommandTree(cmd)
|
||||
|
||||
// run the command
|
||||
err = cmd.ExecuteContext(ctx)
|
||||
require.Error(t, err, clues.ToCore(err))
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ func (suite *FilesystemSuite) TestAddFilesystemCommands() {
|
||||
}{
|
||||
{"init filesystem", initCommand, expectUse, filesystemInitCmd().Short, initFilesystemCmd},
|
||||
{"connect filesystem", connectCommand, expectUse, filesystemConnectCmd().Short, connectFilesystemCmd},
|
||||
{"update filesystem", updateCommand, expectUse, filesystemUpdateCmd().Short, updateFilesystemCmd},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.Run(test.name, func() {
|
||||
|
||||
@ -57,9 +57,8 @@ func AddCommands(cmd *cobra.Command) {
|
||||
for _, addRepoTo := range repoCommands {
|
||||
addRepoTo(initCmd)
|
||||
addRepoTo(connectCmd)
|
||||
addRepoTo(updateCmd)
|
||||
}
|
||||
|
||||
addS3Commands(updateCmd)
|
||||
}
|
||||
|
||||
// The repo category of commands.
|
||||
|
||||
@ -295,6 +295,8 @@ func updateS3Cmd(cmd *cobra.Command, args []string) error {
|
||||
return Only(ctx, clues.Wrap(err, "Failed to update s3"))
|
||||
}
|
||||
|
||||
defer utils.CloseRepo(ctx, r)
|
||||
|
||||
Infof(ctx, "Updated repo password.")
|
||||
|
||||
return nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user