Documentation
¶
Overview ¶
Package pub validates Dart pub archives and maintains their native index. A package version is one gzip-compressed TAR archive, stored at <name>/<name>-<version>.tar.gz, whose pubspec.yaml at the archive root must name the package and version its path does. The item tree, including a remote repository's cache tree, remains the source of truth: the index is rebuilt from it.
Role ¶
artifacts module, ecosystem layer: the Dart pub archive validation and index of the pub slice. Its Handler plugs into the item service through the format hooks (decision 0032), so a version published with dart pub publish and one written through the item routes meet the same checks; the slice's http package (artifacts/ecosystem/pub/http) serves the hosted pub protocol over what it keeps.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for pub repositories to Handler, and the work queue, which runs every format's reindex through it (JFrog's /api/pub/{repoKey}/reindex schedules one); and the protocol, which checks names and versions (ValidName, ValidVersion), builds archive paths (Path), reads uploaded and upstream archives (ReadArchive) 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 before the format's own. YAML (gopkg.in/yaml.v3) decodes the pubspecs, and golang.org/x/mod/semver checks versions.
- Settings: none.
Outputs ¶
- Handler: the hooks that read an archive once before its transaction (Inspect), admit only an archive at a canonical path whose pubspec 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 pub package name, with a version per stored archive, whose metadata is the archive's Metadata as JSON: its pubspec, path and SHA-256.
- The pub.name, pub.version and pub.sha256 item properties on each archive.
- The path and archive rules: ValidName, ValidVersion, Path, ParsePath, ReadArchive, Metadata, ErrArchive and the archive bounds.
Invariants ¶
- An archive is read whole within fixed bounds (64 MiB compressed, 128 MiB unpacked, 4,096 entries and a 1 MiB pubspec.yaml): one gzip member with nothing after it, unique entries that are regular files or folders with no absolute, backslashed or traversing path, and only zeros after the TAR terminator.
- A pubspec has no YAML aliases or anchors, nests at most 64 deep, has string keys, and must encode as JSON.
- A published version is immutable through dart pub publish and the item routes alike (409); deletes and restores keep their normal lifecycle.
- 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); decision 0007: docs/research/decisions/0007-remote-repositories.md (remote repositories, whose cache tree the index also covers).
- docs/testing/pub.md (connecting Dart, the archive rules, reindex and the evidence).
- JFrog pub repositories: https://docs.jfrog.com/artifactory/docs/pub-repositories.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 234 (ecosystem/pub), line 379 (the slice row) and line 997 (the mapping row).
- Plan: docs/implementation/plan.md#p30-language-package-repositories and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/765 and https://github.com/weaveplatform/artifactweave/issues/1048
Status ¶
Implemented P9c, which delivered the plan's P30 group (issues #762 to #768). Moved here in P9d.
Testing ¶
- archive_test.go: whole-tarball validation, invalid manifests, and the path round trip.
- handler_test.go: admission against the archive's identity and the repository policy, and stale or invalid content at Deployed and Reindex.
Index ¶
- Constants
- Variables
- func ParsePath(p string) (name, version string, ok bool)
- func Path(name, version string) string
- func Serves(t repo.PackageType) bool
- func ValidName(name string) bool
- func ValidVersion(version string) bool
- type Handler
- func (Handler) Admit(ctx 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, c 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 archive, uploaded or fetched, at 64 MiB // compressed. MaxArchiveBytes = 64 << 20 // MaxUnpackedBytes bounds an archive's decompressed TAR stream at // 128 MiB, so a small archive cannot expand without limit. MaxUnpackedBytes = 128 << 20 // MaxManifestBytes bounds an archive's pubspec.yaml at 1 MiB. MaxManifestBytes = 1 << 20 // MaxFiles bounds an archive at 4,096 TAR entries, folders included. MaxFiles = 4096 )
const ( // PropName is the property that holds an archive's package name. PropName = "pub.name" // PropVersion is the property that holds an archive's package version. PropVersion = "pub.version" // PropSHA256 is the property that holds an archive's SHA-256. PropSHA256 = "pub.sha256" )
The item properties Deployed and Reindex keep on every stored archive: its pubspec's name and version and its SHA-256. The items keep these names, so they never change.
Variables ¶
var ( // ErrArchive is what ReadArchive returns for every archive it refuses; // the hooks wrap it, and wrap it too when a stored archive no longer // matches its path. ErrArchive = errors.New("pub: invalid dart pub archive") )
Functions ¶
func ParsePath ¶
ParsePath splits an item path into the package name and version whose archive it holds, and reports ok only when p is exactly Path(name, version) with a valid name and version.
func Path ¶
Path is the item path of the archive of package name at version: <name>/<name>-<version>.tar.gz.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the pub package type.
func ValidName ¶
ValidName reports whether name is a pub package name the registry accepts: a lowercase letter followed by up to 127 lowercase letters, digits and underscores.
func ValidVersion ¶
ValidVersion reports whether version 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 pub format's hooks: it admits an archive only when its pubspec matches its path, refuses a second write of a published version, and indexes each stored archive as a version of its package. It embeds the generic hooks, so every path is classed as generic content is.
func (Handler) Admit ¶
func (Handler) Admit( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit applies the generic deploy policy, wrapping its refusal, then passes a checksum deploy and a remote's cached version document (api/packages/<name>). Any other write must be at an archive path, <name>/<name>-<version>.tar.gz (400), and the archive's pubspec must name the package and version its path does (409). A remote's copy at any other path is kept as a plain file (format.RemoteCopy). It reuses Inspect's reading when it covers the same content, and reads the stored archive itself otherwise; an invalid archive fails with ErrArchive.
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: it sets the archive's pub.* properties, creates the package when it is new, and makes the version, linked to the archive, carry its Metadata. Folders and files at other paths change nothing. An archive whose pubspec no longer matches its path fails with ErrArchive.
func (Handler) GuardWrite ¶
func (Handler) GuardWrite( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) error
GuardWrite refuses a write to the path of a stored version (409), so a published version is immutable through both pub publish and the generic item route; a checksum deploy and a remote's cached content pass. Deletes and restores still use their normal lifecycle paths.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (any, error)
Inspect reads and validates the stored archive of a write to a .tar.gz path before the write's transaction, and returns its metadata for Admit and Deployed, so an archive is read once per write. A checksum deploy, a remote's copy outside the archive layout and any other file inspect nothing. An archive that cannot be opened fails the write, and an invalid one fails it with ErrArchive.
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
Version string `json:"version"`
Pubspec map[string]any `json:"pubspec"`
Path string `json:"path"`
SHA256 string `json:"sha256"`
}
Metadata is what the package index keeps for a version, as JSON, and what the protocol answers from: the package's name and version, its pubspec, and the archive's item path and SHA-256. ReadArchive fills the name, version and pubspec, and Deployed and Reindex add the path and SHA-256 of the stored item; a remote's come from its upstream version document.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pubhttp serves the hosted Dart pub protocol through Artifactory's /artifactory/api/pub/{repo} URL, on pub local, federated, remote and virtual repositories: a package's versions, one version, an archive, and the three steps of dart pub publish.
|
Package pubhttp serves the hosted Dart pub protocol through Artifactory's /artifactory/api/pub/{repo} URL, on pub local, federated, remote and virtual repositories: a package's versions, one version, an archive, and the three steps of dart pub publish. |