update kopia password
This commit is contained in:
parent
5c4419fdc0
commit
ae66673492
@ -11,17 +11,19 @@ const (
|
|||||||
AWSSessionTokenFN = "aws-session-token"
|
AWSSessionTokenFN = "aws-session-token"
|
||||||
|
|
||||||
// Corso Flags
|
// Corso Flags
|
||||||
CorsoPassphraseFN = "passphrase"
|
CorsoPassphraseFN = "passphrase"
|
||||||
SucceedIfExistsFN = "succeed-if-exists"
|
UpdateCorsoPassphraseFN = "update-passphrase"
|
||||||
|
SucceedIfExistsFN = "succeed-if-exists"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BackupIDFV string
|
BackupIDFV string
|
||||||
AWSAccessKeyFV string
|
AWSAccessKeyFV string
|
||||||
AWSSecretAccessKeyFV string
|
AWSSecretAccessKeyFV string
|
||||||
AWSSessionTokenFV string
|
AWSSessionTokenFV string
|
||||||
CorsoPassphraseFV string
|
CorsoPassphraseFV string
|
||||||
SucceedIfExistsFV bool
|
UpdateCorsoPhasephraseFV string
|
||||||
|
SucceedIfExistsFV bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddBackupIDFlag adds the --backup flag.
|
// AddBackupIDFlag adds the --backup flag.
|
||||||
@ -59,6 +61,15 @@ func AddCorsoPassphaseFlags(cmd *cobra.Command) {
|
|||||||
"Passphrase to protect encrypted repository contents")
|
"Passphrase to protect encrypted repository contents")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// M365 flags
|
||||||
|
func AddCorsoUpdatePassphraseFlags(cmd *cobra.Command) {
|
||||||
|
fs := cmd.Flags()
|
||||||
|
fs.StringVar(&UpdateCorsoPhasephraseFV,
|
||||||
|
UpdateCorsoPassphraseFN,
|
||||||
|
"",
|
||||||
|
"update kopia passphrase for repo")
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Provider
|
// Provider
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
initCommand = "init"
|
initCommand = "init"
|
||||||
connectCommand = "connect"
|
connectCommand = "connect"
|
||||||
|
updateCommand = "update"
|
||||||
maintenanceCommand = "maintenance"
|
maintenanceCommand = "maintenance"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,12 +35,14 @@ func AddCommands(cmd *cobra.Command) {
|
|||||||
initCmd = initCmd()
|
initCmd = initCmd()
|
||||||
connectCmd = connectCmd()
|
connectCmd = connectCmd()
|
||||||
maintenanceCmd = maintenanceCmd()
|
maintenanceCmd = maintenanceCmd()
|
||||||
|
updateCmd = updateCmd()
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd.AddCommand(repoCmd)
|
cmd.AddCommand(repoCmd)
|
||||||
repoCmd.AddCommand(initCmd)
|
repoCmd.AddCommand(initCmd)
|
||||||
repoCmd.AddCommand(connectCmd)
|
repoCmd.AddCommand(connectCmd)
|
||||||
repoCmd.AddCommand(maintenanceCmd)
|
repoCmd.AddCommand(maintenanceCmd)
|
||||||
|
repoCmd.AddCommand(updateCmd)
|
||||||
|
|
||||||
flags.AddMaintenanceModeFlag(maintenanceCmd)
|
flags.AddMaintenanceModeFlag(maintenanceCmd)
|
||||||
flags.AddForceMaintenanceFlag(maintenanceCmd)
|
flags.AddForceMaintenanceFlag(maintenanceCmd)
|
||||||
@ -50,6 +53,8 @@ func AddCommands(cmd *cobra.Command) {
|
|||||||
addRepoTo(initCmd)
|
addRepoTo(initCmd)
|
||||||
addRepoTo(connectCmd)
|
addRepoTo(connectCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addS3Commands(updateCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The repo category of commands.
|
// The repo category of commands.
|
||||||
@ -58,7 +63,7 @@ func repoCmd() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "repo",
|
Use: "repo",
|
||||||
Short: "Manage your repositories",
|
Short: "Manage your repositories",
|
||||||
Long: `Initialize, configure, and connect to your account backup repositories.`,
|
Long: `Initialize, configure, connect and update to your account backup repositories.`,
|
||||||
RunE: handleRepoCmd,
|
RunE: handleRepoCmd,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
}
|
}
|
||||||
@ -170,3 +175,20 @@ func getMaintenanceType(t string) (repository.MaintenanceType, error) {
|
|||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The repo update subcommand.
|
||||||
|
// `corso repo update <repository> [<flag>...]`
|
||||||
|
func updateCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: updateCommand,
|
||||||
|
Short: "Update a repository.",
|
||||||
|
Long: `Update a existing repository to store your backups.`,
|
||||||
|
RunE: handleUpdateCmd,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler for calls to `corso repo init`.
|
||||||
|
func handleUpdateCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
return cmd.Help()
|
||||||
|
}
|
||||||
|
|||||||
@ -28,6 +28,12 @@ func addS3Commands(cmd *cobra.Command) *cobra.Command {
|
|||||||
|
|
||||||
case connectCommand:
|
case connectCommand:
|
||||||
c, _ = utils.AddCommand(cmd, s3ConnectCmd())
|
c, _ = utils.AddCommand(cmd, s3ConnectCmd())
|
||||||
|
|
||||||
|
case updateCommand:
|
||||||
|
update := s3UpdateCmd()
|
||||||
|
flags.AddCorsoUpdatePassphraseFlags(update)
|
||||||
|
c, _ = utils.AddCommand(cmd, update)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Use = c.Use + " " + s3ProviderCommandUseSuffix
|
c.Use = c.Use + " " + s3ProviderCommandUseSuffix
|
||||||
@ -222,6 +228,10 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
opts,
|
opts,
|
||||||
repoID)
|
repoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return Only(ctx, clues.Wrap(err, "Failed to create a repository controller"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Connect(ctx); err != nil {
|
||||||
return Only(ctx, clues.Wrap(err, "Failed to connect to the S3 repository"))
|
return Only(ctx, clues.Wrap(err, "Failed to connect to the S3 repository"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,3 +245,57 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------
|
||||||
|
// Update Password
|
||||||
|
// ---------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// `corso repo update s3 [<flag>...]`
|
||||||
|
func s3UpdateCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: s3ProviderCommand,
|
||||||
|
Short: "Update to a S3 repository",
|
||||||
|
Long: `Update to an existing S3 repository.`,
|
||||||
|
RunE: updateS3Cmd,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Example: s3ProviderCommandConnectExamples,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// updates to an existing s3 repo.
|
||||||
|
// currently just updating Kopia password
|
||||||
|
func updateS3Cmd(cmd *cobra.Command, args []string) error {
|
||||||
|
ctx := cmd.Context()
|
||||||
|
cfg, err := config.GetConfigRepoDetails(
|
||||||
|
ctx,
|
||||||
|
storage.ProviderS3,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
flags.S3FlagOverrides(cmd))
|
||||||
|
if err != nil {
|
||||||
|
return Only(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repoID := cfg.RepoID
|
||||||
|
if len(repoID) == 0 {
|
||||||
|
repoID = events.RepoIDNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := utils.ControlWithConfig(cfg)
|
||||||
|
|
||||||
|
r, err := repository.New(
|
||||||
|
ctx,
|
||||||
|
cfg.Account,
|
||||||
|
cfg.Storage,
|
||||||
|
opts,
|
||||||
|
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"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ const (
|
|||||||
CorsoStart = "Corso Start"
|
CorsoStart = "Corso Start"
|
||||||
RepoInit = "Repo Init"
|
RepoInit = "Repo Init"
|
||||||
RepoConnect = "Repo Connect"
|
RepoConnect = "Repo Connect"
|
||||||
|
RepoUpdate = "Repo Update"
|
||||||
BackupStart = "Backup Start"
|
BackupStart = "Backup Start"
|
||||||
BackupEnd = "Backup End"
|
BackupEnd = "Backup End"
|
||||||
RestoreStart = "Restore Start"
|
RestoreStart = "Restore Start"
|
||||||
|
|||||||
@ -6,6 +6,7 @@ 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"
|
||||||
|
|
||||||
@ -272,6 +273,44 @@ func (r *repository) Connect(ctx context.Context) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePassword updates Kopia password
|
||||||
|
func (r *repository) UpdatePassword(ctx context.Context, password string) (err error) {
|
||||||
|
ctx = clues.Add(
|
||||||
|
ctx,
|
||||||
|
"acct_provider", r.Account.Provider.String(),
|
||||||
|
"acct_id", clues.Hide(r.Account.ID()),
|
||||||
|
"storage_provider", r.Storage.Provider.String())
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if crErr := crash.Recovery(ctx, recover(), "repo connect"); crErr != nil {
|
||||||
|
err = crErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
progressBar := observe.MessageWithCompletion(ctx, "Connecting to repository")
|
||||||
|
defer close(progressBar)
|
||||||
|
|
||||||
|
kopiaRef := kopia.NewConn(r.Storage)
|
||||||
|
if err := kopiaRef.Connect(ctx, r.Opts.Repo); err != nil {
|
||||||
|
return clues.Wrap(err, "connecting kopia client")
|
||||||
|
}
|
||||||
|
|
||||||
|
repository := kopiaRef.Repository.(repo.DirectRepository)
|
||||||
|
err = repository.FormatManager().ChangePassword(ctx, password)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "unable to update password")
|
||||||
|
}
|
||||||
|
|
||||||
|
// kopiaRef comes with a count of 1 and NewWrapper/NewModelStore bumps it again so safe
|
||||||
|
// to close here.
|
||||||
|
defer kopiaRef.Close(ctx)
|
||||||
|
|
||||||
|
r.Bus.Event(ctx, events.RepoUpdate, nil)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *repository) Close(ctx context.Context) error {
|
func (r *repository) Close(ctx context.Context) error {
|
||||||
if err := r.Bus.Close(); err != nil {
|
if err := r.Bus.Close(); err != nil {
|
||||||
logger.Ctx(ctx).With("err", err).Debugw("closing the event bus", clues.In(ctx).Slice()...)
|
logger.Ctx(ctx).With("err", err).Debugw("closing the event bus", clues.In(ctx).Slice()...)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user