ocifilter

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ocifilter implements "filter" functions that wrap or combine oci implementations in different ways.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessChecker

func AccessChecker(r oci.Interface, check func(repoName string, access AccessKind) error) oci.Interface

AccessChecker returns a wrapper for r that invokes check to check access before calling an underlying method. Only if check succeeds will the underlying method be called.

The check function is invoked with the name of the repository being accessed (or "*" for Repositories), and the kind of access required. For some methods (e.g. Mount), check might be invoked more than once for a given repository.

When invoking the Repositories method, check is invoked for each repository in the iteration - the repository will be omitted if check returns an error.

func Immutable

func Immutable(r oci.Interface) oci.Interface

Immutable returns a registry wrap r but only allows content to be added but not changed once added: nothing can be deleted and tags can't be changed.

func ReadOnly

func ReadOnly(r oci.Interface) oci.Interface

ReadOnly returns a registry implementation that returns an "operation unsupported" error from all entry points that mutate the registry.

func Select

func Select(r oci.Interface, allow func(repoName string) bool) oci.Interface

Select returns a wrapper for r that provides only repositories for which allow returns true.

Requests for disallowed repositories will return ErrNameUnknown errors on read and ErrDenied on write.

func Selector added in v0.0.19

func Selector(selectRegistry func(repo string) oci.Interface) oci.Interface

Selector returns a registry that delegates each operation to the registry returned by selectRegistry. The selector is passed the repository name for the operation, and that name is passed unchanged to the selected registry. The selector may be called concurrently and must be safe for concurrent use.

For oci.Writer.MountBlob, the registry is selected using the destination repository, toRepo; both fromRepo and toRepo are then passed unchanged to that registry. Whether a mount across repositories with different storage backends succeeds is determined by the selected registry.

oci.Extension.Repositories returns an error wrapping oci.ErrUnsupported, because it has no repository name with which to select a registry.

Selector does not validate selectRegistry. It panics when an operation is attempted if selectRegistry is nil or returns a nil registry.

Example
local := &oci.Funcs{
	DeleteTag_: func(_ context.Context, repo, tag string) error {
		fmt.Printf("local: %s:%s\n", repo, tag)
		return nil
	},
}
remote := &oci.Funcs{
	DeleteTag_: func(_ context.Context, repo, tag string) error {
		fmt.Printf("remote: %s:%s\n", repo, tag)
		return nil
	},
}
r := Selector(func(repo string) oci.Interface {
	namespace, _, _ := strings.Cut(repo, "/")
	if namespace == "local" {
		return local
	}
	return remote
})

_ = r.DeleteTag(context.Background(), "local/example", "latest")
_ = r.DeleteTag(context.Background(), "shared/example", "latest")
Output:
local: local/example:latest
remote: shared/example:latest

func Sub

func Sub(r oci.Interface, pathPrefix string) oci.Interface

Sub returns r wrapped so that it addresses only repositories within pathPrefix.

The prefix must match an entire path element so, for example, if the prefix is "foo", "foo" and "foo/a" will be included, but "foobie" will not.

For example, if r has the following repositories:

a
a/b/c
a/d
x/p
aa/b

then Sub(r "a") will return a registry containing the following repositories:

b/c
d

Types

type AccessKind

type AccessKind int

AccessKind represents the type of access being performed on a registry.

const (
	// AccessRead represents [oci.Reader] methods.
	AccessRead AccessKind = iota

	// AccessWrite represents [oci.Writer] methods.
	AccessWrite

	// AccessDelete represents [oci.Deleter] methods.
	AccessDelete

	// AccessList represents [oci.Lister] methods.
	AccessList
)

Jump to

Keyboard shortcuts

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