storage

package
Version: v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: Apache-2.0 Imports: 20 Imported by: 180

Documentation

Index

Constants

View Source
const (
	// MaxErrorResponseSize is the maximum size for an error message - 1KiB
	MaxErrorResponseSize int64 = 1 << 10
	// MaxKeySize is the maximum size for a stored TUF key - 256KiB
	MaxKeySize = 256 << 10
)
View Source
const NoSizeLimit int64 = -1

NoSizeLimit is represented as -1 for arguments to GetMeta

Variables

View Source
var (
	// ErrPathOutsideStore indicates that the returned path would be
	// outside the store
	ErrPathOutsideStore = errors.New("path outside file store")
)

Functions

func NewMultiPartMetaRequest added in v0.4.0

func NewMultiPartMetaRequest(url string, metas map[string][]byte) (*http.Request, error)

NewMultiPartMetaRequest builds a request with the provided metadata updates in multipart form

Types

type Bootstrapper

type Bootstrapper interface {
	// Bootstrap instructs a configured Bootstrapper to perform
	// its setup operations.
	Bootstrap() error
}

Bootstrapper is a thing that can set itself up

type ErrInvalidOperation added in v0.4.0

type ErrInvalidOperation struct {
	// contains filtered or unexported fields
}

ErrInvalidOperation indicates that the server returned a 400 response and propagate any body we received.

func (ErrInvalidOperation) Error added in v0.4.0

func (err ErrInvalidOperation) Error() string

type ErrMaliciousServer added in v0.4.0

type ErrMaliciousServer struct{}

ErrMaliciousServer indicates the server returned a response that is highly suspected of being malicious. i.e. it attempted to send us more data than the known size of a particular role metadata.

func (ErrMaliciousServer) Error added in v0.4.0

func (err ErrMaliciousServer) Error() string

type ErrMetaNotFound added in v0.4.0

type ErrMetaNotFound struct {
	Resource string
}

ErrMetaNotFound indicates we did not find a particular piece of metadata in the store

func (ErrMetaNotFound) Error added in v0.4.0

func (err ErrMetaNotFound) Error() string

type ErrOffline added in v0.4.0

type ErrOffline struct{}

ErrOffline is used to indicate we are operating offline

func (ErrOffline) Error added in v0.4.0

func (e ErrOffline) Error() string

type ErrServerUnavailable added in v0.4.0

type ErrServerUnavailable struct {
	// contains filtered or unexported fields
}

ErrServerUnavailable indicates an error from the server. code allows us to populate the http error we received

func (ErrServerUnavailable) Error added in v0.4.0

func (err ErrServerUnavailable) Error() string

type FilesystemStore added in v0.4.0

type FilesystemStore struct {
	// contains filtered or unexported fields
}

FilesystemStore is a store in a locally accessible directory

func NewFileStore added in v0.4.0

func NewFileStore(baseDir, fileExt string) (*FilesystemStore, error)

NewFileStore creates a fully configurable file store

func NewPrivateKeyFileStorage added in v0.4.0

func NewPrivateKeyFileStorage(baseDir, fileExt string) (*FilesystemStore, error)

NewPrivateKeyFileStorage initializes a new filestore for private keys, appending the notary.PrivDir to the baseDir.

func NewPrivateSimpleFileStore added in v0.4.0

func NewPrivateSimpleFileStore(baseDir, fileExt string) (*FilesystemStore, error)

NewPrivateSimpleFileStore is a wrapper to create an owner readable/writeable _only_ filestore

func (*FilesystemStore) Get added in v0.4.0

func (f *FilesystemStore) Get(name string) ([]byte, error)

Get returns the meta for the given name.

func (*FilesystemStore) GetSized added in v0.4.0

func (f *FilesystemStore) GetSized(name string, size int64) ([]byte, error)

GetSized returns the meta for the given name (a role) up to size bytes If size is "NoSizeLimit", this corresponds to "infinite," but we cut off at a predefined threshold "notary.MaxDownloadSize". If the file is larger than size we return ErrMaliciousServer for consistency with the HTTPStore

