service

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: 26 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 service implements artifact.Service: the repository-independent orchestration of publish, pull, copy, inspect, list, search, delete, document reads, sign, verify, and pin over artifact.Repository implementations.

The service owns name and version selection, producer preparation, effective metadata, digest pinning, conflict policy, retries, and result aggregation; repositories own storage mechanics and capabilities. Three rules hold for every operation:

  • A mutable reference is resolved exactly once; every later read, verification, and copy uses the pinned subject, so a tag moved mid-operation can never substitute different bytes.
  • Capabilities and lock guarantees are checked before the first mutation, locks are acquired in canonical repository/resource order, and they are released on success, error, and cancellation.
  • Required verification runs before destination publication or local materialization, and force never bypasses it. Without any trust configuration the result is "unchecked", never "verified".

Every method returns its typed result alongside the error so reporting can describe completed work.

Package service is a generated GoMock package.

Index

Constants

View Source
const (
	// DefaultAttempts is the default number of publication attempts.
	DefaultAttempts = 3

	// DefaultBackoff is the default base delay between attempts; it doubles each attempt.
	DefaultBackoff = 200 * time.Millisecond
)

Defaults for retry behavior. Retries apply only to publications that failed with a temporary error and whose reconciliation proves nothing was committed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// Existing reports that the candidate is the artifact already stored (not the incoming one).
	Existing bool

	// Repository is the repository alias involved.
	Repository string

	// Inspection is the metadata view for every candidate, including prepared publications
	// and native copies. Policies must classify through this view; Record may be nil for
	// foreign graphs. Pinned is unset until a prepared publication is stored.
	Inspection *artifact.Inspection

	// Prepared optionally provides staged content. It is nil for native copies and stored
	// artifacts, so policies must not rely on it to classify an incoming release.
	Prepared *artifact.PreparedArtifact
}

Candidate is an artifact being considered for the immutability policy.

type ConfigRepositories

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

ConfigRepositories implements Repositories from the validated artifacts configuration and a repository kind registry. Describe reads only configuration and kind descriptors, so it never authenticates; Open constructs each repository once through the registry, which is where identities are resolved.

func FromConfig

FromConfig returns a Repositories backed by configuration. A nil registry uses the default repository registry.

func (*ConfigRepositories) Aliases

func (c *ConfigRepositories) Aliases() []string

Aliases implements Repositories.

func (*ConfigRepositories) Describe

func (c *ConfigRepositories) Describe(alias string) (RepositoryInfo, error)

Describe implements Repositories. For a repository that delegates locking, the lock scopes of the delegate are added to its capabilities, so the lock guarantee check sees what the delegate can provide.

func (*ConfigRepositories) Open

Open implements Repositories. Each repository is constructed once, and constructing one does not block opening another: callers waiting for the same alias share its construction and stop waiting when their own context ends. A failed construction is not cached, so a later Open retries it.

type DiscoveryInfo

type DiscoveryInfo struct {
	// Kind is the repository kind, for example "oci/registry".
	Kind string

	// Location is the credential-free collection root: "registry/prefix" for a registry, "s3://bucket/prefix"
	// for S3, and the directory for local and layout repositories.
	Location string

	// Catalog is the optional catalog reference ("oci://registry/path:tag"); empty when none is configured.
	Catalog string

	// Identity is the name of the Atmos identity bound to the repository; never a credential.
	Identity string

	// Options are the effective repository options. They hold no credentials.
	Options map[string]any
}

DiscoveryInfo is what discovery needs to know about a configured repository, without touching the network or resolving credentials. It never contains credential values.

func (*DiscoveryInfo) Remote

func (d *DiscoveryInfo) Remote() bool

Remote reports whether listing the repository crosses the network, which is what makes a discovery snapshot worthwhile. Local directories, archives, and layouts are always listed live.

