Documentation
¶
Overview ¶
Package composer validates hosted Composer archives and their package identity. A version is one ZIP archive, stored at <vendor>/<package>/<file>.zip, whose single composer.json, at the root or in one top-level folder, names the package its path does; its version is the file's own or the one composer.version property of the archive's item. Composer keeps no index: the protocol builds its catalogs from the stored archives on every request, so a delete or restore shows at once.
Role ¶
artifacts module, ecosystem layer: the Composer archive validation and catalog rules of the Composer slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every archive is checked when it is written; the slice's http package (artifacts/ecosystem/composer/http) serves the Composer 1 and 2 catalogs from the archives it admitted.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for composer repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which reads stored and upstream archives (ParseArchive), checks names, versions and paths (ValidName, ValidVersion, HostedPath) and renders catalog entries (Package.Document).
- Driven: the format hooks' environment (format.Env): its blobs hold the archives, and its store holds the items and their properties. The generic blackout and include and exclude checks (artifacts/ecosystem/generic) run before the format's own.
- Settings: none.
Outputs ¶
- Handler: the hooks that read an archive once before its transaction (Inspect), admit only a valid archive at its package's path in a local or federated repository (Admit), and recheck every stored file (Reindex). It writes no index and no property: its Deployed and delete hooks are the generic ones, which do nothing.
- The archive rules: ParseArchive, Package and its Document, ValidName, ValidVersion, HostedPath and the bounds (ArchiveLimit, MetadataLimit).
Invariants ¶
- An archive is read whole, every entry to its end, within fixed bounds (128 MiB stored, 128 MiB for each inflated entry and 256 MiB in all, 4,096 entries and a 1 MiB composer.json), with no absolute, backslashed or dot-segment path.
- The lowercase vendor/package name in composer.json is the archive's first two path segments. The file name may differ from the version, which a composer.version property may supply, as JFrog's Composer deployment guide describes, but the property must agree with an embedded version.
References ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks); decision 0007: docs/research/decisions/0007-remote-repositories.md (remote repositories, whose upstream archives ParseArchive checks).
- docs/operations/composer.md (connecting Composer, the archive rules, the repository classes and reindex).
- JFrog PHP Composer repositories: https://docs.jfrog.com/artifactory/docs/php-composer-repositories, and the Composer repository specification: https://getcomposer.org/doc/05-repositories.md.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 233 (ecosystem/composer), 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/763 and https://github.com/weaveplatform/artifactweave/issues/1047
Status ¶
Implemented P9c, which delivered the plan's P30 group (issues #762 to #768). Moved here in P9d.
Testing ¶
- composer_test.go: archive identity and bounds, the hosted path and name grammar, adversarial archives, and Admit's class and cached-write rules.
- admission_test.go: admission and reindex of a local repository through the item service.
Index ¶
Constants ¶
const ( // ArchiveLimit bounds a Composer archive at 128 MiB stored, each entry // at 128 MiB inflated, and all its entries together at twice that. ArchiveLimit = 128 << 20 // MetadataLimit bounds an archive's composer.json at 1 MiB. MetadataLimit = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
func HostedPath ¶
HostedPath binds the embedded package identity to the upload path. The final filename may differ from the metadata version when a matrix version supplies it, as documented by Artifactory's Composer deployment guide.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Composer package type.
func ValidName ¶
ValidName reports whether name is a Composer package name the registry accepts: a lowercase vendor/package of at most 255 bytes, each part a letter or digit followed by letters, digits, underscores, dots and hyphens.
func ValidVersion ¶
ValidVersion reports whether version is a version the registry accepts: a letter or digit followed by up to 127 ASCII letters, digits, dots, underscores, pluses and hyphens. It checks the characters only, so a branch version such as dev-main passes.
Types ¶
type Handler ¶
Handler is the Composer format's hooks: it admits a ZIP archive to a local or federated repository only when its composer.json names the package its path does, and rechecks every stored file on reindex. It keeps no index, since the protocol reads the archives on every request. 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 remote's cached content and a checksum deploy. Any other write must be a .zip archive in a local or federated repository (400) that passes Inspect's checks. It reuses Inspect's reading when it covers the same content, and reads the stored archive itself otherwise.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect reads and validates the stored archive of a write to a .zip path before the write's transaction, and returns what it found for Admit, so an archive is read once per write. A remote's cached content and any other file inspect nothing. The archive must be valid (ParseArchive), with the version from the write's composer.version property when it has one, and must sit directly under its package's name (HostedPath); otherwise the write is refused with 400, as is a write without content or with more than one composer.version. An archive that cannot be opened fails the write.
type Package ¶
type Package struct {
Name string
Version string
Fields map[string]json.RawMessage
}
Package is the validated composer.json of one archive. Extra Composer fields are retained so the solver sees require, autoload, conflicts and stability.
func ParseArchive ¶
ParseArchive reads a whole ZIP archive of size bytes from r and returns its validated composer.json. The archive must hold 1 to 4,096 entries within ArchiveLimit, with no absolute, backslashed or dot-segment path, each read to its end, and exactly one composer.json, at the root or in one top-level folder, within MetadataLimit and with a valid name (ValidName). The version is the file's own, or override when the file has none; a non-empty override must be valid and agree with the file's version, and the result must have a valid version. It stops, wrapping ctx's error, when ctx ends.
func (Package) Document ¶
Document returns the package's composer.json as a catalog entry: every retained field, with name and version set to the validated identity, so the entry has a version even when a composer.version property supplied it. A package without fields yields just the name and version.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package composerhttp serves Composer 1 local catalogs and Composer 2 metadata through the native Artifactory Composer URL, /artifactory/api/composer/{repoKey}, on local, federated, remote and virtual repositories: packages.json, a package's Composer 2 metadata, its archives and the reindex operation.
|
Package composerhttp serves Composer 1 local catalogs and Composer 2 metadata through the native Artifactory Composer URL, /artifactory/api/composer/{repoKey}, on local, federated, remote and virtual repositories: packages.json, a package's Composer 2 metadata, its archives and the reindex operation. |