smart

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package smart is Smart Remote: a remote repository that discovers the Artifactory repository behind its URL, copies and refreshes the user properties of what it caches, reports its downloads to the peer, records when an item is confirmed gone from the origin, and answers transitive AQL against the peer. It reads through core remote's shared retrieval and cache policy and adds only authenticated, bounded and durable side effects.

Role

artifacts module, core layer: Smart Remote, beside core remote (artifacts/core/remote), which it imports and which never imports it (decision 0044). The policy reaches Smart only through the core-owned remote.Interceptor and the WithSmart and SmartActive context mark; Smart installs itself as Policy.Smart and reaches the upstream through the remote.Upstream port and the outbound request hook, never a client's fields.

Inputs

  • Driving: the shared policy, which hands Smart every read whose context carries no WithSmart mark (Read); the router, which wraps every request in SmartTrace; the remote status endpoint (Status); the AQL transitive peer reader, which reads through the source service with a Smart AQL query; and the work queue's workers, which run the queued property refreshes and statistics submissions.
  • Driven: remote.Policy (its store, item service, credential options, circuit and capacity) and remote.Upstream for the peer requests; the access API's Authenticator and Authorizer, which recheck the principal a queued side effect runs as; the persistent work queue (platform/work) under the work kind the application passes, one for ordinary remotes and one for registry remotes; and the registry-path parser, the docker slice's ParseRegistryPath, which the application passes so that Smart never imports the slice.

Outputs

  • Smart, the remote.Interceptor of one policy, with Discover, Status and Close; NewSmart, which builds it and starts its workers.
  • SmartTrace, the router middleware that reads the loop trace, and SmartOriginHeader, the header that carries it.
  • SmartStatus with SmartRepresentationStatus and SmartWorkStatus, the JSON document of the remote status endpoint, an artifactweave diagnostic rather than an Artifactory wire document.

Invariants

  • The X-Artifactory-Originated trace fences loops: a request whose trace holds this node, or 8 nodes already, is refused before any peer request.
  • Smart headers go only to same-origin requests: the outbound hook adds them to the first request and to a redirect that stays on its origin.
  • Metadata requests are confined to the peer's storage targets, on the first request and on every redirect.
  • A nil registry-path parser fails closed: Docker, OCI and Helm OCI repositories get no property path and no registry grant.
  • A statistics claim commits before its submission, so a restart never counts a download twice, and a lost acknowledgement stays uncertain rather than being sent again.
  • Cache-only, offline and no-network reads make no peer request at all, Smart side effects included (decision 0007).
  • The work kinds, the header name, the status document's fields and the error texts stay byte-identical.

References

Status

Implemented P9. Moved here in P9d.

Testing

  • smart_test.go: property refresh and ownership, statistics claims, origin absence, the flags, authority rechecks, the status document (unreadable state, items gone, registry work), and reads that fail closed when their options moved or their refresh state is missing or fails.
  • smart_durable_test.go: retries, capacity shared with peer work, lost acknowledgements, observation order, discovery throttling, no-store and credential revisions across the durable queue; enqueue and queued job refusals, refresh publication and held-off statistics.
  • smart_fault_test.go: discovery protocol failures, shared discovery, property document admission, the metadata target and redirect fence, and the loop bound; its store and pool fakes drive the peer request, discovery, storage and upload paths that fail closed.
  • smart_aql_test.go: the transient authenticated AQL POST, its query preflight, and its admission, failure and boundary cases.
  • smart_listing_test.go: Smart listings through real discovery and the cache fences.
  • smart_registry_test.go (package smart_test): the registry grant and property path with the docker slice's parser, and a nil parser; it reads Smart's helpers through export_test.go.
  • smart_fixture_test.go holds the policy fixture these tests share, copied from core remote's external tests.

Index

Constants

View Source
const SmartOriginHeader = "X-Artifactory-Originated"

SmartOriginHeader carries the Smart Remote nodes a request has passed through, as Artifactory's own Smart Remote sends it. SmartTrace reads up to 8 nodes from it, and Smart's peer requests send it with this node added, so that a chain of Smart remotes that loops back is refused.

Variables

This section is empty.

Functions

func SmartTrace

func SmartTrace(next http.Handler) http.Handler

SmartTrace carries only loop-prevention evidence. It grants no authority and is ignored by ordinary requests. A client can use it only to deny its own Smart request, never to authenticate or widen a repository scope.

Types

type Smart

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

Smart adds authenticated discovery and bounded durable side effects to one shared policy. Registry and ordinary policies keep separate validators.

func NewSmart

func NewSmart(
	ctx context.Context,
	p *remote.Policy,
	pool remote.Upstream,
	authn accessapi.Authenticator,
	authz accessapi.Authorizer,
	kind string,
	registryPath func(string) (image, operation, reference string, err error),
	log *slog.Logger,
) (*Smart, error)

NewSmart attaches smart remote discovery and side effects to p, with pool for peer requests, and starts the workers that run the side effects queued as kind. A side effect runs as the principal whose request queued it, rechecked when it runs: authn's CurrentRegistry for a registry token, or Current for any other credential, must still accept it, and authz must still grant it, or the side effect fails permanently with source.ErrDenied. registryPath splits a Docker, OCI or Helm OCI repository's upstream path into image, operation and reference (the application passes the docker slice's ParseRegistryPath, which Smart cannot import); nil gives those repositories no property path and no registry grant. NewSmart installs Smart as p.Smart and chains its property fetch after p's PrepareUpload; Close stops the workers.

func (*Smart) Close

func (s *Smart) Close()

Close stops the workers that NewSmart started and waits for them to return. Queued jobs stay in the persistent work queue for the next start. Close may be called more than once, and on a nil *Smart.

func (*Smart) Discover

func (s *Smart) Discover(
	ctx context.Context,
	q source.Request,
	permit source.Permit,
) (remote.SmartPeer, error)

Discover requires the caller's existing permit. Public adapters invoke it through RequireSmart and source.Service, never manufacture their own permit.

func (*Smart) Read

func (s *Smart) Read(
	ctx context.Context,
	q source.Request,
	permit source.Permit,
) (source.Result, error)

Read reads q in place of the shared policy, as Policy.Smart. A read that may not reach the upstream (cache-only, without network permission, or of an offline repository), or of a repository with neither Smart Remote nor property synchronisation on, goes to the policy unchanged; a Smart AQL query among them answers source.ErrUnavailable. Any other read enters the loop trace, refused when the trace already holds this node or 8 nodes, discovers the peer, and reads through the policy with the Smart headers on; a metadata request (RequireSmart) is confined to the peer's storage targets. A GET that delivers an item first brings its properties up to date when a refresh is due, and its Used queues the download's statistics. Errors are the source service's sentinels and typed errors, matched with errors.Is and errors.As.

func (*Smart) Status

func (s *Smart) Status(ctx context.Context, key, path string) (SmartStatus, error)

Status reads one exact path under a source lifetime lock. Options resolves only stored settings: this endpoint never discovers or contacts a peer.

type SmartRepresentationStatus

type SmartRepresentationStatus struct {
	PropertiesCheckedAt time.Time         `json:"properties_checked_at"`
	OriginCheckedAt     time.Time         `json:"origin_checked_at"`
	OriginAbsent        *bool             `json:"origin_absent,omitempty"`
	Downloads           int64             `json:"downloads"`
	Claimed             int64             `json:"claimed"`
	Uncertain           int64             `json:"uncertain"`
	Work                []SmartWorkStatus `json:"work"`
}

SmartRepresentationStatus is the Smart state of one cached representation of the path: when its properties and its origin were last checked (zero for never), whether the origin was found absent (nil until it was checked), the downloads counted here, how many of them a statistics submission claimed, how many claimed ones the peer never acknowledged, and its queued Smart work.

type SmartStatus

type SmartStatus struct {
	Repository      string                      `json:"repository"`
	Path            string                      `json:"path"`
	Representations []SmartRepresentationStatus `json:"representations"`
	Truncated       bool                        `json:"truncated"`
}

SmartStatus is an artifactweave diagnostic, not an Artifactory storage wire document. A zero origin timestamp means unknown, never confirmed absent.

type SmartWorkStatus

type SmartWorkStatus struct {
	Operation string         `json:"operation"`
	State     work.WorkState `json:"state"`
	Attempts  int            `json:"attempts"`
}

SmartWorkStatus is one queued Smart job of a representation: its operation, "refresh" or "statistics", its work-queue state and the attempts made so far.

Jump to

Keyboard shortcuts

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