mirror of
https://github.com/kopia/kopia.git
synced 2026-03-27 10:32:08 -04:00
* feat(infra): improved support for in-process testing * support for killing of a running server using simulated Ctrl-C * support for overriding os.Stdin * migrated many tests from the exe runner to in-process runner * added required indirection when defining Envar() so we can later override it in tests * refactored CLI runners by moving environment overrides to CLITestEnv
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(svc.EnvName("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
|
|
}
|