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
- Variables
- func Name(kind Kind, scope string, rev digest.Digest) (string, error)
- func NewS3Client(endpoint, region string, pathStyle bool) (*minio.Client, error)
- func ReadBlob(ctx context.Context, s Store, kind Kind, scope string, rev digest.Digest, ...) ([]byte, error)
- func StateScope(workspace, resource string) string
- func ValidateDigest(d digest.Digest) error
- func ValidateKey(key string) error
- func ValidateObject(o Object) error
- type Capabilities
- type GHCRPackages
- type Kind
- type OCIOption
- type Object
- type Store
- type TagDeleter
Constants ¶
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 ¶
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 ¶
Name is the flat tag or file name of a revision: s-<scope>-<rev>, k-<scope>-<rev>, c-<rev>, r-<rev>.
func NewS3Client ¶
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 ¶
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 ValidateKey ¶
ValidateKey checks that a name is a legal OCI tag and a legal file name.
func ValidateObject ¶
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.
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 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 WithHeadCache ¶
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.
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. |