type EnumerateRequest

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

	// Info is the repository description.
	Info *RepositoryInfo

	// Name restricts the listing to the versions of one exact name; empty enumerates the collection.
	Name string

	// Refresh bypasses a fresh snapshot.
	Refresh bool

	// Open opens the repository, resolving credentials. It is lazy so a cache hit never authenticates.
	Open func(ctx context.Context) (artifact.Repository, error)

	// Live lists the repository directly and consumes its pagination. The known entries, keyed by
	// resolved digest, let the repository reuse metadata of unchanged references.
	Live func(ctx context.Context, known map[digest.Digest]artifact.ListEntry) ([]artifact.ListEntry, error)
}

EnumerateRequest selects what an Enumerator lists.

type Enumeration

type Enumeration struct {
	// Entries are the unfiltered entries.
	Entries []artifact.ListEntry

	// Source is "live", "cache", or "catalog".
	Source string

	// FetchedAt is when a cached or catalog snapshot was fetched; zero for a live listing.
	FetchedAt time.Time

	// Diagnostics are non-fatal notes, for example that the entries come from a catalog.
	Diagnostics []artifact.Diagnostic
}

Enumeration is the result of Enumerator.Enumerate.

type Enumerator

type Enumerator interface {
	// Enumerate returns the unfiltered entries of the repository (or of one name). The service
	// applies label and text filters afterward, so a snapshot holds the whole collection.
	Enumerate(ctx context.Context, request *EnumerateRequest) (*Enumeration, error)
}

Enumerator supplies the entries of one repository for List and Search. The service falls back to reading the repository directly when no enumerator is configured. An enumerator owns caching: when a fresh snapshot answers the request it must not call EnumerateRequest.Live or open the repository.

type ImmutabilityFunc

type ImmutabilityFunc func(candidate Candidate) (bool, string)

ImmutabilityFunc adapts a function to ImmutabilityPolicy.

func (ImmutabilityFunc) Immutable

func (f ImmutabilityFunc) Immutable(candidate Candidate) (bool, string)

Immutable implements ImmutabilityPolicy.

type ImmutabilityPolicy

type ImmutabilityPolicy interface {
	// Immutable reports whether the candidate is in an immutable release format and why.
	Immutable(candidate Candidate) (bool, string)
}

ImmutabilityPolicy is the admission seam for immutable release formats. The OCI adapter supplies the plugin-format detector; the service consults it for both the stored artifact and the incoming one, so a generic operation can never overwrite a plugin release, with or without force.

type Journal

type Journal interface {
	// Record observes one lifecycle event. It must return promptly.
	Record(ctx context.Context, entry *JournalEntry)
}

Journal receives publication lifecycle events. The service never fails because of it, but it calls Record inline and in lifecycle order, because a recovery record must not be reordered or dropped. A slow Record therefore delays the publication, so an implementation must return promptly and hand any slow work to its own buffer or goroutine.

type JournalEntry

type JournalEntry struct {
	// OperationID is the logical operation identifier, stable across retries.
	OperationID string

	// Phase is the lifecycle step.
	Phase JournalPhase

	// Repository is the target repository alias.
	Repository string

	// Ref is the reference being mutated.
	Ref string

	// IntentDigest is the intent digest of the artifact being published.
	IntentDigest string

	// Attempt is the one-based publication attempt.
	Attempt int

	// Err is the failure for PhaseFailed.
	Err error
}

JournalEntry is one lifecycle event. It is an implementation recovery record, not a catalog.

type JournalPhase

type JournalPhase string

JournalPhase names a step in the publication lifecycle.

const (
	// PhasePrepared means the source snapshot and Record were sealed.
	PhasePrepared JournalPhase = "prepared"

	// PhaseLocked means the writer lock was acquired.
	PhaseLocked JournalPhase = "locked"

	// PhasePending means the publication is about to be handed to the repository.
	PhasePending JournalPhase = "pending"

	// PhaseCommitted means the repository confirmed completion.
	PhaseCommitted JournalPhase = "committed"

	// PhaseReconciled means an ambiguous failure was resolved by reading the completed reference.
	PhaseReconciled JournalPhase = "reconciled"

	// PhaseFailed means the operation failed without a committed publication.
	PhaseFailed JournalPhase = "failed"

	// PhaseReleased means the writer lock was released.
	PhaseReleased JournalPhase = "released"
)