func (FilesystemStore) ListFiles added in v0.4.0

func (f FilesystemStore) ListFiles() []string

ListFiles returns a list of all the filenames that can be used with Get* to retrieve content from this filestore

func (FilesystemStore) Location added in v0.4.0

func (f FilesystemStore) Location() string

Location returns a human readable name for the storage location

func (*FilesystemStore) Remove added in v0.4.0

func (f *FilesystemStore) Remove(name string) error

Remove removes the metadata for a single role - if the metadata doesn't exist, no error is returned

func (*FilesystemStore) RemoveAll added in v0.4.0

func (f *FilesystemStore) RemoveAll() error

RemoveAll clears the existing filestore by removing its base directory

func (*FilesystemStore) Set added in v0.4.0

func (f *FilesystemStore) Set(name string, meta []byte) error

Set sets the meta for a single role

func (*FilesystemStore) SetMulti added in v0.4.0

func (f *FilesystemStore) SetMulti(metas map[string][]byte) error

SetMulti sets the metadata for multiple roles in one operation

type HTTPStore added in v0.4.0

type HTTPStore struct {
	// contains filtered or unexported fields
}

HTTPStore manages pulling and pushing metadata from and to a remote service over HTTP. It assumes the URL structure of the remote service maps identically to the structure of the TUF repo: <baseURL>/<metaPrefix>/(root|targets|snapshot|timestamp).json <baseURL>/<targetsPrefix>/foo.sh

