mirror of
https://github.com/kopia/kopia.git
synced 2026-01-06 05:27:59 -05:00
* implemented format blob cache abstraction * moved upgrade lock logic to repo/format * moved set parameters logic to repo/format * moved change password functionality to repo/format * mechanical changes * mechanical changes to react to format manager interface * get current repository format bytes instead of static * implemented format.Manager which dynamically fetches and caches latest format blob * repo changes to use format.Manager * fixed failing unit test due to different timings * reduced lock contention by using RWMutex * serve immutable parts of format without any locks * increase test timeout * fixed handling of negative validDuration The new rules are: - validDuration < 0 - ignore initial cached file, refresh every 15min - validDuration > 15min - refresh every 15 minutes - validDuration > 0 && validDuration <= 15min - refresh using provided interval (mostly used for testing)
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.FormatManager().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
|
|
}
|