Documentation
¶
Overview ¶
Package agentpackages validates and indexes APM Agent Packages ZIP archives. A package version is one archive, stored at <owner>/<name>/<name>-<version>.zip, that carries its apm.yml descriptor at the root, or the apm.lock.yaml fallback of a manually supplied archive. The path names the package owner/name and its version, and a descriptor that names another package or version is refused. The item tree remains the source of truth.
Role ¶
artifacts module, ecosystem layer: the APM Agent Packages archive admission and index of the Agent Packages slice. Its Handler plugs into the item service through the format hooks (decision 0032), so a version published through APM and one written through the item routes meet the same checks; the slice's http package (artifacts/ecosystem/agentpackages/http) serves the APM v1 registry protocol over what it keeps.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for agentpackages repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which checks identities and versions (ValidComponent, ValidVersion), builds archive paths (Path), bounds an upload (MaxArchiveBytes) and decodes the version metadata the index holds (Metadata).
- Driven: the format hooks' environment (format.Env): its blobs hold the archives, and its store holds the items, their properties and the package index (artifacts/core/pkgindex). The generic blackout and include and exclude checks (artifacts/ecosystem/generic) run after the format's own. YAML (gopkg.in/yaml.v3) decodes the descriptors.
- Settings: none.
Outputs ¶
- Handler: the hooks that read an archive once before its transaction (Inspect), admit only an archive at a canonical path whose descriptor agrees with it (Admit), refuse a second write of a published version (GuardWrite), index a version and set its properties once its archive is stored (Deployed) and rebuild the index from the stored archives (Reindex). Deletes need no hook: the item service prunes a version whose archive is gone.
- The package index: a package per owner/name, with a version per stored archive, whose metadata is the archive's Metadata as JSON: its description, tags and primitive types (the folders under .apm/), its path, SHA-256 and size.
- The agentpackages.name, agentpackages.version, agentpackages.sha256 and agentpackages.description item properties on each archive.
- The path and archive rules: ValidComponent, ValidVersion, Path, ParsePath, ReadArchive, Metadata, ErrArchive and the archive bounds.
Invariants ¶
- An archive is read to its end, every member's CRC and size included, within fixed bounds (64 MiB stored and inflated, 512 entries and a 1 MiB descriptor), with no link and no duplicate, absolute or traversing path.
- apm.yml takes precedence over apm.lock.yaml; its name, when given, must be the package's name or owner/name, and its version the path's.
- A published version is immutable through APM and the item routes alike (409); a restore bypasses the guard and reindexes the saved bytes.
- The property names are stored, so they stay byte-identical.
References ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks and the write guard).
- docs/operations/agent-packages.md (connecting APM, the archive rules, the API and its permissions), and docs/research/33-package-formats.md, "Agent Packages" (the contract and its open questions).
- JFrog Agent Packages repositories: https://docs.jfrog.com/artifactory/docs/agent-packages-repositories.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 232 (ecosystem/agentpackages), line 379 (the slice row) and line 997 (the mapping row).
- Plan: docs/implementation/plan.md#p9b-newly-identified-artifactory-formats and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/692 and https://github.com/weaveplatform/artifactweave/issues/1046
Status ¶
Implemented P9b (newly identified Artifactory formats). Moved here in P9d.
Testing ¶
- archive_test.go: archive reading and the canonical path, and unsafe or corrupt archives.
- handler_test.go: admission and the hooks' no-content branches.
Index ¶
- Constants
- Variables
- func ParsePath(p string) (owner, name, version string, ok bool)
- func Path(owner, name, version string) string
- func Serves(t repo.PackageType) bool
- func ValidComponent(v string) bool
- func ValidVersion(v string) bool
- type Handler
- func (Handler) Admit(_ context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Deleted(context.Context, format.Env, repo.Config, []model.Item) error
- func (Handler) Deleting(context.Context, format.Env, repo.Config, model.Item) error
- func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (Handler) GuardWrite(ctx context.Context, env format.Env, c repo.Config, w format.Write) error
- func (Handler) Inspect(ctx context.Context, env format.Env, _ repo.Config, w format.Write) (any, error)
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- type Metadata
Constants ¶
const ( // MaxArchiveBytes bounds an Agent Package archive, and the total its // files inflate to, at 64 MiB. MaxArchiveBytes = 64 << 20 // MaxManifestBytes bounds an archive's apm.yml and apm.lock.yaml at // 1 MiB. MaxManifestBytes = 1 << 20 // MaxFiles bounds an archive at 512 ZIP entries, folders included. MaxFiles = 512 )
Variables ¶
var ( // ErrArchive is what ReadArchive returns for every archive it refuses; // Deployed and Reindex wrap it for a stored archive whose descriptor // disagrees with its path. ErrArchive = errors.New("agentpackages: invalid agent package archive") )
Functions ¶
func ParsePath ¶
ParsePath splits a canonical archive path into the owner, package name and version, and reports ok only when p is exactly Path(owner, name, version) with valid components and version.
func Path ¶
Path is the canonical item path of the archive of package owner/name at version, <owner>/<name>/<name>-<version>.zip, the only path a version is stored at.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Agent Packages package type.
func ValidComponent ¶
ValidComponent reports whether v is an owner or package name the registry accepts: a letter or digit followed by up to 127 letters, digits, dots, underscores and hyphens.
func ValidVersion ¶
ValidVersion reports whether v is a full semantic version of at most 128 bytes, major.minor.patch with an optional pre-release and build, written without a leading v.
Types ¶
type Handler ¶
Handler is the Agent Packages format's hooks: it admits an archive only at its canonical path and when its descriptor agrees with that path, keeps published versions immutable, and keeps the package index and the agentpackages.* properties in step with the stored archives. It embeds the generic hooks, so every path is classed as generic content is.
func (Handler) Admit ¶
func (Handler) Admit( _ context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit refuses a write, other than a checksum deploy or a remote's cached content, that is not at a canonical archive path, whose archive Inspect did not read or found invalid, or whose apm.yml names another version or a name other than the package's own or owner/name (409). It then applies the generic blackout and include and exclude checks, keeping their refusals as they are.
func (Handler) Deleted ¶
Deleted does nothing: a version is one archive, so the item service's pruning of versions left without files is all a delete needs.
func (Handler) Deleting ¶
Deleting does nothing: the item service drops a removed archive's version link with it.
func (Handler) Deployed ¶
Deployed indexes a stored archive at a canonical path of the repository's own tree; folders, cached items and other files change nothing. An archive whose descriptor no longer agrees with its path fails with ErrArchive. Otherwise it sets the agentpackages.* properties, dropping agentpackages.description when the descriptor has none, creates the package owner/name when it is new, and links the version to the archive, with its Metadata as the version's metadata.
func (Handler) GuardWrite ¶
func (Handler) GuardWrite( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) error
GuardWrite keeps version ZIPs immutable through both APM and ordinary item routes. Restore bypasses the guard by design; it reindexes the saved bytes.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect reads the stored archive of every write but a checksum deploy before the write's transaction, and keeps what it read, or why the archive is invalid, for Admit and Deployed, so an archive is read once per write. A write without a SHA-256 inspects nothing; an archive that cannot be opened fails the write.
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
Version string `json:"version"`
Path string `json:"path"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Types []string `json:"types,omitempty"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
}
Metadata carries bounded descriptor fields; the canonical path supplies identity and version after validation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agentpackageshttp serves the APM v1 registry protocol on Agent Packages local and federated repositories, at /artifactory/api/agentpackages/{repoKey}: a package's versions, a version's archive, publishing a version, and JFrog's search extension.
|
Package agentpackageshttp serves the APM v1 registry protocol on Agent Packages local and federated repositories, at /artifactory/api/agentpackages/{repoKey}: a package's versions, a version's archive, publishing a version, and JFrog's search extension. |