discovery

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package discovery serves artifact List and Search from a source-scoped discovery cache and optional catalogs, without ever downloading a payload.

Directory, archive, and OCI layout repositories enumerate their managed records locally and are always listed live. Remote repositories (S3 and OCI registries) are listed once per fifteen minutes: the entries are stored as a snapshot under the XDG cache directory (atmos/artifacts/discovery), scoped by the effective authentication configuration, realm, and host bindings, never by credential values, and replaced atomically only after a complete refresh. A fresh snapshot answers a request with zero repository requests. An explicit refresh revalidates the source and reuses the metadata of references whose resolved digest is unchanged. Offline mode serves only an existing valid snapshot and fails on a missing or corrupt one.

A registry cannot be portably enumerated, so a collection listing of an OCI registry uses the registry's repository catalog scoped to the repository prefix when it provides one, or the catalog configured on the repository. Listing the versions of one explicit name needs neither. A collection that cannot be enumerated fails with an unsupported-capability error; it is never an empty successful result.

Catalogs and snapshots are discoverable data, never trust grants. The current policy is re-evaluated on every read, including a read of a cached snapshot, and every catalog entry must be bound to the destination repository's path.

The shared snapshot mechanics live in the neutral cache subpackage, which plugin discovery also uses; the artifact-specific schema and policy live here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScopeOf

func ScopeOf(config *schema.AtmosConfiguration) (string, error)

ScopeOf returns the cache scope of a configuration: a hash of the authentication configuration, the effective authentication realm, and the identity bound to each repository. Credentials never enter it. A snapshot written under one scope is invisible under another, so a different realm, auth configuration, or identity binding can never reuse another's discovery data.

Types

type Discovery

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

Discovery implements service.Enumerator over the shared discovery cache and optional catalogs.

func New

func New(scope func() (string, error), opts ...Option) *Discovery

New returns a discovery cache. The scope function is called once, on first use, so building the service performs no file or network access; compose supplies ScopeOf bound to the configuration.

func (*Discovery) Enumerate

func (d *Discovery) Enumerate(ctx context.Context, request *service.EnumerateRequest) (*service.Enumeration, error)

Enumerate implements service.Enumerator.

type LocationPolicy

type LocationPolicy struct{}

LocationPolicy is the default policy. A repository must be readable, and every entry that came from a catalog must be bound to the destination repository path: a catalog is discoverable data and can never direct the repository's identity to another registry or path.

func (LocationPolicy) AuthorizeEntries

func (LocationPolicy) AuthorizeEntries(_ context.Context, check *SourceCheck, entries []artifact.ListEntry) error

AuthorizeEntries implements Policy.

func (LocationPolicy) AuthorizeSource

func (LocationPolicy) AuthorizeSource(_ context.Context, check *SourceCheck) error

AuthorizeSource implements Policy.

type Option

type Option func(*Discovery)

Option customizes a Discovery.

func WithClock

func WithClock(now func() time.Time) Option

WithClock injects the clock that stamps and ages snapshots.

func WithDirectory

func WithDirectory(directory string) Option

WithDirectory sets the snapshot directory. The default is the XDG cache directory atmos/artifacts/discovery.

func WithMaxSize

func WithMaxSize(size int64) Option

WithMaxSize bounds one snapshot file in bytes.

func WithOffline

func WithOffline(offline func(info *service.RepositoryInfo) bool) Option

WithOffline decides, per repository, whether discovery is offline. Offline discovery serves only an existing valid snapshot and never contacts a repository; a refresh is rejected.

func WithPolicy

func WithPolicy(policy Policy) Option

WithPolicy replaces the default LocationPolicy.

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets how long a snapshot stays fresh. The default is fifteen minutes.

type Policy

type Policy interface {
	// AuthorizeSource runs before a snapshot is served from cache and before a source is read.
	AuthorizeSource(ctx context.Context, check *SourceCheck) error

	// AuthorizeEntries runs on the entries about to be returned, cached or fresh.
	AuthorizeEntries(ctx context.Context, check *SourceCheck, entries []artifact.ListEntry) error
}

Policy decides whether a discovery source may be used now. It is evaluated on every read, so a policy that changed since a snapshot was written applies to the cached data too: a snapshot is never an authorization.

type SourceCheck

type SourceCheck struct {
	// Alias is the configured repository alias.
	Alias string

	// Info describes the repository.
	Info *service.RepositoryInfo

	// Kind is "collection", "named", or "catalog".
	Kind string

	// Reference is the source reference: the repository location, or the catalog reference.
	Reference string

	// Cached reports that the read is served from a snapshot rather than the source.
	Cached bool
}

SourceCheck identifies one discovery source to a Policy.

Directories

Path Synopsis
Package cache provides neutral, source-scoped discovery snapshots shared by plugin discovery and artifact discovery.
Package cache provides neutral, source-scoped discovery snapshots shared by plugin discovery and artifact discovery.
Package catalog maintains optional artifact catalogs: discovery snapshots published as generic artifact Records of kind "catalog" (artifact type application/vnd.atmos.artifact.catalog.v1) with one direct JSON payload layer (application/vnd.atmos.artifact.catalog.v1+json).
Package catalog maintains optional artifact catalogs: discovery snapshots published as generic artifact Records of kind "catalog" (artifact type application/vnd.atmos.artifact.catalog.v1) with one direct JSON payload layer (application/vnd.atmos.artifact.catalog.v1+json).
internal
testkit
Package testkit provides in-process registries and publication helpers for discovery and catalog tests: an OCI registry that counts every request, repositories bound to it, and a deterministic way to publish small packages.
Package testkit provides in-process registries and publication helpers for discovery and catalog tests: an OCI registry that counts every request, repositories bound to it, and a deterministic way to publish small packages.

Jump to

Keyboard shortcuts

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