backend

package
v1.14.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package backend implements a registry to register differnet plugable backends for encryption and storage (incl. version control). The actual backends are implemented in the subpackages. They register themselves in the registry with blank imports.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CryptoRegistry is the global registry of available crypto backends.
	CryptoRegistry = NewRegistry[CryptoBackend, CryptoLoader]()
	// StorageRegistry is the global registry of available storage backends.
	StorageRegistry = NewRegistry[StorageBackend, StorageLoader]()

	// ErrNotFound is returned if the requested backend was not found.
	ErrNotFound = fmt.Errorf("backend not found")
)
View Source
var ErrNotSupported = fmt.Errorf("not supported")

ErrNotSupported is returned by backends for unsupported calls.

Functions

func CryptoBackendName

func CryptoBackendName(cb CryptoBackend) string

CryptoBackendName returns the name of the given backend.

func HasCryptoBackend

func HasCryptoBackend(ctx context.Context) bool

HasCryptoBackend returns true if a value for crypto backend has been set in the context.

func HasStorageBackend

func HasStorageBackend(ctx context.Context) bool

HasStorageBackend returns true if a value for store backend was set.

func StorageBackendName

func StorageBackendName(sb StorageBackend) string

StorageBackendName returns the name of the given backend.

func WithCryptoBackend

func WithCryptoBackend(ctx context.Context, be CryptoBackend) context.Context

WithCryptoBackend returns a context with the given crypto backend set.

func WithCryptoBackendString

func WithCryptoBackendString(ctx context.Context, be string) context.Context

WithCryptoBackendString returns a context with the given crypto backend set.

func WithStorageBackend

func WithStorageBackend(ctx context.Context, sb StorageBackend) context.Context

WithStorageBackend returns a context with the given store backend set.

func WithStorageBackendString

func WithStorageBackendString(ctx context.Context, sb string) context.Context

WithStorageBackendString returns a context with the given store backend set.

Types

type Crypto

type Crypto interface {
	Keyring

	Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error)
	Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error)
	RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error)

	Name() string
	Version(context.Context) semver.Version
	Initialized(ctx context.Context) error
	Ext() string    // filename extension.
	IDFile() string // recipient IDs.
	Concurrency() int
}

Crypto is a crypto backend.

func DetectCrypto

func DetectCrypto(ctx context.Context, storage Storage) (Crypto, error)

DetectCrypto tries to detect the crypto backend used.

func NewCrypto

func NewCrypto(ctx context.Context, id CryptoBackend) (Crypto, error)

NewCrypto instantiates a new crypto backend.

type CryptoBackend

type CryptoBackend int

CryptoBackend is a cryptographic backend.

const (
	// Plain is a no-op crypto backend.
	Plain CryptoBackend = iota
	// GPGCLI is a gpg-cli based crypto backend.
	GPGCLI
	// Age - age-encryption.org.
	Age
)

func GetCryptoBackend

func GetCryptoBackend(ctx context.Context) CryptoBackend

GetCryptoBackend returns the selected crypto backend or the default (GPGCLI).

func (CryptoBackend) String

func (c CryptoBackend) String() string

type CryptoLoader

type CryptoLoader interface {
	fmt.Stringer
	Prioritized
	New(context.Context) (Crypto, error)
	Handles(context.Context, Storage) error
}

CryptoLoader is the interface for creating a new crypto backend.

type Keyring

type Keyring interface {
	ListRecipients(ctx context.Context) ([]string, error)
	ListIdentities(ctx context.Context) ([]string, error)

	FindRecipients(ctx context.Context, needles ...string) ([]string, error)
	FindIdentities(ctx context.Context, needles ...string) ([]string, error)

	Fingerprint(ctx context.Context, id string) string
	FormatKey(ctx context.Context, id, tpl string) string
	ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error)

	GenerateIdentity(ctx context.Context, name, email, passphrase string) error
}

Keyring is a public/private key manager.

type Prioritized

