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 CanDelete(s Store) bool
- func Name(kind Kind, scope string, rev digest.Digest) (string, error)
- func NewS3Client(endpoint, region string, pathStyle bool) (*minio.Client, error)
- func ReadPayload(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 ValidateObject(o Object) error
- type GHCRPackages
- type Kind
- type Object
- type Store
- func NewGHCR(ref string, credential auth.CredentialFunc, token func() (string, error)) (Store, error)
- func NewLocal(dir string) Store
- func NewOCI(ref string, credential auth.CredentialFunc, plainHTTP bool) (Store, error)
- func NewS3(client *minio.Client, bucket, prefix string) Store
- func WithHeadCache(s Store, dir string) Store
Constants ¶
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 ¶
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
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 NewS3Client ¶
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 ¶
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 ValidateObject ¶
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.
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 NewOCI ¶
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. 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. |