Documentation
¶
Overview ¶
Package layout defines the backend-neutral record layout shared by the local directory, local archive, and S3 artifact repositories. It is pure data and logic: it performs no filesystem, network, or AWS work, so every backend stores the same documents and agrees on names, paths, state transitions, and collision rules.
Below a repository root (a directory, or a bucket prefix) the managed records live in the reserved ".atmos-artifacts/v1/" namespace:
.atmos-artifacts/v1/refs/<reference-key>.json stable-root reference record .atmos-artifacts/v1/records/<record-digest-hex>.json immutable canonical Record .atmos-artifacts/v1/representations/<reference-key>.json mutable storage description .atmos-artifacts/v1/operations/<operation-id>.json publication journal (recovery only) .atmos-artifacts/v1/signatures/<kind>/<subject-hex>/<evidence-hex>.json detached evidence <resolved-payload-path> payload (outside the namespace)
The reference key is the SHA-256 of "name:version", so names containing slashes can never collide with control paths. A reference record binds a name and version to the digest of its immutable Record and carries the pending or completed publication state. The Record never holds a mutable storage locator: the resolved payload location is rendered from the repository key_pattern exactly once, at publication, from the captured creation time, and is persisted in the representation record. Reads, deletes, and retries use the persisted location and never render the pattern again, so a date rollover cannot move an artifact.
Publication order: write the pending operation journal and mark the reference pending, stage and install the payload, write the Record, the representation, and the adjacent documents, and only then flip the reference to completed. Pending references are unavailable to readers and absent from search results; readers recheck the reference generation after reading from a mutable payload location.
Index ¶
- Constants
- func ArchiveExtension(packaging artifact.Packaging) string
- func CleanLocation(location string) (string, error)
- func DefaultLocation(name, version string, packaging artifact.Packaging) string
- func DistributionPath(location, name string) string
- func DocsSidecarDir(location string) string
- func DocumentFileName(role artifact.DocumentRole) string
- func DocumentSidecarPath(location string, role artifact.DocumentRole) string
- func FoldPath(p string) string
- func InManagedNamespace(p string) bool
- func LockPath(resource string) string
- func MetadataSidecarPath(location string) string
- func OperationFileName(operationID string) string
- func OperationPath(operationID string) string
- func PathsOverlap(a, b string) bool
- func PayloadPaths(repositoryKind, location string) []string
- func RecordPath(recordDigest digest.Digest) string
- func ReferenceKey(name, version string) string
- func ReferencePath(key string) string
- func ReferencesDir() string
- func RenderLocation(pattern string, in *PatternInput, packaging artifact.Packaging) (string, error)
- func RepresentationPath(key string) string
- func SignatureDir(kind artifact.SubjectKind, subject digest.Digest) string
- func SignaturePath(kind artifact.SubjectKind, subject, evidence digest.Digest) string
- func StagingPath(operationID string) string
- func TempDir() string
- type Admission
- type AdmitInput
- type Claim
- type Evidence
- type Operation
- type PatternInput
- type Prior
- type Reference
- type Representation
- type Retired
- type State
Constants ¶
const ( // SchemaVersion is the schema version of every layout document. SchemaVersion = 1 // Version is the layout version directory below the reserved namespace. Version = "v1" // ManagedRoot is the slash-separated managed directory below a repository root. ManagedRoot = artifact.ReservedNamespace + "/" + Version // MetadataSuffix is appended to an archive payload path for its adjacent metadata sidecar. MetadataSuffix = ".metadata.json" // DocsSuffix is appended to an archive payload path for its adjacent documents directory. DocsSuffix = ".docs" // DistributionDir is the distribution directory below a copied-files payload, and inside an // archive, that holds README, CHANGELOG, and manifest.json. Managed readers omit it when // materializing user content. DistributionDir = ".atmos/artifact" // ManifestName is the generated manifest file name inside the distribution directory. ManifestName = "manifest.json" )
Names of the managed layout.
const MaxDocumentBytes int64 = 1 << 20
MaxDocumentBytes bounds every layout document (reference, representation, operation journal).
const MaxEvidenceFileBytes = 2*artifact.MaxEvidenceSize + 4096
MaxEvidenceFileBytes bounds one stored evidence file: the base64 form of the largest evidence blob plus its envelope.
Variables ¶
This section is empty.
Functions ¶
func ArchiveExtension ¶
ArchiveExtension returns the file extension (with the dot) of an archive packaging, or the empty string for copied files and unknown packagings.
func CleanLocation ¶
CleanLocation validates a resolved or persisted payload location and returns it in canonical form (a single trailing slash is removed). A location is relative, slash separated, free of empty, "." and ".." segments, control and Windows-reserved characters, and never enters the reserved namespace, however the case is written. Locations are never rewritten otherwise.
func DefaultLocation ¶
DefaultLocation returns the default payload location below the repository root for the packaging: "<name>/<version>" for copied files, "<name>/<version>.<ext>" for an archive.
func DistributionPath ¶
DistributionPath returns the distribution file of a copied-files payload location.
func DocsSidecarDir ¶
DocsSidecarDir returns the adjacent documents directory of an archive payload location.
func DocumentFileName ¶
func DocumentFileName(role artifact.DocumentRole) string
DocumentFileName returns the file name of a distribution document.
func DocumentSidecarPath ¶
func DocumentSidecarPath(location string, role artifact.DocumentRole) string
DocumentSidecarPath returns the adjacent document file of an archive payload location.
func FoldPath ¶
FoldPath returns the comparison form of a slash-separated path: cleaned and case folded, because common filesystems alias names that differ only by case.
func InManagedNamespace ¶
InManagedNamespace reports whether a slash-separated path enters the reserved namespace. The comparison folds case because common filesystems alias names that differ only by case.
func LockPath ¶
LockPath returns the slash-separated path of the lock file for a resource. The file name is the hash of the resource so any resource string is safe.
func MetadataSidecarPath ¶
MetadataSidecarPath returns the adjacent metadata sidecar of an archive payload location.
func OperationFileName ¶
OperationFileName returns the file stem for an operation identifier. Safe identifiers are used verbatim; anything else (slashes, spaces, overlong values) maps to a hash so that no identifier can address a path outside the operations directory. The hashed prefix is reserved: an identifier that starts with it is hashed too, so a literal identifier can never collide with the hashed file name of another identifier.
func OperationPath ¶
OperationPath returns the slash-separated path of the journal for an operation.
func PathsOverlap ¶
PathsOverlap reports whether two paths are equal or one contains the other.
func PayloadPaths ¶
PayloadPaths returns the paths a payload at location owns for the repository kind: a copied directory owns the directory; an archive owns the file, its metadata sidecar, and its documents directory.
func RecordPath ¶
RecordPath returns the slash-separated path of the immutable Record with the given digest.
func ReferenceKey ¶
ReferenceKey returns the private reference key for a name and version: the lowercase hex SHA-256 of "name:version". The colon is unambiguous because names never contain one.
func ReferencePath ¶
ReferencePath returns the slash-separated path of the reference record for key.
func ReferencesDir ¶
func ReferencesDir() string
ReferencesDir returns the directory that holds every reference record.
func RenderLocation ¶
RenderLocation resolves the payload location for one publication. An empty pattern selects DefaultLocation. A non-empty pattern is rendered as a Go template with the Sprig functions (minus the non-hermetic ones) and a UTC "date". The result is validated: it must stay below the repository root, avoid the reserved namespace, and for archives agree with the packaging.
Callers render once, at publication, persist the result in the representation record, and use the persisted value for every later read, delete, and retry; they never render again.
func RepresentationPath ¶
RepresentationPath returns the slash-separated path of the representation record for key.
func SignatureDir ¶
func SignatureDir(kind artifact.SubjectKind, subject digest.Digest) string
SignatureDir returns the directory that holds the detached evidence for a subject.
func SignaturePath ¶
func SignaturePath(kind artifact.SubjectKind, subject, evidence digest.Digest) string
SignaturePath returns the slash-separated path of one detached evidence file: .atmos-artifacts/v1/signatures/<subject-kind>/<subject-digest>/<evidence-digest>.json, with the digests written as lowercase hex.
func StagingPath ¶
StagingPath returns the slash-separated staging directory owned by an operation. Staging lives below the managed root so it shares a filesystem with the payload for atomic renames.
Types ¶
type Admission ¶
type Admission string
Admission is the decision a repository takes for one publication after reading the current reference under the writer guard.
const ( // AdmitCreate writes a new reference. AdmitCreate Admission = "create" // AdmitReplace replaces a completed reference under force. AdmitReplace Admission = "replace" // AdmitUnchanged leaves the completed reference untouched: the same intent already exists. AdmitUnchanged Admission = "unchanged" // AdmitResumeCreate resumes a pending first publication of the same intent. AdmitResumeCreate Admission = "resume-create" // AdmitResumeReplace resumes a pending replacement of the same intent. AdmitResumeReplace Admission = "resume-replace" )
Admission decisions.
func Admit ¶
func Admit(in *AdmitInput) (Admission, error)
Admit applies the compare-and-swap, intent, force, and recovery rules of the publication lifecycle:
- A stale expected-prior reference is a conflict, never a silent overwrite.
- The same record or intent as the completed reference is unchanged.
- A different completed intent conflicts unless force is set.
- A pending reference of the same intent resumes; a pending reference of a different intent is unavailable and names the owning operation, even under force. A pending operation is never stolen automatically.
type AdmitInput ¶
type AdmitInput struct {
// Current is the reference as stored, or nil when it does not exist.
Current *Reference
// CurrentIntent is the intent digest of the completed Record. It is only read when Current is
// completed; empty means it could not be computed, which never counts as unchanged.
CurrentIntent digest.Digest
// IncomingRecord and IncomingIntent identify the artifact being published.
IncomingRecord digest.Digest
IncomingIntent digest.Digest
// ExpectedPrior is the reference the service observed; nil means the reference must not exist.
ExpectedPrior *artifact.PinnedReference
// Force permits replacing a conflicting completed reference.
Force bool
}
AdmitInput is everything the admission rules need.
type Claim ¶
type Claim struct {
// ReferenceKey identifies the owning reference.
ReferenceKey string
// Name and Version identify the owner for diagnostics.
Name string
Version string
// OperationID is the pending operation holding the claim, empty for a completed reference.
OperationID string
// Paths are the owned slash-separated paths relative to the repository root.
Paths []string
}
Claim is the set of storage paths one reference owns. Two references may never own overlapping paths, which is how two references with a colliding key_pattern are detected: the second fails with a conflict and is never bound to the first reference's payload.
func FindConflict ¶
FindConflict returns the first existing claim, owned by a different reference, that overlaps the candidate, or nil. A reference never conflicts with itself, so replacement and same-intent retry keep working.
type Evidence ¶
type Evidence struct {
// SchemaVersion is [SchemaVersion].
SchemaVersion int `json:"schema_version"`
// Subject is the immutable subject the evidence claims to cover.
Subject artifact.SignatureSubject `json:"subject"`
// Format is the evidence encoding.
Format artifact.EvidenceFormat `json:"format"`
// MediaType is the evidence media type.
MediaType string `json:"media_type"`
// Data is the evidence bytes, at most [artifact.MaxEvidenceSize].
Data []byte `json:"data"`
}
Evidence is the stored form of one detached signature evidence blob. The file name is the SHA-256 of Data, so the evidence digest the verifier reports identifies exactly the signed bytes, and a stored file is rejected when its name and content disagree.
Evidence is stored beside, never inside, the signed Record, so adding a signature cannot change the Record, its digest, or the reference.
func DecodeEvidence ¶
DecodeEvidence strictly parses a stored evidence file. The wantDigest argument is the evidence digest taken from the file name; it must equal the digest of the stored bytes.
func NewEvidence ¶
func NewEvidence(subject artifact.SignatureSubject, payload *artifact.EvidencePayload) (*Evidence, error)
NewEvidence builds the stored form of a freshly produced evidence payload.
func (*Evidence) Blob ¶
func (e *Evidence) Blob(locator string) artifact.EvidenceBlob
Blob converts the stored evidence into an artifact.EvidenceBlob. The locator argument is the display location of the evidence file.
type Operation ¶
type Operation struct {
// SchemaVersion is [SchemaVersion].
SchemaVersion int `json:"schema_version"`
// RepositoryKind is the repository kind performing the publication.
RepositoryKind string `json:"repository_kind"`
// OperationID is the logical operation identifier, stable across retries.
OperationID string `json:"operation_id"`
// Name is the artifact name.
Name string `json:"name"`
// Version is the artifact version.
Version string `json:"version"`
// IntentDigest is the intent digest of the artifact being published.
IntentDigest digest.Digest `json:"intent_digest"`
// RecordDigest is the digest of the Record being published.
RecordDigest digest.Digest `json:"record_digest"`
// CapturedAt is the creation time captured once for the publication.
CapturedAt artifact.Timestamp `json:"captured_at"`
// Packaging is the payload packaging being written.
Packaging artifact.Packaging `json:"packaging"`
// Location is the resolved payload location reserved for this operation.
Location string `json:"location"`
// ExpectedPrior is the record digest the writer observed under the guard; empty means none.
ExpectedPrior digest.Digest `json:"expected_prior,omitempty"`
// Prior describes the state being replaced, if any.
Prior *Prior `json:"prior,omitempty"`
// Abandoned lists payloads of superseded attempts that still await removal.
Abandoned []Retired `json:"abandoned,omitempty"`
// Payload and Documents are the prepared representation checksums.
Payload []ocispec.Descriptor `json:"payload"`
Documents []ocispec.Descriptor `json:"documents"`
// Owner identifies the writer for recovery diagnostics, for example host and process.
Owner string `json:"owner,omitempty"`
}
Operation is the publication journal: an implementation recovery record, not a public catalog. It is written before any payload path changes and records everything a same-intent retry needs to resume or repair the publication: the captured time, the intent, the prior reference, the resolved location, and the prepared representation checksums.
func DecodeOperation ¶
DecodeOperation strictly parses a stored operation journal.
type PatternInput ¶
type PatternInput struct {
// Name is the artifact name.
Name string
// Version is the artifact version.
Version string
// Kind is the artifact kind.
Kind string
// CreatedAt is the captured creation time; it is rendered in UTC.
CreatedAt time.Time
}
PatternInput holds the values a key_pattern may reference: .Name, .Version, .Kind, and .CreatedAt. CreatedAt is the creation time captured once for a publication.
type Prior ¶
type Prior struct {
// RecordDigest is the replaced Record.
RecordDigest digest.Digest `json:"record_digest"`
// Location is where the replaced payload lives, so a recovery can retire it.
Location string `json:"location,omitempty"`
// Packaging is the packaging of the replaced payload, for backends such as S3 whose object
// keys depend on it. Local backends leave it empty.
Packaging artifact.Packaging `json:"packaging,omitempty"`
}
Prior describes the state an operation replaces.
type Reference ¶
type Reference struct {
// SchemaVersion is [SchemaVersion].
SchemaVersion int `json:"schema_version"`
// Name is the artifact name.
Name string `json:"name"`
// Version is the artifact version.
Version string `json:"version"`
// State is pending or completed.
State State `json:"state"`
// Generation increases by one on every state change; the first record has generation 1.
Generation int64 `json:"generation"`
// OperationID is the operation that wrote this state: the pending operation, or the operation
// that completed the publication.
OperationID string `json:"operation_id"`
// IntentDigest is the intent digest of the publication that wrote this state.
IntentDigest digest.Digest `json:"intent_digest"`
// RecordDigest is the digest of the canonical Record. It is required when completed and empty
// while a first publication is pending.
RecordDigest digest.Digest `json:"record_digest,omitempty"`
// PriorRecordDigest is the Record this pending publication replaces, kept for recovery
// diagnostics. It is empty for a first publication and once completed.
PriorRecordDigest digest.Digest `json:"prior_record_digest,omitempty"`
}
Reference is the stable-root reference record: it binds a name and version to the digest of the immutable Record. It is the only mutable document readers consult, and it is replaced atomically. Generation increases on every state change so a reader can detect that the reference moved while it was reading from a mutable payload location.
func DecodeReference ¶
DecodeReference strictly parses a stored reference record.
func NewPendingReference ¶
func NewPendingReference(name, version, operationID string, intent digest.Digest, prior *Reference) Reference
NewPendingReference returns the pending state that replaces prior (nil for a first publication).
func (*Reference) Completed ¶
Completed returns the completed state that follows a pending reference once the Record, payload, and documents are in place.
type Representation ¶
type Representation struct {
// SchemaVersion is [SchemaVersion].
SchemaVersion int `json:"schema_version"`
// RepositoryKind is the repository kind that wrote it, for example "local/archive".
RepositoryKind string `json:"repository_kind"`
// Name is the artifact name.
Name string `json:"name"`
// Version is the artifact version.
Version string `json:"version"`
// RecordDigest is the digest of the Record this representation belongs to.
RecordDigest digest.Digest `json:"record_digest"`
// OperationID is the operation that wrote the representation.
OperationID string `json:"operation_id"`
// Packaging is the payload packaging.
Packaging artifact.Packaging `json:"packaging"`
// Location is the resolved payload location, relative to the repository root.
Location string `json:"location"`
// Payload lists the payload blob descriptors: one archive, or one per file.
Payload []ocispec.Descriptor `json:"payload"`
// Documents lists the document blob descriptors stored alongside the payload.
Documents []ocispec.Descriptor `json:"documents"`
// RepresentationDigest is the checksum of the archive, or of the per-file payload digests.
RepresentationDigest digest.Digest `json:"representation_digest,omitempty"`
}
Representation is the mutable storage description of one reference's current Record. It holds the resolved payload location rendered once at publication; later reads and deletes use it and never render the key_pattern again.
func DecodeRepresentation ¶
func DecodeRepresentation(raw []byte) (*Representation, error)
DecodeRepresentation strictly parses a stored representation record.
func (*Representation) Artifact ¶
func (r *Representation) Artifact(locator string) artifact.Representation
Artifact converts the stored description into the repository-neutral artifact.Representation. The locator argument is the display locator of the payload, for example an absolute path or an s3:// URI.
func (*Representation) Claim ¶
func (r *Representation) Claim() Claim
Claim returns the paths a completed representation owns.
func (*Representation) Marshal ¶
func (r *Representation) Marshal() ([]byte, error)
Marshal returns the canonical bytes of the representation.
func (*Representation) Validate ¶
func (r *Representation) Validate() error
Validate checks the representation's shape.
type Retired ¶
type Retired struct {
// Packaging is the packaging of the abandoned payload, which decides its object keys.
Packaging artifact.Packaging `json:"packaging,omitempty"`
// Location is where the abandoned payload was written.
Location string `json:"location"`
// Files are the per-file payload paths below Location. Archive packaging leaves it empty.
Files []string `json:"files,omitempty"`
// Docs are the distribution document file names written beside the payload.
Docs []string `json:"docs,omitempty"`
}
Retired names a payload an earlier attempt of the same reference abandoned: written, never completed, and replaced by a later attempt under a different location or packaging. The journal that replaces the old one carries it until a retry has removed the objects, so a stopped retry never loses the recovery metadata of the payload it superseded.
type State ¶
type State string
State is the publication state of a reference.
const ( // StatePending marks a reference whose publication started and has not completed. It stays // pending after an interruption until the same intent retries and repairs it. StatePending State = "pending" // StateCompleted marks a reference whose Record, payload, and documents are all in place. StateCompleted State = "completed" )
Reference states. A pending reference is unavailable to managed readers and absent from completed search results. The completed state is written last in the publication sequence.