Documentation
¶
Index ¶
- Constants
- func BestTag(tags []string, constraint string) (string, error)
- func BundleToTarGz(fsys fs.FS) ([]byte, error)
- func ExportedUserHomeDirFn() func() (string, error)
- func FilterSemverTags(tags []string) []string
- func HasExplicitTag(ref string) bool
- func NewKeychain(opts CredentialOptions) authn.Keychain
- func PactoConfigDir() (string, error)
- func PactoConfigPath() (string, error)
- func ResolveRef(ctx context.Context, lister TagLister, ref, constraint string) (string, error)
- func SetUserHomeDirFn(fn func() (string, error)) func() (string, error)
- type ArtifactNotFoundError
- type AuthenticationError
- type BundleStore
- type CachedStore
- func (c *CachedStore) CacheDir() string
- func (c *CachedStore) DisableCache()
- func (c *CachedStore) ListTags(ctx context.Context, repo string) ([]string, error)
- func (c *CachedStore) Pull(ctx context.Context, ref string) (*contract.Bundle, error)
- func (c *CachedStore) Push(ctx context.Context, ref string, bundle *contract.Bundle) (string, error)
- func (c *CachedStore) Resolve(ctx context.Context, ref string) (string, error)
- type Client
- func (c *Client) ListTags(ctx context.Context, repo string) ([]string, error)
- func (c *Client) Pull(ctx context.Context, ref string) (*contract.Bundle, error)
- func (c *Client) Push(ctx context.Context, ref string, bundle *contract.Bundle) (string, error)
- func (c *Client) Resolve(ctx context.Context, ref string) (string, error)
- type ClientOption
- type CredentialOptions
- type InvalidBundleError
- type InvalidRefError
- type NoMatchingVersionError
- type PactoAuth
- type PactoConfig
- type RegistryUnreachableError
- type ResolveMode
- type Resolver
- func (r *Resolver) FetchAllVersions(ctx context.Context, ref string) ([]string, error)
- func (r *Resolver) ListVersions(ctx context.Context, ref string) ([]string, error)
- func (r *Resolver) Resolve(ctx context.Context, ref string, mode ResolveMode) (*contract.Bundle, error)
- func (r *Resolver) ResolveConstrained(ctx context.Context, ref, constraint string, mode ResolveMode) (*contract.Bundle, error)
- type TagLister
Constants ¶
const (
LayerMediaType = types.MediaType("application/vnd.pacto.bundle.layer.v1.tar+gzip")
)
Variables ¶
This section is empty.
Functions ¶
func BestTag ¶
BestTag selects the highest semver tag from tags. If constraint is non-empty, only tags satisfying the semver constraint are considered.
func BundleToTarGz ¶
BundleToTarGz creates a tar.gz archive of all files in the bundle FS. Used by the pack command to produce a local archive.
func ExportedUserHomeDirFn ¶
ExportedUserHomeDirFn returns the current userHomeDirFn for testing.
func FilterSemverTags ¶
FilterSemverTags returns only valid semver tags, sorted descending (latest first).
func HasExplicitTag ¶
HasExplicitTag reports whether an OCI reference includes an explicit tag or digest (e.g. "repo:v1" or "repo@sha256:...").
func NewKeychain ¶
func NewKeychain(opts CredentialOptions) authn.Keychain
NewKeychain builds a keychain that tries, in order: 1. Explicit credentials (flags/env vars) 2. Pacto config (~/.config/pacto/config.json) 3. gh CLI token (for GitHub registries) 4. Docker config, credential helpers, and cloud auto-detection
func PactoConfigDir ¶
PactoConfigDir returns the pacto configuration directory. It respects $XDG_CONFIG_HOME, defaulting to ~/.config/pacto.
func PactoConfigPath ¶
PactoConfigPath returns the path to pacto's dedicated config file. It respects $XDG_CONFIG_HOME, defaulting to ~/.config/pacto/config.json.
func ResolveRef ¶
ResolveRef resolves an OCI reference that may be missing a tag by querying available tags and selecting the best semver match. If the ref already has an explicit tag or digest, it is returned unchanged.
Types ¶
type ArtifactNotFoundError ¶
ArtifactNotFoundError indicates the reference does not exist (404).
func (*ArtifactNotFoundError) Error ¶
func (e *ArtifactNotFoundError) Error() string
func (*ArtifactNotFoundError) Unwrap ¶
func (e *ArtifactNotFoundError) Unwrap() error
type AuthenticationError ¶
AuthenticationError indicates credential rejection (401/403).
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
func (*AuthenticationError) Unwrap ¶
func (e *AuthenticationError) Unwrap() error
type BundleStore ¶
type BundleStore interface {
Push(ctx context.Context, ref string, bundle *contract.Bundle) (string, error)
Pull(ctx context.Context, ref string) (*contract.Bundle, error)
Resolve(ctx context.Context, ref string) (string, error)
ListTags(ctx context.Context, repo string) ([]string, error)
}
BundleStore handles push and pull of contract bundles to/from OCI registries.
type CachedStore ¶
type CachedStore struct {
// contains filtered or unexported fields
}
CachedStore wraps a BundleStore with in-memory and disk caching. Pulled bundles are kept in memory (fastest) and persisted to disk under ~/.cache/pacto/oci/ so they survive across process invocations. ListTags results are cached in memory for the lifetime of the process.
func NewCachedStore ¶
func NewCachedStore(inner BundleStore) *CachedStore
NewCachedStore creates a BundleStore that caches pulled bundles on disk. If the cache directory cannot be determined, caching is silently disabled.
func (*CachedStore) CacheDir ¶
func (c *CachedStore) CacheDir() string
CacheDir returns the resolved on-disk cache directory (e.g. ~/.cache/pacto/oci). Returns empty string if no cache directory could be determined at creation time.
func (*CachedStore) DisableCache ¶
func (c *CachedStore) DisableCache()
DisableCache skips reading from the disk cache (cold-start mode) and clears the in-memory cache. Disk writes remain enabled so that same-session pulls (e.g. fetch-all-versions) are still persisted and available for enrichment.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements BundleStore using go-containerregistry.
func NewClient ¶
func NewClient(keychain authn.Keychain, opts ...ClientOption) *Client
NewClient creates a new OCI client with the given keychain.
func (*Client) Pull ¶
Pull fetches an OCI image from the given reference and converts it to a Bundle.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures the OCI Client.
func WithNameOptions ¶
func WithNameOptions(opts ...name.Option) ClientOption
WithNameOptions adds name.Option values used when parsing OCI references.
func WithRemoteOptions ¶
func WithRemoteOptions(opts ...remote.Option) ClientOption
WithRemoteOptions adds remote.Option values used for all remote operations.
type CredentialOptions ¶
CredentialOptions holds explicit credentials provided via CLI flags or env vars.
type InvalidBundleError ¶
InvalidBundleError indicates the pulled artifact is not a valid Pacto bundle.
func (*InvalidBundleError) Error ¶
func (e *InvalidBundleError) Error() string
func (*InvalidBundleError) Unwrap ¶
func (e *InvalidBundleError) Unwrap() error
type InvalidRefError ¶
InvalidRefError indicates the OCI reference could not be parsed.
func (*InvalidRefError) Error ¶
func (e *InvalidRefError) Error() string
func (*InvalidRefError) Unwrap ¶
func (e *InvalidRefError) Unwrap() error
type NoMatchingVersionError ¶
NoMatchingVersionError indicates no tags satisfy the compatibility constraint.
func (*NoMatchingVersionError) Error ¶
func (e *NoMatchingVersionError) Error() string
func (*NoMatchingVersionError) Unwrap ¶
func (e *NoMatchingVersionError) Unwrap() error
type PactoAuth ¶
type PactoAuth struct {
Auth string `json:"auth"`
}
PactoAuth represents a single registry auth entry.
type PactoConfig ¶
PactoConfig represents the structure of pacto's config.json file.
type RegistryUnreachableError ¶
RegistryUnreachableError indicates a network or DNS failure.
func (*RegistryUnreachableError) Error ¶
func (e *RegistryUnreachableError) Error() string
func (*RegistryUnreachableError) Unwrap ¶
func (e *RegistryUnreachableError) Unwrap() error
type ResolveMode ¶
type ResolveMode int
ResolveMode controls whether remote fetching is allowed.
const ( // LocalOnly restricts resolution to the local disk cache. LocalOnly ResolveMode = iota // RemoteAllowed permits fetching from the OCI registry on cache miss. RemoteAllowed )
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver provides lazy, on-demand resolution of Pacto bundles from OCI references. It checks the local disk cache first and optionally falls back to pulling from the remote registry.
func NewResolver ¶
func NewResolver(store BundleStore) *Resolver
NewResolver creates a Resolver backed by the given BundleStore. The store should be a CachedStore so that successful pulls persist to disk.
func (*Resolver) FetchAllVersions ¶
FetchAllVersions lists all semver tags for the given OCI repo reference and pulls each one, ensuring they are cached by the underlying BundleStore. Returns the version list sorted descending (latest first).
func (*Resolver) ListVersions ¶
ListVersions returns all semver tags available for the given OCI repo reference. The ref should be untagged (e.g. "ghcr.io/org/svc-pacto"). Non-semver tags are excluded. Results are sorted descending (latest first).
func (*Resolver) Resolve ¶
func (r *Resolver) Resolve(ctx context.Context, ref string, mode ResolveMode) (*contract.Bundle, error)
Resolve fetches a Pacto bundle for the given OCI reference.
In LocalOnly mode, only the disk cache is checked. In RemoteAllowed mode, a cache miss triggers a pull from the registry.
Errors are typed:
- *InvalidRefError: ref cannot be parsed
- *ArtifactNotFoundError: not in registry (404)
- *AuthenticationError: credentials rejected (401/403)
- *RegistryUnreachableError: network/DNS failure
- *InvalidBundleError: pulled artifact is not a valid Pacto bundle
func (*Resolver) ResolveConstrained ¶
func (r *Resolver) ResolveConstrained(ctx context.Context, ref, constraint string, mode ResolveMode) (*contract.Bundle, error)
ResolveConstrained fetches a Pacto bundle, resolving untagged refs using the compatibility constraint to select the best matching version from the OCI registry's available tags.
If the ref already has an explicit tag or digest, the constraint is ignored. If the ref is untagged and constraint is empty, the highest semver tag is used.
Additional error type:
- *NoMatchingVersionError: no tags satisfy the constraint