Files
kopia/repo/parameters.go
Jarek Kowalski 730ba7b94a Repository password change support (#1197)
* 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>
2021-07-17 07:58:02 -07:00

44 lines
1.1 KiB
Go

package repo
import (
"context"
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo/content"
)
// SetParameters changes mutable repository parameters.
func (r *directRepository) SetParameters(ctx context.Context, m content.MutableParameters) error {
f := r.formatBlob
repoConfig, err := f.decryptFormatBytes(r.formatEncryptionKey)
if err != nil {
return errors.Wrap(err, "unable to decrypt repository config")
}
if err := m.Validate(); err != nil {
return errors.Wrap(err, "invalid parameters")
}
repoConfig.FormattingOptions.MutableParameters = m
if err := encryptFormatBytes(f, repoConfig, r.formatEncryptionKey, f.UniqueID); err != nil {
return errors.Errorf("unable to encrypt format bytes")
}
if err := writeFormatBlob(ctx, r.blobs, f); err != nil {
return errors.Wrap(err, "unable to write format blob")
}
if cd := r.cachingOptions.CacheDirectory; cd != "" {
if err := os.Remove(filepath.Join(cd, "kopia.repository")); err != nil && !os.IsNotExist(err) {
return errors.Errorf("unable to remove cached repository format blob: %v", err)
}
}
return nil
}