mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 16:23:04 -05:00
* repo: added 'enable password change' flag (defaults to true for new repositories), which prevents embedding replicas of kopia.repository in pack blobs * cli: added 'repo change-password' which can change the password of a connected repository * repo: nit - renamed variables and functions dealing with key derivation * repo: fixed cache validation HMAC secret to use stored HMAC secret instead of password-derived one * cli: added test for repo change-password * repo: negative cases for attempting to change password in an old repository * Update cli/command_repository_change_password.go Co-authored-by: Julio Lopez <julio+gh@kasten.io> Co-authored-by: Julio Lopez <julio+gh@kasten.io>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
type commandRepositoryChangePassword struct {
|
|
newPassword string
|
|
|
|
svc advancedAppServices
|
|
}
|
|
|
|
func (c *commandRepositoryChangePassword) setup(svc advancedAppServices, parent commandParent) {
|
|
cmd := parent.Command("change-password", "Change repository password")
|
|
cmd.Flag("new-password", "New password").Envar("KOPIA_NEW_PASSWORD").StringVar(&c.newPassword)
|
|
|
|
c.svc = svc
|
|
cmd.Action(svc.directRepositoryWriteAction(c.run))
|
|
}
|
|
|
|
func (c *commandRepositoryChangePassword) run(ctx context.Context, rep repo.DirectRepositoryWriter) error {
|
|
var newPass string
|
|
|
|
if c.newPassword == "" {
|
|
n, err := askForChangedRepositoryPassword(c.svc.stdout())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
newPass = n
|
|
} else {
|
|
newPass = c.newPassword
|
|
}
|
|
|
|
if err := rep.ChangePassword(ctx, newPass); err != nil {
|
|
return errors.Wrap(err, "unable to change password")
|
|
}
|
|
|
|
log(ctx).Infof(`NOTE: Repository password has been changed.`)
|
|
|
|
if err := c.svc.passwordPersistenceStrategy().PersistPassword(ctx, c.svc.repositoryConfigFileName(), newPass); err != nil {
|
|
return errors.Wrap(err, "unable to persist password")
|
|
}
|
|
|
|
return nil
|
|
}
|