oci

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingCatalogBase error = MissingCatalogBaseError{}

ErrMissingCatalogBase is the zero-value sentinel for errors.Is.

View Source
var ErrNotAManifest error = NotAManifestError{}
View Source
var ErrNotAnImageIndex error = NotAnImageIndexError{}
View Source
var ErrUnexpectedMediaType error = UnexpectedMediaTypeError{}
View Source
var ErrUnsupportedPlatform error = UnsupportedPlatformError{}

Functions

func IsRelative

func IsRelative(ref string) bool

IsRelative reports whether ref lacks a registry/repository base — i.e. it is empty, or begins with ":" (tag) or "@" (digest).

func JoinRef

func JoinRef(repository, reference string) string

JoinRef appends reference to a repository with the separator the reference implies: "@" for a digest, ":" for a tag.

func OpenArchive

func OpenArchive(ctx context.Context, c Client, ref string, platform Platform) (io.ReadCloser, int64, error)

OpenArchive pulls ref (which must be an OCI Image Index), selects the entry matching platform, fetches that per-platform manifest, and streams its single layer blob.

func OpenSource

func OpenSource(ctx context.Context, c Client, ref string) (io.ReadCloser, int64, error)

OpenSource pulls ref (which must be a plain image manifest) and streams its single layer blob. Source is platform-independent, so there is no selection.

func PullArtifactBytes

func PullArtifactBytes(ctx context.Context, c Client, ref, wantMediaType string) ([]byte, error)

PullArtifactBytes pulls the single-layer image manifest at ref, verifies the top manifest against ref's digest when ref is digest-pinned, rejects an image index, requires the layer's media type to equal wantMediaType, verifies the layer blob against its descriptor (digest + size), and returns the fully-read bytes. Pass wantMediaType == "" to skip the media-type check.

func ResolveRef

func ResolveRef(rawRef, kind, name, base string) (string, error)

ResolveRef turns an authored oci.ref template into an absolute ref template (still containing any {{.Version}} placeholder). kind is "archives" or "sources"; base is the catalog base ("" when none is available). A relative ref with no base yields MissingCatalogBaseError.

func SplitRef

func SplitRef(ref string) (name, reference string)

SplitRef splits an absolute reference "<name>[:<tag>][@<digest>]" into the repository name and the reference (digest if present, else tag). A registry port colon (e.g. "localhost:5000/foo") is not mistaken for a tag.

func WithDefaultTag

func WithDefaultTag(ref string) string

WithDefaultTag appends ":{{.Version}}" when ref carries neither a tag nor a digest. An empty ref becomes the bare default tag.

Types

type Client

type Client interface {
	// PullManifest fetches the manifest addressed by ref (its tag or digest).
	PullManifest(ctx context.Context, ref string) ([]byte, ocispec.Descriptor, error)
	// PullManifestByDigest fetches a manifest by digest from ref's repository.
	PullManifestByDigest(ctx context.Context, ref, digest string) ([]byte, error)
	// PullBlob fetches a blob described by target from ref's repository.
	PullBlob(ctx context.Context, ref string, target ocispec.Descriptor) (io.ReadCloser, int64, error)
}

Client is the minimal ORAS surface OpenArchive/OpenSource need. Every method is scoped to the repository named in ref.

func NewClient

func NewClient(cred CredentialFunc, opts ...Option) Client

NewClient builds a Client that pulls from OCI registries using cred.

type CredentialFunc

type CredentialFunc func(ctx context.Context, host string) (orasauth.Credential, error)

CredentialFunc returns registry credentials for a host, in oras-go's shape.

func Keychain

func Keychain(resolver auth.Resolver) CredentialFunc

Keychain composes credentials: the Docker credential store first, then the nem resolver's per-registry fallback, then anonymous. The Docker store loads lazily and memoized; a load failure degrades to the nem/anonymous path.

type MissingCatalogBaseError

type MissingCatalogBaseError struct {
	Package string
}

MissingCatalogBaseError reports a relative oci.ref used where no catalog base is available to resolve it (e.g. a git or local-dir catalog).

func (MissingCatalogBaseError) Error

func (e MissingCatalogBaseError) Error() string

func (MissingCatalogBaseError) Is

func (e MissingCatalogBaseError) Is(target error) bool

type NotAManifestError

type NotAManifestError struct{ Ref, Got string }

NotAManifestError reports that a source ref resolved to an image index rather than a plain image manifest.

func (NotAManifestError) Error

func (e NotAManifestError) Error() string

func (NotAManifestError) Is

func (e NotAManifestError) Is(target error) bool

type NotAnImageIndexError

type NotAnImageIndexError struct{ Ref, Got string }

NotAnImageIndexError reports that an archive ref resolved to a media type other than an OCI image index.

func (NotAnImageIndexError) Error

func (e NotAnImageIndexError) Error() string

func (NotAnImageIndexError) Is

func (e NotAnImageIndexError) Is(target error) bool

type Option

type Option func(*realClient)

Option configures a Client built by NewClient.

func WithPlainHTTP

func WithPlainHTTP() Option

WithPlainHTTP makes the client use http:// (for local registries / tests).

type Platform

type Platform struct {
	OS   string
	Arch string
}

Platform is the runtime target used to select an archive from an Image Index.

type UnexpectedMediaTypeError

type UnexpectedMediaTypeError struct {
	Ref  string
	Want string
	Got  string
}

UnexpectedMediaTypeError reports that a single-layer artifact's layer carried a media type other than the one the caller required.

func (UnexpectedMediaTypeError) Error

func (e UnexpectedMediaTypeError) Error() string

func (UnexpectedMediaTypeError) Is

func (e UnexpectedMediaTypeError) Is(target error) bool

type UnsupportedPlatformError

type UnsupportedPlatformError struct {
	Ref       string
	Want      Platform
	Available []Platform
}

UnsupportedPlatformError reports that an image index contained no entry matching the requested platform.

func (UnsupportedPlatformError) Error

func (e UnsupportedPlatformError) Error() string

func (UnsupportedPlatformError) Is

func (e UnsupportedPlatformError) Is(target error) bool

Jump to

Keyboard shortcuts

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