moved all Vault types to 'repo' package

This commit is contained in:
Jarek Kowalski committed 2017-08-01 08:29:41 +02:00
1 parent cab2723443
commit c3f0d5ddc4
13 files changed
+38 -50

No files matched your search

+1 -2
View File
@@ -13,7 +13,6 @@ import (
"github.com/kopia/kopia/internal/units"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/vault"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
@@ -255,7 +254,7 @@ func runCleanupCommand(context *kingpin.ParseContext) error {
totalBlocks++
totalBytes += b.Length
if strings.HasPrefix(b.BlockID, vault.VaultBlockPrefix) {
if strings.HasPrefix(b.BlockID, repo.VaultBlockPrefix) {
ignoredBlocks++
ignoredBytes += b.Length
continue
+4 -5
View File
@@ -9,7 +9,6 @@ import (
"github.com/kopia/kopia/blob"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/vault"
)
var (
@@ -21,7 +20,7 @@ var (
createMaxBlockSize = createCommand.Flag("max-block-size", "Maximum size of a data block.").PlaceHolder("KB").Default("20480").Int()
createObjectSplitter = createCommand.Flag("object-splitter", "The splitter to use for new objects in the repository").Default("DYNAMIC").Enum(supportedObjectSplitters()...)
createInlineBlobSize = createCommand.Flag("inline-blob-size", "Maximum size of an inline data object.").PlaceHolder("KB").Default("32").Int()
createVaultEncryptionFormat = createCommand.Flag("vault-encryption", "Vault encryption.").PlaceHolder("FORMAT").Default(vault.SupportedEncryptionAlgorithms[0]).Enum(vault.SupportedEncryptionAlgorithms...)
createVaultEncryptionFormat = createCommand.Flag("vault-encryption", "Vault encryption.").PlaceHolder("FORMAT").Default(repo.SupportedEncryptionAlgorithms[0]).Enum(repo.SupportedEncryptionAlgorithms...)
createOverwrite = createCommand.Flag("overwrite", "Overwrite existing data (DANGEROUS).").Bool()
createOnly = createCommand.Flag("create-only", "Create the vault, but don't connect to it.").Short('c').Bool()
)
@@ -30,8 +29,8 @@ func init() {
createCommand.Action(runCreateCommand)
}
func vaultFormat() (*vault.VaultFormat, error) {
f := &vault.VaultFormat{
func vaultFormat() (*repo.VaultFormat, error) {
f := &repo.VaultFormat{
Version: "1",
}
f.UniqueID = make([]byte, 32)
@@ -122,7 +121,7 @@ func runCreateCommand(context *kingpin.ParseContext) error {
"Initializing vault with encryption '%v'.\n",
vf.EncryptionAlgorithm)
vlt, err := vault.Create(vaultStorage, vf, creds, repoFormat)
vlt, err := repo.Create(vaultStorage, vf, creds, repoFormat)
if err != nil {
return fmt.Errorf("cannot create vault: %v", err)
}
+13 -14
View File
@@ -20,7 +20,6 @@ import (
"github.com/kopia/kopia/fs/loggingfs"
"github.com/kopia/kopia/internal/config"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/vault"
)
var (
@@ -56,7 +55,7 @@ func openConnection(options ...repo.RepositoryOption) (*client.Connection, error
func connectionOptionsFromFlags(options ...repo.RepositoryOption) *client.Options {
opts := &client.Options{
CredentialsCallback: func() (vault.Credentials, error) { return getVaultCredentials(false) },
CredentialsCallback: func() (repo.Credentials, error) { return getVaultCredentials(false) },
RepositoryOptions: options,
}
@@ -113,7 +112,7 @@ func vaultConfigFileName() string {
return filepath.Join(getHomeDir(), ".kopia/vault.config")
}
func persistVaultConfig(v *vault.Vault) error {
func persistVaultConfig(v *repo.Vault) error {
cfg, err := v.Config()
if err != nil {
return err
@@ -136,7 +135,7 @@ func persistVaultConfig(v *vault.Vault) error {
return ioutil.WriteFile(fname, d, 0600)
}
func openVaultSpecifiedByFlag() (*vault.Vault, error) {
func openVaultSpecifiedByFlag() (*repo.Vault, error) {
if *vaultPath == "" {
return nil, fmt.Errorf("--vault must be specified")
}
@@ -150,21 +149,21 @@ func openVaultSpecifiedByFlag() (*vault.Vault, error) {
return nil, err
}
return vault.Open(storage, creds)
return repo.Open(storage, creds)
}
func getVaultCredentials(isNew bool) (vault.Credentials, error) {
func getVaultCredentials(isNew bool) (repo.Credentials, error) {
if *key != "" {
k, err := hex.DecodeString(*key)
if err != nil {
return nil, fmt.Errorf("invalid key format: %v", err)
}
return vault.MasterKey(k)
return repo.MasterKey(k)
}
if *password != "" {
return vault.Password(strings.TrimSpace(*password))
return repo.Password(strings.TrimSpace(*password))
}
if *keyFile != "" {
@@ -173,7 +172,7 @@ func getVaultCredentials(isNew bool) (vault.Credentials, error) {
return nil, fmt.Errorf("unable to read key file: %v", err)
}
return vault.MasterKey(key)
return repo.MasterKey(key)
}
if *passwordFile != "" {
@@ -182,7 +181,7 @@ func getVaultCredentials(isNew bool) (vault.Credentials, error) {
return nil, fmt.Errorf("unable to read password file: %v", err)
}
return vault.Password(strings.TrimSpace(string(f)))
return repo.Password(strings.TrimSpace(string(f)))
}
if isNew {
for {
@@ -197,7 +196,7 @@ func getVaultCredentials(isNew bool) (vault.Credentials, error) {
if p1 != p2 {
fmt.Println("Passwords don't match!")
} else {
return vault.Password(p1)
return repo.Password(p1)
}
}
} else {
@@ -206,7 +205,7 @@ func getVaultCredentials(isNew bool) (vault.Credentials, error) {
return nil, err
}
fmt.Println()
return vault.Password(p1)
return repo.Password(p1)
}
}
@@ -236,11 +235,11 @@ func askPass(prompt string) (string, error) {
continue
}
if len(p) >= vault.MinPasswordLength {
if len(p) >= repo.MinPasswordLength {
return p, nil
}
fmt.Printf("Password too short, must be at least %v characters, you entered %v. Try again.", vault.MinPasswordLength, len(p))
fmt.Printf("Password too short, must be at least %v characters, you entered %v. Try again.", repo.MinPasswordLength, len(p))
fmt.Println()
}
}
+1 -2
View File
@@ -7,11 +7,10 @@ import (
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/fs/repofs"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/vault"
)
// ParseObjectID interprets the given ID string and returns corresponding repo.ObjectID.
func parseObjectID(id string, vlt *vault.Vault, r *repo.Repository) (repo.ObjectID, error) {
func parseObjectID(id string, vlt *repo.Vault, r *repo.Repository) (repo.ObjectID, error) {
head, tail := splitHeadTail(id)
if len(head) == 0 {
return repo.NullObjectID, fmt.Errorf("invalid object ID: %v", id)
+4 -5
View File
@@ -11,7 +11,6 @@ import (
"github.com/kopia/kopia/blob/logging"
"github.com/kopia/kopia/internal/config"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/vault"
// Register well-known blob storage providers
_ "github.com/kopia/kopia/blob/filesystem"
@@ -20,7 +19,7 @@ import (
// Connection represents open connection to Vault and Repository.
type Connection struct {
Vault *vault.Vault
Vault *repo.Vault
Repository *repo.Repository
}
@@ -46,9 +45,9 @@ func Open(ctx context.Context, configFile string, options *Options) (*Connection
return nil, err
}
var creds vault.Credentials
var creds repo.Credentials
if len(lc.VaultConnection.Key) > 0 {
creds, err = vault.MasterKey(lc.VaultConnection.Key)
creds, err = repo.MasterKey(lc.VaultConnection.Key)
} else {
if options.CredentialsCallback == nil {
return nil, errors.New("vault key not persisted and no credentials specified")
@@ -72,7 +71,7 @@ func Open(ctx context.Context, configFile string, options *Options) (*Connection
}
var conn Connection
conn.Vault, err = vault.Open(vaultStorage, creds)
conn.Vault, err = repo.Open(vaultStorage, creds)
if err != nil {
rawVaultStorage.Close()
return nil, fmt.Errorf("unable to open vault: %v", err)
+2 -5
View File
@@ -1,13 +1,10 @@
package client
import (
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/vault"
)
import "github.com/kopia/kopia/repo"
// Options specifies the behavior of Connection.
type Options struct {
CredentialsCallback func() (vault.Credentials, error) // credentials required to open the vault, unless persisted
CredentialsCallback func() (repo.Credentials, error) // credentials required to open the vault, unless persisted
TraceStorage func(f string, args ...interface{})
RepositoryOptions []repo.RepositoryOption
+2 -2
View File
@@ -7,14 +7,14 @@ import (
"os"
"github.com/kopia/kopia/blob/caching"
"github.com/kopia/kopia/vault"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/blob"
)
// LocalConfig is a configuration of Kopia.
type LocalConfig struct {
VaultConnection *vault.Config `json:"vault,omitempty"`
VaultConnection *repo.Config `json:"vault,omitempty"`
RepoConnection *blob.ConnectionInfo `json:"repository,omitempty"` // can be nil indicating the same connection as for the vault
Caching *caching.Options `json:"caching,omitempty"`
}
+1 -1
View File
@@ -1,4 +1,4 @@
package vault
package repo
import (
"crypto/sha256"
+3 -4
View File
@@ -1,4 +1,4 @@
package vault
package repo
import (
"crypto/aes"
@@ -13,7 +13,6 @@ import (
"sync"
"github.com/kopia/kopia/blob"
"github.com/kopia/kopia/repo"
"golang.org/x/crypto/hkdf"
)
@@ -237,7 +236,7 @@ func (v *Vault) RemoveMany(itemIDs []string) error {
func Create(
vaultStorage blob.Storage,
vaultFormat *VaultFormat, vaultCreds Credentials,
repoFormat *repo.Format,
repoFormat *Format,
) (*Vault, error) {
v := Vault{
storage: vaultStorage,
@@ -287,7 +286,7 @@ func Create(
// RepositoryConfig stores the configuration of the repository associated with the vault.
type RepositoryConfig struct {
Format *repo.Format `json:"format"`
Format *Format `json:"format"`
}
// Open opens a vault.
+1 -1
View File
@@ -1,4 +1,4 @@
package vault
package repo
// VaultFormat describes the format of a Vault.
// Contents of this structure are serialized in plain text in the Vault storage.
+2 -3
View File
@@ -1,4 +1,4 @@
package vault
package repo
import (
"context"
@@ -10,7 +10,6 @@ import (
"github.com/kopia/kopia/blob"
"github.com/kopia/kopia/blob/filesystem"
"github.com/kopia/kopia/repo"
"testing"
)
@@ -60,7 +59,7 @@ func verifyVault(t *testing.T, vaultPath string, repoPath string) {
EncryptionAlgorithm: "AES256_GCM",
}
repoFormat := &repo.Format{
repoFormat := &Format{
Version: 1,
MaxBlockSize: 1000000,
ObjectFormat: "UNENCRYPTED_HMAC_SHA256",
+4 -4
View File
@@ -12,7 +12,7 @@ import (
"sync"
"github.com/kopia/kopia/vault"
"github.com/kopia/kopia/repo"
)
const snapshotPrefix = "S"
@@ -26,7 +26,7 @@ var GlobalPolicySourceInfo = &SourceInfo{}
// Manager manages filesystem snapshots.
type Manager struct {
vault *vault.Vault
vault *repo.Vault
snapshotIDSecret []byte
policyIDSecret []byte
}
@@ -253,7 +253,7 @@ func (m *Manager) policyID(src *SourceInfo) string {
func (m *Manager) getPolicyItem(itemID string) (*Policy, error) {
b, err := m.vault.Get(itemID)
if err == vault.ErrItemNotFound {
if err == repo.ErrItemNotFound {
return nil, ErrPolicyNotFound
}
@@ -309,7 +309,7 @@ func (m *Manager) ListPolicies() ([]*Policy, error) {
}
// NewManager creates new snapshot manager for a given connection.
func NewManager(vlt *vault.Vault) *Manager {
func NewManager(vlt *repo.Vault) *Manager {
return &Manager{
vlt,
vlt.DeriveKey([]byte("snapshot-id"), 32),
-2
View File
@@ -1,2 +0,0 @@
// Package vault implements vault for securely storing object IDs and other sensitive data protected with a password or a key.
package vault