composerhttp

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: 25 Imported by: 0

Documentation

Overview

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. Archive validation and the package rules are the format package's (artifacts/ecosystem/composer); this package answers HTTP with them.

Role

artifacts module, ecosystem layer: the native Composer 1 and 2 catalog protocol of the Composer slice. It is named composerhttp so that it does not shadow net/http. Outside tests, only its own http subtree, the module's http adapters and app may import it (decision 0044, dependency rule 9).

Inputs

  • Driving: the server, which mounts Protocol through the router kit (pkgroute) for repositories of package type composer. Archives are published through the generic item routes, not through this protocol; the format's Handler admits them there.
  • Driven: the router kit (pkgroute.Kit), whose store (pkgroute.Store) the handlers also reach through DB(), and which resolves the repository (a key with the -cache suffix names a remote's cache) and the caller, checks permissions, lists items and reads their properties, builds a virtual repository's member requests, serves items and writes errors; the blob store in Options, from which the hosted catalogs read every archive; the remote source service, which fetches a remote's upstream packages.json, package metadata and archives into the remote cache; and the format package.

Outputs

  • Protocol and Options: the routes, the source of each repository class and the Artifactory error profile.
  • Answers: packages.json, which gives a Composer 1 user agent a local or federated repository's full version map and any other caller only the metadata-url template of the Composer 2 documents; a package's stable or development versions, each with a dist entry that points back through this repository; an archive's bytes; and a plain-text acknowledgement of a reindex.

Invariants

  • Hosted catalogs are built from the stored archives on every request and list only archives the caller may read; an unknown package answers 404, and a stored archive that no longer validates answers 502.
  • A dist URL names this repository under its trusted base URL, so the client downloads through it and its permissions; a hosted archive carries its SHA-1 as the shasum.
  • A virtual repository's members are distinct and read in order; the first readable member that holds a package supplies all its versions.
  • The download policy (decision 0032): a blacked-out repository, a remote's included, refuses packages.json and p2 metadata with the blackout's 404 naming the request path, after read permission; 7.x does not document where it keeps them, so the patterns do not refuse them. An archive answers its own path's policy, and a pattern on it leaves the release listed. A virtual repository resolves a package past a blacked-out member, passes an archive the resolved member refuses on to the next member that holds the version, and answers its own patterns on an archive with "No repository found to serve the request".
  • A remote accepts an upstream metadata-url only on the upstream's own scheme and host, and dist URLs only as http or https without credentials, query or fragment. Its entries are served without their source field, and an archive is delivered only when it holds the package and version asked for and matches its declared SHA-1, if any.
  • A catalog or archive request with a query string answers 400.
  • Statuses and error texts stay byte-identical.

References

Status

Implemented P9c, which delivered the plan's P30 group (issues #762 to #768). Moved here in P9d.

Testing

  • composer_test.go: hosted metadata and dist entries, development versions and stored integrity, virtual member order, missing members and the -cache alias, refusals and virtual authority, the trusted base URL, and route parsing.
  • remote_test.go: the remote's metadata cache and integrity checks, untrusted upstream metadata, access revoked at delivery, a remote without a registry URL, source failures, and a virtual repository that selects a remote's archive.
  • download_policy_test.go: the download policy on hosted, virtual and remote repositories.
  • served_copy_fault_test.go: a cached root or p2 document whose copy fails a read as the route reads it answers 500 and stays cached.

The router's guard TestAccNativeComposerRoutesAvoidHandwrittenStubs (internal/app) and the @composer acceptance scenarios, with the native Composer client, drive it through the whole server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Protocol

func Protocol(o Options) pkgroute.Protocol

Protocol returns the Composer protocol for the router kit, under /artifactory/api/composer/{repoKey}: GET and HEAD of packages.json, of a package's Composer 2 metadata (p2/<vendor>/<package>.json, and p2/<vendor>/<package>~dev.json for development versions) and of an archive (dist/<vendor>/<package>/<version>.zip), and POST of reindex, which needs Manage and verifies a local or federated repository's stored archives. A key with the -cache suffix names a remote's cache, which answers without contacting the upstream. Local and federated repositories are served from their stored archives, virtual ones from their members in order, and remote ones through o.RemoteSources when it is set; a class without a source answers 501. The virtual class's source supports no single-item lookup, because the protocol reads a virtual repository's members itself.

Types

type Options

type Options struct {
	Blobs         blob.Store
	RemoteSources *source.Service
}

Options configures the Composer protocol. Blobs opens the stored archives the hosted catalogs are read from; without it a local or federated repository's catalogs, archives and reindex answer 501. RemoteSources serves remote repositories and fetches through them; nil leaves the remote class without a source, so a remote repository answers 501.

Jump to

Keyboard shortcuts

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