Help us shape the future of Go! Take the 2026 Go Developer Survey

ociregistry

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package ociregistry embeds a Docker Registry v2 / OCI distribution server, shared by the ECR, Azure Container Registry and Artifact Registry emulators.

Index

Constants

View Source
const (
	OpRead   = "read"
	OpWrite  = "write"
	OpDelete = "delete"
)

Operations a ledger entry can forbid.

View Source
const DefaultMaxRequestBytes int64 = 8 << 30

DefaultMaxRequestBytes bounds a single upload request body (one monolithic PUT or one PATCH chunk).

Variables

View Source
var ErrNotFound = errors.New("ociregistry: not found")

ErrNotFound is returned when a repository, manifest or blob does not exist.

View Source
var ErrNullEntry = errors.New("ociregistry: null ledger entry")

ErrNullEntry is returned by Normalize when a repository entry is null.

View Source
var ErrRegistry = errors.New("ociregistry: registry error")

ErrRegistry is returned when the registry answers with an unexpected error status.

View Source
var ErrTooLarge = errors.New("ociregistry: blob too large")

ErrTooLarge is returned when a blob exceeds the size the caller allowed.

Functions

func IsDigest

func IsDigest(ref string) bool

IsDigest reports whether a manifest reference is a digest rather than a tag.

func IsIndexType

func IsIndexType(mediaType string) bool

IsIndexType reports whether mediaType is a manifest list or OCI index.

func Limit

func Limit(next http.Handler, maxBytes int64) http.Handler

Limit rejects request bodies larger than maxBytes (DefaultMaxRequestBytes when zero) with a 413-style read error instead of streaming them into storage without bound.

func New

func New(parent context.Context, opts Options) http.Handler

New builds a registry http.Handler with deletes enabled and no authentication. The result is a *handlers.App, whose Shutdown() error releases the library's resources.

func ServeObserved

func ServeObserved(app http.Handler, w http.ResponseWriter, r *http.Request, obs Observer)

ServeObserved serves r through app, reporting manifest writes and deletes to obs.

func Shutdown

func Shutdown(h http.Handler)

Shutdown releases a registry built by New; other handlers are ignored.

func SplitManifestPath

func SplitManifestPath(path string) (string, string, bool)

SplitManifestPath parses /v2/<repo>/manifests/<ref>; ok is false for every other path.

Types

type Attrs

type Attrs struct {
	DeleteDisabled bool `json:"deleteDisabled,omitempty"`
	WriteDisabled  bool `json:"writeDisabled,omitempty"`
	ReadDisabled   bool `json:"readDisabled,omitempty"`
	ListDisabled   bool `json:"listDisabled,omitempty"`
}

Attrs are the changeable attributes of a repository, manifest or tag. The zero value enables everything.

func (Attrs) Allows

func (a Attrs) Allows(op string) bool

Allows reports whether op is enabled.

type Client

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

Client calls a registry handler in-process, bypassing any authentication in front of it.

func NewClient

func NewClient(h http.Handler) Client

NewClient returns a Client for h.

func (Client) Catalog

func (c Client) Catalog(ctx context.Context) ([]string, error)

Catalog lists every repository that holds content, in lexical order.

func (Client) DeleteManifest

func (c Client) DeleteManifest(ctx context.Context, repo, digest string) error

DeleteManifest removes the manifest with the given digest (and every tag pointing at it).

func (Client) Describe

func (c Client) Describe(ctx context.Context, repo string, m Manifest) Info

Describe parses a manifest and, for an image manifest, reads its config blob for the platform.

func (Client) GetBlob

func (c Client) GetBlob(ctx context.Context, repo, digest string, maxBytes int64) ([]byte, error)

GetBlob fetches a blob, failing with ErrTooLarge past maxBytes.

func (Client) GetManifest

func (c Client) GetManifest(ctx context.Context, repo, ref string) (Manifest, error)

GetManifest fetches the manifest at repo:ref, where ref is a tag or a digest.

func (Client) PutManifest

func (c Client) PutManifest(ctx context.Context, repo, ref, mediaType string, body []byte) (string, error)

PutManifest stores body as repo:ref (a tag or digest) and returns its digest.

func (Client) Tags

func (c Client) Tags(ctx context.Context, repo string) ([]string, error)

Tags lists the tags of repo, in lexical order. A repository with no content has none.

type Descriptor

type Descriptor struct {
	Digest    string `json:"digest"`
	MediaType string `json:"mediaType"`
	Size      int64  `json:"size"`
}

Descriptor is the part of a manifest entry used for sizing and platform lookup.

type Info

type Info struct {
	Digest          string
	MediaType       string
	ConfigMediaType string
	Architecture    string
	OS              string
	Children        []Descriptor
	Size            int64
	Index           bool
}

Info summarises a manifest.

type Ledger

type Ledger map[string]*RepoEntry

Ledger records when manifests and tags were pushed, which the registry itself does not keep. Repositories disappear from it with their last manifest. It is not safe for concurrent use: callers hold their own lock.

func (Ledger) Allowed

func (l Ledger) Allowed(repo, ref, op string) bool

Allowed reports whether op may touch repo:ref. An operation on a digest also needs every tag pointing at it to allow it.

func (Ledger) Normalize

func (l Ledger) Normalize() error

Normalize fills nil maps after a decode and rejects null entries.

func (Ledger) RecordDelete

func (l Ledger) RecordDelete(repo, ref string)

RecordDelete forgets a deleted manifest with its tags, or just the tag when ref is one.

func (Ledger) RecordPut

func (l Ledger) RecordPut(repo, ref, digest string, now time.Time)

RecordPut notes a stored manifest, and the tag when ref is one.

type Manifest

type Manifest struct {
	Digest    string
	MediaType string
	Body      []byte
}

Manifest is a stored manifest.

type ManifestEntry

type ManifestEntry struct {
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
	Attrs   Attrs     `json:"attrs"`
}

ManifestEntry is a manifest's ledger entry.

type Observer

type Observer struct {
	// Permit may refuse a manifest read, write or delete; it must write the error response itself.
	Permit func(w http.ResponseWriter, repo, ref, op string) bool
	// Put runs after a manifest is stored (201); digest is the stored manifest's digest.
	Put func(repo, ref, digest string)
	// Delete runs after a manifest or tag is deleted (202).
	Delete func(repo, ref string)
}

Observer hooks manifest traffic passing through ServeObserved. Every field is optional.

type Options

type Options struct {
	// InstanceID labels the registry in the distribution library's logs.
	InstanceID string
	// RootDir keeps blobs and manifests on disk under this directory; empty keeps them in memory.
	RootDir string
}

Options configures a registry.

type RepoEntry

type RepoEntry struct {
	Created   time.Time                 `json:"created"`
	Updated   time.Time                 `json:"updated"`
	Manifests map[string]*ManifestEntry `json:"manifests"`
	Tags      map[string]*TagEntry      `json:"tags"`
	Attrs     Attrs                     `json:"attrs"`
}

RepoEntry is a repository's ledger entry.

type TagEntry

type TagEntry struct {
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
	Digest  string    `json:"digest"`
	Attrs   Attrs     `json:"attrs"`
}

TagEntry is a tag's ledger entry.

Directories

Path Synopsis
Package ocitest drives a Docker Registry v2 endpoint with the push, pull, delete and listing calls a registry client makes, so each registry emulator proves the same conformance behaviour.
Package ocitest drives a Docker Registry v2 endpoint with the push, pull, delete and listing calls a registry client makes, so each registry emulator proves the same conformance behaviour.

Jump to

Keyboard shortcuts

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