If consistent snapshots are disabled, it is advised that caching is not enabled. Simple set a cachePath (and ensure it's writeable) to enable caching.

func (HTTPStore) GetKey added in v0.4.0

func (s HTTPStore) GetKey(role data.RoleName) ([]byte, error)

GetKey retrieves a public key from the remote server

func (HTTPStore) GetSized added in v0.4.0

func (s HTTPStore) GetSized(name string, size int64) ([]byte, error)

GetSized downloads the named meta file with the given size. A short body is acceptable because in the case of timestamp.json, the size is a cap, not an exact length. If size is "NoSizeLimit", this corresponds to "infinite," but we cut off at a predefined threshold "notary.MaxDownloadSize".

func (HTTPStore) Location added in v0.4.0

func (s HTTPStore) Location() string

Location returns a human readable name for the storage location

func (HTTPStore) Remove added in v0.4.0

func (s HTTPStore) Remove(name string) error

Remove always fails, because we should never be able to delete metadata remotely

func (HTTPStore) RemoveAll added in v0.4.0

func (s HTTPStore) RemoveAll() error

RemoveAll will attempt to delete all TUF metadata for a GUN

func (HTTPStore) RotateKey added in v0.4.0

func (s HTTPStore) RotateKey(role data.RoleName) ([]byte, error)

RotateKey rotates a private key and returns the public component from the remote server

func (HTTPStore) Set added in v0.4.0

func (s HTTPStore) Set(name string, blob []byte) error

Set sends a single piece of metadata to the TUF server

func (HTTPStore) SetMulti added in v0.4.0

func (s HTTPStore) SetMulti(metas map[string][]byte) error

SetMulti does a single batch upload of multiple pieces of TUF metadata. This should be preferred for updating a remote server as it enable the server to remain consistent, either accepting or rejecting the complete update.

type MemoryStore added in v0.4.0

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore implements a mock RemoteStore entirely in memory. For testing purposes only.

func NewMemoryStore added in v0.4.0

func NewMemoryStore(seed map[data.RoleName][]byte) *MemoryStore

NewMemoryStore returns a MetadataStore that operates entirely in memory. Very useful for testing

func (MemoryStore) Get added in v0.4.0

func (m MemoryStore) Get(name string) ([]byte, error)

Get returns the data associated with name

func (MemoryStore) GetSized added in v0.4.0

func (m MemoryStore) GetSized(name string, size int64) ([]byte, error)

GetSized returns up to size bytes of data references by name. If size is "NoSizeLimit", this corresponds to "infinite," but we cut off at a predefined threshold "notary.MaxDownloadSize", as we will always know the size for everything but a timestamp and sometimes a root, neither of which should be exceptionally large

func (*MemoryStore) ListFiles added in v0.4.0

func (m *MemoryStore) ListFiles() []string

ListFiles returns a list of all files. The names returned should be usable with Get directly, with no modification.

func (MemoryStore) Location added in v0.4.0

func (m MemoryStore) Location() string

Location provides a human readable name for the storage location

func (*MemoryStore) Remove added in v0.4.0

func (m *MemoryStore) Remove(name string) error

Remove removes the metadata for a single role - if the metadata doesn't exist, no error is returned

func (*MemoryStore) RemoveAll added in v0.4.0

func (m *MemoryStore) RemoveAll() error

RemoveAll clears the existing memory store by setting this store as new empty one

func (*MemoryStore) Set added in v0.4.0

func (m *MemoryStore) Set(name string, meta []byte) error

Set sets the metadata value for the given name

func (*MemoryStore) SetMulti added in v0.4.0

func (m *MemoryStore) SetMulti(metas map[string][]byte) error

SetMulti sets multiple pieces of metadata for multiple names in a single operation.

type MetadataStore added in v0.4.0

type MetadataStore interface {
	GetSized(name string, size int64) ([]byte, error)
	Set(name string, blob []byte) error
	SetMulti(map[string][]byte) error
	RemoveAll() error
	Remove(name string) error
	Location() string
}

MetadataStore must be implemented by anything that intends to interact with a store of TUF files

type NetworkError added in v0.4.1

type NetworkError struct {
	Wrapped error
}

NetworkError represents any kind of network error when attempting to make a request

func (NetworkError) Error added in v0.4.1

func (n NetworkError) Error() string

type OfflineStore added in v0.4.0

type OfflineStore struct{}

OfflineStore is to be used as a placeholder for a nil store. It simply returns ErrOffline for every operation

func (OfflineStore) GetKey added in v0.4.0

func (es OfflineStore) GetKey(role data.RoleName) ([]byte, error)

GetKey returns ErrOffline

func (OfflineStore) GetSized added in v0.4.0

func (es OfflineStore) GetSized(name string, size int64) ([]byte, error)

GetSized returns ErrOffline

func (OfflineStore) Location added in v0.4.0

func (es OfflineStore) Location() string

Location returns a human readable name for the storage location

func (OfflineStore) Remove added in v0.4.0

func (es OfflineStore) Remove(name string) error

Remove returns ErrOffline

func (OfflineStore) RemoveAll added in v0.4.0

func (es OfflineStore) RemoveAll() error

RemoveAll return ErrOffline

func (OfflineStore) RotateKey added in v0.4.0

func (es OfflineStore) RotateKey(role data.RoleName) ([]byte, error)

RotateKey returns ErrOffline

func (OfflineStore) Set added in v0.4.0

func (es OfflineStore) Set(name string, blob []byte) error

Set returns ErrOffline

func (OfflineStore) SetMulti added in v0.4.0

func (es OfflineStore) SetMulti(map[string][]byte) error

SetMulti returns ErrOffline

type PublicKeyStore added in v0.4.0

type PublicKeyStore interface {
	GetKey(role data.RoleName) ([]byte, error)
	RotateKey(role data.RoleName) ([]byte, error)
}

PublicKeyStore must be implemented by a key service

type RemoteStore added in v0.4.0

type RemoteStore interface {
	MetadataStore
	PublicKeyStore
}

RemoteStore is similar to LocalStore with the added expectation that it should provide a way to download targets once located

func NewHTTPStore added in v0.4.0

func NewHTTPStore(baseURL, metaPrefix, metaExtension, keyExtension string, roundTrip http.RoundTripper) (RemoteStore, error)

NewHTTPStore initializes a new store against a URL and a number of configuration options.

In case of a nil `roundTrip`, a default offline store is used instead.

func NewNotaryServerStore added in v0.7.0

func NewNotaryServerStore(serverURL string, gun data.GUN, roundTrip http.RoundTripper) (RemoteStore, error)

NewNotaryServerStore returns a new HTTPStore against a URL which should represent a notary server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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