Journal phases, in lifecycle order.

type MockImmutabilityPolicy

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

MockImmutabilityPolicy is a mock of ImmutabilityPolicy interface.

func NewMockImmutabilityPolicy

func NewMockImmutabilityPolicy(ctrl *gomock.Controller) *MockImmutabilityPolicy

NewMockImmutabilityPolicy creates a new mock instance.

func (*MockImmutabilityPolicy) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockImmutabilityPolicy) Immutable

func (m *MockImmutabilityPolicy) Immutable(candidate Candidate) (bool, string)

Immutable mocks base method.

type MockImmutabilityPolicyMockRecorder

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

MockImmutabilityPolicyMockRecorder is the mock recorder for MockImmutabilityPolicy.

func (*MockImmutabilityPolicyMockRecorder) Immutable

func (mr *MockImmutabilityPolicyMockRecorder) Immutable(candidate any) *gomock.Call

Immutable indicates an expected call of Immutable.

type MockJournal

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

MockJournal is a mock of Journal interface.

func NewMockJournal

func NewMockJournal(ctrl *gomock.Controller) *MockJournal

NewMockJournal creates a new mock instance.

func (*MockJournal) EXPECT

func (m *MockJournal) EXPECT() *MockJournalMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockJournal) Record

func (m *MockJournal) Record(ctx context.Context, entry *JournalEntry)

Record mocks base method.

type MockJournalMockRecorder

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

MockJournalMockRecorder is the mock recorder for MockJournal.

func (*MockJournalMockRecorder) Record

func (mr *MockJournalMockRecorder) Record(ctx, entry any) *gomock.Call

Record indicates an expected call of Record.

type MockRepacker

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

MockRepacker is a mock of Repacker interface.

func NewMockRepacker

func NewMockRepacker(ctrl *gomock.Controller) *MockRepacker

NewMockRepacker creates a new mock instance.

func (*MockRepacker) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRepacker) Repack

Repack mocks base method.

type MockRepackerMockRecorder

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

MockRepackerMockRecorder is the mock recorder for MockRepacker.

func (*MockRepackerMockRecorder) Repack

func (mr *MockRepackerMockRecorder) Repack(ctx, request any) *gomock.Call

Repack indicates an expected call of Repack.

type MockRepositories

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

MockRepositories is a mock of Repositories interface.

func NewMockRepositories

func NewMockRepositories(ctrl *gomock.Controller) *MockRepositories

NewMockRepositories creates a new mock instance.

func (*MockRepositories) Aliases

func (m *MockRepositories) Aliases() []string

Aliases mocks base method.

func (*MockRepositories) Describe

func (m *MockRepositories) Describe(alias string) (RepositoryInfo, error)

Describe mocks base method.

func (*MockRepositories) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRepositories) Open

Open mocks base method.

type MockRepositoriesMockRecorder

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

MockRepositoriesMockRecorder is the mock recorder for MockRepositories.

func (*MockRepositoriesMockRecorder) Aliases

func (mr *MockRepositoriesMockRecorder) Aliases() *gomock.Call

Aliases indicates an expected call of Aliases.

func (*MockRepositoriesMockRecorder) Describe

func (mr *MockRepositoriesMockRecorder) Describe(alias any) *gomock.Call

Describe indicates an expected call of Describe.

func (*MockRepositoriesMockRecorder) Open

func (mr *MockRepositoriesMockRecorder) Open(ctx, alias any) *gomock.Call

Open indicates an expected call of Open.

type Option

type Option func(*Service)

Option customizes a Service.

func WithClock

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

WithClock injects the clock. The service captures the time once per operation, in UTC.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets the transfer and discovery concurrency. The default is artifact.DefaultConcurrency.

