lint code and kopia code movement to kopia package

This commit is contained in:
neha-Gupta1 2023-09-29 15:33:49 +05:30
parent 1b1ddcc713
commit 585a394367
5 changed files with 24 additions and 12 deletions

View File

@ -67,7 +67,7 @@ func AddCorsoUpdatePassphraseFlags(cmd *cobra.Command) {
fs.StringVar(&UpdateCorsoPhasephraseFV, fs.StringVar(&UpdateCorsoPhasephraseFV,
UpdateCorsoPassphraseFN, UpdateCorsoPassphraseFN,
"", "",
"update kopia passphrase for repo") "update Corso passphrase for repo")
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -182,7 +182,7 @@ func updateCmd() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: updateCommand, Use: updateCommand,
Short: "Update a repository.", Short: "Update a repository.",
Long: `Update a existing repository to store your backups.`, Long: `Update repository configuration and behavior.`,
RunE: handleUpdateCmd, RunE: handleUpdateCmd,
Args: cobra.NoArgs, Args: cobra.NoArgs,
} }

View File

@ -33,7 +33,6 @@ func addS3Commands(cmd *cobra.Command) *cobra.Command {
update := s3UpdateCmd() update := s3UpdateCmd()
flags.AddCorsoUpdatePassphraseFlags(update) flags.AddCorsoUpdatePassphraseFlags(update)
c, _ = utils.AddCommand(cmd, update) c, _ = utils.AddCommand(cmd, update)
} }
c.Use = c.Use + " " + s3ProviderCommandUseSuffix c.Use = c.Use + " " + s3ProviderCommandUseSuffix
@ -266,6 +265,7 @@ func s3UpdateCmd() *cobra.Command {
// currently just updating Kopia password // currently just updating Kopia password
func updateS3Cmd(cmd *cobra.Command, args []string) error { func updateS3Cmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
cfg, err := config.GetConfigRepoDetails( cfg, err := config.GetConfigRepoDetails(
ctx, ctx,
storage.ProviderS3, storage.ProviderS3,
@ -297,5 +297,7 @@ func updateS3Cmd(cmd *cobra.Command, args []string) error {
return Only(ctx, clues.Wrap(err, "Failed to update s3")) return Only(ctx, clues.Wrap(err, "Failed to update s3"))
} }
Infof(ctx, "Updated repo password.")
return nil return nil
} }

View File

@ -578,3 +578,17 @@ func (w *conn) LoadSnapshot(
func (w *conn) SnapshotRoot(man *snapshot.Manifest) (fs.Entry, error) { func (w *conn) SnapshotRoot(man *snapshot.Manifest) (fs.Entry, error) {
return snapshotfs.SnapshotRoot(w.Repository, man) return snapshotfs.SnapshotRoot(w.Repository, man)
} }
func (w *conn) UpdatePassword(ctx context.Context, password string, opts repository.Options) error {
kopiaRef := NewConn(w.storage)
if err := kopiaRef.Connect(ctx, opts); err != nil {
return clues.Wrap(err, "connecting kopia client")
}
defer kopiaRef.Close(ctx)
repository := kopiaRef.Repository.(repo.DirectRepository)
err := repository.FormatManager().ChangePassword(ctx, password)
return errors.Wrap(err, "unable to update password")
}

View File

@ -6,7 +6,6 @@ import (
"github.com/alcionai/clues" "github.com/alcionai/clues"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/repo/manifest"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -129,7 +128,7 @@ func New(
s storage.Storage, s storage.Storage,
opts control.Options, opts control.Options,
configFileRepoID string, configFileRepoID string,
) (repo *repository, err error) { ) (singleRepo *repository, err error) {
ctx = clues.Add( ctx = clues.Add(
ctx, ctx,
"acct_provider", acct.Provider.String(), "acct_provider", acct.Provider.String(),
@ -295,15 +294,12 @@ func (r *repository) UpdatePassword(ctx context.Context, password string) (err e
return clues.Wrap(err, "connecting kopia client") return clues.Wrap(err, "connecting kopia client")
} }
defer kopiaRef.Close(ctx) if err := kopiaRef.UpdatePassword(ctx, password, r.Opts.Repo); err != nil {
return clues.Wrap(err, "updating on kopia")
repository := kopiaRef.Repository.(repo.DirectRepository)
err = repository.FormatManager().ChangePassword(ctx, password)
if err != nil {
return errors.Wrap(err, "unable to update password")
} }
defer kopiaRef.Close(ctx)
r.Bus.Event(ctx, events.RepoUpdate, nil) r.Bus.Event(ctx, events.RepoUpdate, nil)
return nil return nil