type Prioritized interface {
	Priority() int
}

Prioritized is the interface for prioritized items.

type Registry

type Registry[K comparable, V Prioritized] struct {
	// contains filtered or unexported fields
}

Registry is a registry of backends.

func NewRegistry

func NewRegistry[K comparable, V Prioritized]() *Registry[K, V]

NewRegistry returns a new registry.

func (*Registry[K, V]) Backend

func (r *Registry[K, V]) Backend(name string) (K, error)

func (*Registry[K, V]) BackendName

func (r *Registry[K, V]) BackendName(backend K) (string, error)

func (*Registry[K, V]) BackendNames

func (r *Registry[K, V]) BackendNames() []string

func (*Registry[K, V]) Backends

func (r *Registry[K, V]) Backends() []V

func (*Registry[K, V]) Get

func (r *Registry[K, V]) Get(key K) (V, error)

func (*Registry[K, V]) Prioritized

func (r *Registry[K, V]) Prioritized() []V

func (*Registry[K, V]) Register

func (r *Registry[K, V]) Register(backend K, name string, loader V)

type Revision

type Revision struct {
	Hash        string
	AuthorName  string
	AuthorEmail string
	Date        time.Time
	Subject     string
	Body        string
}

Revision is a SCM revision.

type Revisions

type Revisions []Revision

Revisions implements the sort interface.

func (Revisions) Len

func (r Revisions) Len() int

func (Revisions) Less

func (r Revisions) Less(i, j int) bool

func (Revisions) Swap

func (r Revisions) Swap(i, j int)

type Storage

type Storage interface {
	fmt.Stringer

	Get(ctx context.Context, name string) ([]byte, error)
	Set(ctx context.Context, name string, value []byte) error
	Delete(ctx context.Context, name string) error
	Exists(ctx context.Context, name string) bool
	Move(ctx context.Context, from, to string, del bool) error
	List(ctx context.Context, prefix string) ([]string, error)
	IsDir(ctx context.Context, name string) bool
	Prune(ctx context.Context, prefix string) error
	Link(ctx context.Context, from, to string) error

	Name() string
	Path() string
	Version(context.Context) semver.Version
	Fsck(context.Context) error
	// contains filtered or unexported methods
}

Storage is an storage backend.

func Clone

func Clone(ctx context.Context, id StorageBackend, repo, path string) (Storage, error)

Clone clones an existing repository from a remote.

func DetectStorage

func DetectStorage(ctx context.Context, path string) (Storage, error)

DetectStorage tries to detect the storage backend being used.

func InitStorage

func InitStorage(ctx context.Context, id StorageBackend, path string) (Storage, error)

InitStorage initilizes a new storage location.

func NewStorage

func NewStorage(ctx context.Context, id StorageBackend, path string) (Storage, error)

NewStorage initializes an existing storage backend.

type StorageBackend

type StorageBackend int

StorageBackend is a type of storage backend.

const (
	// FS is a filesystem-backed storage.
	FS StorageBackend = iota
	// GitFS is a filesystem-backed storage with Git.
	GitFS
	// FossilFS is a filesystem-backed storage with Fossil.
	FossilFS
)

func GetStorageBackend

func GetStorageBackend(ctx context.Context) StorageBackend

GetStorageBackend returns the store backend or the default (FS).

func (StorageBackend) String

func (s StorageBackend) String() string

type StorageLoader

StorageLoader is the interface for creating a new storage backend.

Directories

Path Synopsis
age
gpg
gpg/cli
Package cli implements a GPG CLI crypto backend.
Package cli implements a GPG CLI crypto backend.
plain
Package plain implements a plaintext backend
Package plain implements a plaintext backend
fs
Package fs implement a password-store compatible on disk storage layout with unencrypted paths.
Package fs implement a password-store compatible on disk storage layout with unencrypted paths.
gitfs
Package gitfs implements a git cli based RCS backend.
Package gitfs implements a git cli based RCS backend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL