storage

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storage publishes immutable, content-named objects. Storage is untrusted: a name is a locator and every fetched object is checked against the digest embedded in its name. There is no compare-and-swap; concurrent writers publish different names and readers merge the resulting heads.

Index

Constants

View Source
const (
	// MaxPayloadBytes bounds one attached blob, such as a revision's ciphertext.
	MaxPayloadBytes = 10 * 1024 * 1024
	// MaxHeadBytes bounds the head of an object, which is read for every revision.
	MaxHeadBytes = 1024 * 1024
	// MaxBlobs bounds the blobs one object can attach.
	MaxBlobs = 8
)

Variables

View Source
var (
	ErrNotFound    = errors.New("storage object not found")
	ErrCorrupt     = errors.New("storage object does not match its name")
	ErrTooLarge    = fmt.Errorf("payload exceeds %d bytes", MaxPayloadBytes)
	ErrUnsupported = errors.New("storage operation not supported by this backend")
)

Functions

func Name

func Name(kind Kind, scope string, rev digest.Digest) (string, error)

Name is the flat tag or file name of a revision: s-<scope>-<rev>, k-<scope>-<rev>, c-<rev>, r-<rev>.

func NewS3Client

func NewS3Client(endpoint, region string, pathStyle bool) (*minio.Client, error)

NewS3Client connects to an S3-compatible endpoint using environment, shared AWS profile, or IAM credentials. An empty endpoint selects Amazon S3.

func ReadBlob

func ReadBlob(ctx context.Context, s Store, kind Kind, scope string, rev digest.Digest, index int, limit int64) ([]byte, error)

ReadBlob reads a whole blob of at most limit bytes.

func StateScope

func StateScope(workspace, resource string) string

StateScope names the listing bucket of one resource of a workspace. A scope collision only mixes two resources in one listing: fetchers re-derive the scope from the signed workspace and resource.

func ValidateDigest

func ValidateDigest(d digest.Digest) error

func ValidateKey

func ValidateKey(key string) error

ValidateKey checks that a name is a legal OCI tag and a legal file name.

func ValidateObject

func ValidateObject(o Object) error

ValidateObject checks everything about an object that does not need the backend.

Types

type Capabilities

type Capabilities struct {
	PhysicalDelete bool
}

Capabilities lists optional backend features. Correctness never depends on them.

type GHCRPackages

type GHCRPackages struct {
	// Token returns the credential for the API, so it is read when needed.
	Token func() (string, error)
	// Owner and Package come from ghcr.io/<owner>/<package>.
	Owner, Package string
	// BaseURL is the API root; empty means https://api.github.com.
	BaseURL string
	Client  *http.Client
}

GHCRPackages deletes package versions of ghcr.io through the GitHub Packages API. The token needs read:packages and delete:packages.

func GHCRPackagesFor

func GHCRPackagesFor(ref string, token func() (string, error)) (*GHCRPackages, bool)

GHCRPackagesFor builds a deleter for a repository reference such as ghcr.io/owner/repo-enbu. It reports false for other registries.

func (*GHCRPackages) DeleteTag

func (g *GHCRPackages) DeleteTag(ctx context.Context, tag string) error

DeleteTag deletes the package version that carries tag. A version deletes every tag it carries, so a version with any other tag is left alone.

type Kind

type Kind string

Kind separates the object namespaces of one storage location.

const (
	KindState   Kind = "state"
	KindControl Kind = "control"
	KindRequest Kind = "request"
	// KindCompaction holds an admin's record of the revisions of one resource
	// that were removed. It is scoped like the resource's states.
	KindCompaction Kind = "compaction"
)

type OCIOption

type OCIOption func(*ociStore)

OCIOption configures an OCI store.

func WithTagDeleter

func WithTagDeleter(d TagDeleter) OCIOption

WithTagDeleter lets the store delete revisions, which plain OCI cannot.

type Object

type Object struct {
	Kind  Kind
	Scope string // StateScope for State and Compaction, empty otherwise
	Rev   digest.Digest
	Head  []byte
	Blobs [][]byte
}

Object is one published revision: a head that names it, and blobs the head refers to. Rev is the digest of Head. Storage gives the parts no meaning; the protocol on top decides what the head says and what each blob is.

They are separate because they are read separately: finding a resource's heads and merge base needs only the small heads of every revision, and a blob is fetched only for a revision whose content is actually needed.

type Store

type Store interface {
	// Publish stores the object under its content-derived name. It is create-only
	// and idempotent, and returns only after reading the object back by name, so
	// a head is never visible without the blobs it refers to.
	Publish(ctx context.Context, o Object) error
	// FetchHead returns the head, verified against its name. A missing object is
	// ErrNotFound. It never transfers the blobs.
	FetchHead(ctx context.Context, kind Kind, scope string, rev digest.Digest) ([]byte, error)
	// OpenBlob streams the index-th blob of an object (counting from 0). A missing
	// object or blob is ErrNotFound. The caller checks the content against the
	// digest its head names, because only the protocol on top knows it.
	OpenBlob(ctx context.Context, kind Kind, scope string, rev digest.Digest, index int) (io.ReadCloser, error)
	// Discover lists the revisions it can currently see. The list may be stale
	// but never names an object that does not exist.
	Discover(ctx context.Context, kind Kind, scope string) ([]digest.Digest, error)
	// Scopes lists the state scopes that hold at least one revision it can
	// currently see, sorted. Like Discover it may be stale.
	Scopes(ctx context.Context) ([]string, error)
	// Delete removes an object. Backends without Capabilities.PhysicalDelete return ErrUnsupported.
	Delete(ctx context.Context, kind Kind, scope string, rev digest.Digest) error
	Capabilities() Capabilities
}

Store is the whole contract a backend implements.

func NewLocal

func NewLocal(dir string) Store

NewLocal stores each revision as one file under dir/revisions.

func NewOCI

func NewOCI(ref string, credential auth.CredentialFunc, plainHTTP bool, opts ...OCIOption) (Store, error)

NewOCI publishes each revision as one OCI manifest under a unique tag. No Referrers `subject` is set: GHCR has no native Referrers support and the specification would then require updating a racy fallback index.

func NewS3

func NewS3(client *minio.Client, bucket, prefix string) Store

NewS3 stores each revision as one object under prefix/revisions.

func WithHeadCache

func WithHeadCache(s Store, dir string) Store

WithHeadCache returns s with its heads cached under dir. Blobs are not cached: they are read only for the few revisions whose content is used.

type TagDeleter

type TagDeleter interface {
	DeleteTag(ctx context.Context, tag string) error
}

TagDeleter removes the registry version that a tag names. A registry has no delete API for tags on its own, so a provider supplies one.

Directories

Path Synopsis
Package storagetest provides an in-memory Store, fault injection, and the contract every storage backend must satisfy.
Package storagetest provides an in-memory Store, fault injection, and the contract every storage backend must satisfy.

Jump to

Keyboard shortcuts

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