func WithEnumerator

func WithEnumerator(enumerator Enumerator) Option

WithEnumerator routes List and Search through an enumerator (the discovery cache and catalogs).

func WithIDGenerator

func WithIDGenerator(newID func() string) Option

WithIDGenerator injects the operation ID generator.

func WithImmutabilityPolicy

func WithImmutabilityPolicy(policy ImmutabilityPolicy) Option

WithImmutabilityPolicy registers the immutable-format admission seam.

func WithJournal

func WithJournal(journal Journal) Option

WithJournal registers a lifecycle observer.

func WithOwner

func WithOwner(owner string) Option

WithOwner sets the lock owner recorded in claims, for example host and process.

func WithRepacker

func WithRepacker(repacker Repacker) Option

WithRepacker overrides the repacker used by Copy's staging fallback.

func WithRetry

func WithRetry(attempts int, backoff time.Duration) Option

WithRetry sets the number of publication attempts and the base backoff.

func WithSigner

func WithSigner(signer artifact.Signer) Option

WithSigner supplies the signer used by Sign.

func WithSleep

func WithSleep(sleep func(ctx context.Context, d time.Duration) error) Option

WithSleep injects the backoff sleep; tests use a no-op.

func WithStagingRoot

func WithStagingRoot(dir string) Option

WithStagingRoot sets the directory for bounded disk staging (preparation and copy trees).

type PublishOutcome

type PublishOutcome struct {
	// Operation is the typed operation result.
	Operation artifact.OperationResult

	// Record is the Record now published (the existing one on a no-op); it is empty on failure
	// before preparation and for dry runs holds the Record that would be published.
	Record artifact.Record

	// Existing reports an unchanged no-op that returned the stored Record.
	Existing bool
}

PublishOutcome is the detailed result of Service.PublishDetailed. On an unchanged no-op, Record is the EXISTING record, byte for byte, and Operation reports the current execution separately (its own operation ID and duration).

type Repacker

type Repacker interface {
	// Repack stages an existing Record from a materialized tree.
	Repack(ctx context.Context, request *produce.RepackRequest) (*artifact.PreparedArtifact, error)
}

Repacker rebuilds an existing Record for a different packaging. produce.Producer implements it.

type Repositories

type Repositories interface {
	// Describe returns the repository description without authenticating.
	Describe(alias string) (RepositoryInfo, error)

	// Open constructs (or returns a cached) repository, resolving credentials as needed.
	Open(ctx context.Context, alias string) (artifact.Repository, error)

	// Aliases lists every configured repository alias, sorted.
	Aliases() []string
}

Repositories resolves repository aliases. Describe must be free of network access and credential resolution so dry runs never authenticate; Open may resolve identities.

type RepositoryInfo

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

	// Capabilities describes the repository without network access. For a repository that
	// delegates locking, it already includes the delegate's lock scopes.
	Capabilities artifact.Capabilities

	// Packaging is the effective payload packaging mode for publications.
	Packaging artifact.Packaging

	// Defaults is defaults.metadata; its labels sit under explicit publication labels.
	Defaults artifact.Metadata

	// RequiredLockScope is locking.required_scope; empty means host.
	RequiredLockScope artifact.LockScope

	// LockProvider is the alias of the repository that provides write coordination when
	// locking.repository delegates it. Empty (or equal to Alias) means the repository locks itself.
	LockProvider string

	// Policy is the effective verification policy: the global and repository trust sets, both of
	// which must be satisfied.
	Policy artifact.VerificationPolicy

	// Discovery describes where the repository's discoverable data lives, for the discovery cache
	// and catalogs. It is empty for repositories described without configuration.
	Discovery DiscoveryInfo
}

RepositoryInfo is everything the service needs to know about a configured repository without touching the network or resolving credentials.

func (*RepositoryInfo) Clone

func (i *RepositoryInfo) Clone() RepositoryInfo

Clone returns a RepositoryInfo that shares no map, slice, or pointer with i, so a caller editing a description it received cannot change the configuration that produced it.

type Service

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

Service implements artifact.Service over repositories.

func New

func New(repos Repositories, producers *artifact.ProducerRegistry, opts ...Option) (*Service, error)

New returns a Service. With a nil producer registry, the built-in producers are available: the generic files producer and the scaffold and component/terraform producers.

func (*Service) Copy

Copy implements artifact.Service. The source reference is resolved once and verified against BOTH the source and destination policies before the destination is touched; force never bypasses that. A compatible native transfer is used when available, otherwise the bounded staging fallback repacks the unchanged Record for the destination's packaging.

func (*Service) Delete

Delete implements artifact.Service. Deletion is scoped to the pinned subject within the repository's declared delete capability and guarded by the writer locks. Digest references are inspected before locking to identify the canonical reference, then resolved again under lock.

func (*Service) Inspect

Inspect implements artifact.Service. It reads metadata only. Verification is reported when policy requires or constrains it; a failed or unchecked verification is information here, not a reason to hide metadata, because inspect consumes no payload.

func (*Service) List

func (s *Service) List(ctx context.Context, request artifact.ListRequest) (*artifact.ListResult, error)

List implements artifact.Service.

func (*Service) Pin

func (s *Service) Pin(ctx context.Context, request artifact.PinRequest) (*artifact.PinResult, error)

Pin implements artifact.Service. A pin is immutable reference data for consumer lockfiles; it acquires no write lock and is not a substitute for signature verification.

func (*Service) Publish

Publish implements artifact.Service.

func (*Service) PublishDetailed

func (s *Service) PublishDetailed(ctx context.Context, request artifact.PublishRequest) (*PublishOutcome, error)

PublishDetailed prepares the source and stores it in one repository, returning the Record alongside the typed operation result. The result is always non-nil, even on error.

func (*Service) Pull

Pull implements artifact.Service. It resolves the reference once, verifies the pinned subject against policy, refuses to overlay a different non-empty destination without force, extracts into staging, and only then replaces the destination.

func (*Service) Search

func (s *Service) Search(ctx context.Context, request artifact.SearchRequest) (*artifact.ListResult, error)

Search implements artifact.Service. The text is matched case-insensitively against names, kinds, descriptions, and label keys and values of the enumerated collection.

func (*Service) ShowDocument

func (s *Service) ShowDocument(ctx context.Context, request artifact.ShowDocumentRequest) (*artifact.DocumentResult, error)

ShowDocument implements artifact.Service. It never downloads the payload; the document bytes are bounded and verified against the Record descriptor.

func (*Service) Sign

func (s *Service) Sign(ctx context.Context, request artifact.SignRequest) (*artifact.SignResult, error)

Sign implements artifact.Service. It accepts digest references only, binds evidence to the resolved immutable subject, and reports that the subject is signed, not policy-verified.

func (*Service) Verify

Verify implements artifact.Service. An explicit verify always requires a trusted valid signature: with no usable trust configuration the result is unchecked and the call fails rather than returning a green result.

type StaticRepositories

type StaticRepositories struct {
	// Repositories maps aliases to repositories.
	Repositories map[string]artifact.Repository

	// Info optionally overrides the description of an alias; the zero fields fall back to defaults.
	Info map[string]RepositoryInfo
}

StaticRepositories is a fixed alias-to-repository table. Describe reads Capabilities from each repository (which never authenticates) and Open returns it unchanged. It suits tests and composition roots that construct repositories up front.

func (*StaticRepositories) Aliases

func (s *StaticRepositories) Aliases() []string

Aliases implements Repositories.

func (*StaticRepositories) Describe

func (s *StaticRepositories) Describe(alias string) (RepositoryInfo, error)

Describe implements Repositories.

func (*StaticRepositories) Open

Open implements Repositories.

Jump to

Keyboard shortcuts

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