modregistry

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package modregistry provides functionality for reading and writing CUE modules from an OCI registry.

WARNING: THIS PACKAGE IS EXPERIMENTAL. ITS API MAY CHANGE AT ANY TIME.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("module not found")

Functions

This section is empty.

Types

type Client

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

Client represents a OCI-registry-backed client that provides a store for CUE modules.

func NewClient

func NewClient(registry ociregistry.Interface) *Client

NewClient returns a new client that talks to the registry at the given hostname.

func NewClientWithResolver

func NewClientWithResolver(resolver Resolver) *Client

NewClientWithResolver returns a new client that uses the given resolver to decide which registries to fetch from or push to.

func (*Client) GetModule

func (c *Client) GetModule(ctx context.Context, m module.Version) (*Module, error)

GetModule returns the module instance for the given version. It returns an error that satisfies errors.Is(ErrNotFound) if the module is not present in the store at this version.

func (*Client) GetModuleWithManifest

func (c *Client) GetModuleWithManifest(ctx context.Context, m module.Version, contents []byte, mediaType string) (*Module, error)

GetModuleWithManifest returns a module instance given the top level manifest contents, without querying its tag. It assumes that the module will be tagged with the given version.

func (*Client) ModuleVersions

func (c *Client) ModuleVersions(ctx context.Context, m string) ([]string, error)

ModuleVersions returns all the versions for the module with the given path sorted in semver order. If m has a major version suffix, only versions with that major version will be returned.

func (*Client) PutModule

func (c *Client) PutModule(ctx context.Context, m module.Version, r io.ReaderAt, size int64) error

PutModule puts a module whose contents are held as a zip archive inside f. It assumes all the module dependencies are correctly resolved and present inside the cue.mod/module.cue file.

TODO check deps are resolved correctly? Or is that too domain-specific for this package? Is it a problem to call zip.CheckZip twice?

type Module

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

Module represents a CUE module instance.

func (*Module) GetZip

func (m *Module) GetZip(ctx context.Context) (io.ReadCloser, error)

GetZip returns a reader that can be used to read the contents of the zip archive containing the module files. The reader should be closed after use, and the contents should not be assumed to be correct until the close error has been checked.

func (*Module) ManifestDigest

func (m *Module) ManifestDigest() ociregistry.Digest

ManifestDigest returns the digest of the manifest representing the module.

func (*Module) ModuleFile

func (m *Module) ModuleFile(ctx context.Context) ([]byte, error)

ModuleFile returns the contents of the cue.mod/module.cue file.

func (*Module) Version

func (m *Module) Version() module.Version

type RegistryLocation

type RegistryLocation struct {
	// Registry holds the registry to use to access the module.
	Registry ociregistry.Interface
	// Repository holds the repository where the module is located.
	Repository string
	// Tag holds the tag for the module version. If an empty version
	// was passed to Resolve, it holds the prefix shared by all
	// version tags for the module.
	Tag string
}

RegistryLocation holds a registry and a location within it that a specific module (or set of versions for a module) will be stored.

type Resolver

type Resolver interface {
	// ResolveToRegistry resolves a base module path (without a version)
	// and optional version to the location for that path.
	//
	// If the version is empty, the Tag in the returned Location
	// will hold the prefix that all versions of the module in its
	// repository have. That prefix will be followed by the version
	// itself.
	ResolveToRegistry(mpath, vers string) (RegistryLocation, error)
}

Resolver resolves module paths to a registry and a location within that registry.

Jump to

Keyboard shortcuts

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