store

package
v0.0.0-...-1f8c1e5 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: AGPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ErrNotFound is returned when the file is not found.
	ErrNotFound = errors.ConstError("file not found")

	// ErrFileToLarge is returned when the file is too large.
	ErrFileToLarge = errors.ConstError("file too large")

	// ErrCharmHashMismatch is returned when the charm hash does not match the expected hash.
	ErrCharmHashMismatch = errors.ConstError("charm hash mismatch")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CharmReader

type CharmReader interface {
	io.Reader
	io.ReaderAt
	io.Closer
}

CharmReader is an interface that combines the io.Reader, io.ReaderAt, and io.Closer interfaces.

type CharmStore

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

CharmStore provides an API for storing and retrieving charm blobs.

func NewCharmStore

func NewCharmStore(objectStoreGetter objectstore.ModelObjectStoreGetter, logger logger.Logger) *CharmStore

NewCharmStore returns a new charm store instance.

func (*CharmStore) Get

func (s *CharmStore) Get(ctx context.Context, path string) (io.ReadCloser, error)

Get retrieves a ReadCloser for the charm archive at the give path from the underlying storage. NOTE: It is up to the caller to verify the integrity of the data from the charm hash stored in DQLite.

func (*CharmStore) GetBySHA256Prefix

func (s *CharmStore) GetBySHA256Prefix(ctx context.Context, sha256Prefix string) (io.ReadCloser, error)

GetBySHA256Prefix retrieves a ReadCloser for a charm archive who's SHA256 hash starts with the provided prefix.

func (*CharmStore) Store

func (s *CharmStore) Store(ctx context.Context, path string, size int64, sha384 string) (StoreResult, error)

Store the charm at the specified path into the object store. It is expected that the archive already exists at the specified path. If the file isn't found, a ErrNotFound is returned.

func (*CharmStore) StoreFromReader

func (s *CharmStore) StoreFromReader(ctx context.Context, reader io.Reader, hashPrefix string) (_ StoreFromReaderResult, _ Digest, err error)

StoreFromReader stores the charm from the provided reader into the object store. The caller is expected to remove the temporary file after the call. This does not check the integrity of the charm hash.

type Digest

type Digest struct {
	SHA256 string
	SHA384 string
	Size   int64
}

Digest contains the SHA256 and SHA384 hashes of a charm archive. This will be used to verify the integrity of the charm archive.

type StoreFromReaderResult

type StoreFromReaderResult struct {
	Charm           CharmReader
	UniqueName      string
	ObjectStoreUUID objectstore.UUID
}

StoreFromReaderResult contains the unique name of the charm archive and the object store UUID.

type StoreResult

type StoreResult struct {
	UniqueName      string
	ObjectStoreUUID objectstore.UUID
}

StoreResult contains the path of the stored charm archive, the unique name of the charm archive, and the object store UUID.

Jump to

Keyboard shortcuts

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