Files
kopia/cli/command_repository_disconnect.go
Jarek Kowalski 41931f21ce repo: refactored password persistence (#1065)
* introduced passwordpersist package which has password persistence
  strategies (keyring, file, none, multiple) with possibility of adding
  more in the future.
* moved all password persistence logic out of 'repo'
* removed global variable repo.EnableKeyRing
2021-05-11 21:53:36 -07:00

35 lines
834 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
)
type commandRepositoryDisconnect struct {
svc advancedAppServices
}
func (c *commandRepositoryDisconnect) setup(svc advancedAppServices, parent commandParent) {
cmd := parent.Command("disconnect", "Disconnect from a repository.")
cmd.Action(svc.noRepositoryAction(c.run))
c.svc = svc
}
func (c *commandRepositoryDisconnect) run(ctx context.Context) error {
c.svc.removeUpdateState()
if err := repo.Disconnect(ctx, c.svc.repositoryConfigFileName()); err != nil {
return errors.Wrap(err, "unable to disconnect from repository")
}
if err := c.svc.passwordPersistenceStrategy().DeletePassword(ctx, c.svc.repositoryConfigFileName()); err != nil {
return errors.Wrap(err, "unable to remove persisted password")
}
return nil
}