storage

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 29 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 the payload of an object, 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

	// MaxRequestRefs bounds request discovery before all pages are accumulated.
	// Duplicate refs consume the budget too: a hostile listing may repeat them.
	MaxRequestRefs = 10000
)

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 cannot delete objects")
	ErrDiscoveryLimit = errors.New("request discovery exceeds the reference budget")
)

Functions

func CanDelete added in v0.10.0

func CanDelete(s Store) bool

CanDelete reports, without calling the backend, whether s can delete objects. A backend that may not delete says so through a CanDelete method, and a wrapper passes its inner store's answer on; every other backend can.

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>, 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 ReadPayload added in v0.10.0

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

ReadPayload reads a whole payload 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 ValidateObject

func ValidateObject(o Object) error

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

Types

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 Object

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

Object is one published revision: a head that names it, and an optional payload the head refers to. Rev is the digest of Head. Storage gives the parts no meaning; the protocol on top decides what they say.

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 payload 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 its payload.
	Publish(ctx context.Context, o Object) error
	// FetchHead returns the head, verified against its name. A missing object is
	// ErrNotFound. It never transfers the payload.
	FetchHead(ctx context.Context, kind Kind, scope string, rev digest.Digest) ([]byte, error)
	// OpenPayload streams the payload of an object. A missing object or payload
	// is ErrNotFound. The caller checks the content against the digest its head
	// names, because only the protocol on top knows it.
	OpenPayload(ctx context.Context, kind Kind, scope string, rev digest.Digest) (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. Request discovery stops at
	// MaxRequestRefs and returns ErrDiscoveryLimit without a partial list.
	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. A backend that cannot delete returns ErrUnsupported.
	Delete(ctx context.Context, kind Kind, scope string, rev digest.Digest) error
}

Store is the whole contract a backend implements.

func NewGHCR added in v0.10.0

func NewGHCR(ref string, credential auth.CredentialFunc, token func() (string, error)) (Store, error)

NewGHCR is NewOCI for ghcr.io, which also deletes revisions through the GitHub Packages API with token.

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) (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. Payloads are not cached: they are read only for the few revisions whose content is used.

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