mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 23:59:27 -05:00
feat(codeartifact): retain npm packages from a public external connection (#7198)
npm's native registry route can now retain a missing package from a repository's own public:npmjs external connection and serve it, instead of always 404ing, mirroring the AWS-documented external-connection behavior already shipped for Maven (#6889) and NuGet (#7104). Unlike Maven's GAV layout and NuGet's {id}/{version}/{filename} content route, npm's own real wire protocol has no request shape that names one version: npm install <pkg>@<version> always fetches the bare package's full packument first (confirmed against pacote's own source, RegistryFetcher#packumentUrl, always the bare package path) and only picks the version out of its own versions map afterward. So this does two things together, not just one: - A bare packument read (the one every real npm install actually sends) merges the real registry's own versions and dist-tags into whatever Verdaccio already knows locally, computed fresh per request and never written to Verdaccio itself (its own publish protocol has no way to record a version's metadata without that version's real tarball bytes in the very same call, confirmed against a live container). Every newly-merged version's dist.tarball is rewritten to this repository's own proxy URL under a deterministic <bareName>-<version>.tgz shape; dist.shasum/dist.integrity are kept exactly as the real registry declared them, since there is no real content yet to hash locally. - A tarball download for a version not yet genuinely retained triggers the real fetch, the same claim/fence/origin-tracking machinery Maven and NuGet already use (closing the same race against a concurrent DeletePackageVersions/direct push), reusing CodeArtifactService's already-generalized claimRetainedVersionOrigin/retainAssetUnderVersionFence methods directly. New: NpmExternalConnectionClient (the outbound client for public:npmjs) and CodeArtifactNpmExternalConnectionImporter (the merge and retention logic), wired into CodeArtifactNpmDataPlane's existing raw proxy. Deliberately scoped the same way Maven/NuGet's own base PRs were: no caching/TTL on the merge fetch (a live check against the real registry on every packument read for a connected repository, matching the same no-caching fidelity level Maven's own maven-metadata.xml merge already ships with), and the documented but rarely-used single-version registry endpoint (GET /<pkg>/<version>) is not specially handled, since real npm install never sends it either. Update: fixed three issues Greptile's review caught, all specific to npm's own two-step retention (a plain cache-miss asset fetch, as NuGet/Maven's retention already was, is not enough here): - retainAssetUnderVersionFence's own write was always the fixed RepositorySidecarManager# storePackageVersionAsset call, which builds a minimal version document with no dependencies/ engines/scripts. Generalized it to take the actual write as a plain Runnable instead, so npm's own call can reuse the real registry's full-form version document verbatim (the same reuse-the-source-document treatment VerdaccioSidecarClient#copyPackageVersionAsset already gives a version copied from another repository), fetched once, only when a version is actually retained, via a new NpmExternalConnectionClient#fetchFullPackument. NuGet's own call site wraps the exact same plain storePackageVersionAsset call it always made. - Verdaccio always points a fresh package's dist-tags.latest at whichever version was retained most recently (confirmed live, nothing a retention write sends can suppress it), so a plain retention could silently move what an unpinned npm install or ListPackageVersions' defaultDisplayVersion resolves to. Fixed on both sides of that same bug: the merge now only lets an external dist-tag replace a local one that itself points at an externally-retained version, and CodeArtifactService#listPackageVersions ignores preferredDisplayVersion the same way when it names one. - A retained version's readme was never captured, so GetPackageVersionReadme 404ed on it even though the tarball existed; the full packument fetch above also captures the package's own readme (confirmed live: it only ever lives at the top of the full packument, never per version) the same way a native publish's own readme capture already works. Verified two ways beyond the automated suite: - A Docker-gated integration test retains a real package (is-even 1.0.0) from the real, live npmjs.com, through a real Verdaccio sidecar: a bare packument read merges the real version in without yet counting any bytes, a subsequent tarball fetch retains it and counts its bytes, a refetch does not double-count, mixed-case-irrelevant upstream-block enforcement blocks both the merge and the retention, a genuinely-missing package stays 404, the retained version's EXTERNAL origin reporting is confirmed against the real sidecar, and its real dependencies/ engines and readme are confirmed readable back from the real sidecar afterward. - Direct curl checks against the real registry.npmjs.org confirmed the exact packument/tarball URL shapes this client builds, including the %2F-escaped scope separator the packument endpoint specifically needs (unlike the tarball path, which uses a literal slash), and that the abbreviated packument form carries dependencies/engines but not scripts or any readme. Update: fixed a fourth issue from the same re-review, found once the three fixes above landed: mergedPackument always fetched the real registry's abbreviated form, even when the real npm client's own Accept header asked for the full one (the shape npm view <pkg> readme-style commands use), so a package the merge had not yet retained anything for showed no readme at all. The merge now honors that header, fetching the real full packument only when the request actually asked for it, and copies its package-level descriptive fields (readme among them) in the same never-override-local way everything else here already merges, with no change to the hot npm install path's own abbreviated fetch. Update 3: fixed a fifth issue from the same re-review: mergedPackument's own real registry fetch is a genuine network round trip, and nothing held any lock across it, so a DeleteRepository finishing its own cleanup while that fetch was still in flight let the later ensureReady call start a fresh container under an id the delete had already released, one nothing would ever release again. Added a re-check that the repository still exists right after that fetch, before this method ever touches the sidecar. This narrows the window back down to an ordinary check-then-act gap rather than one stretched out by a real network round trip, not a full fix: VerdaccioSidecarManager's own beginUse/endUse are no-ops today (unlike PypiserverSidecarManager's), so nothing here can fully close this yet. Filed #7204 to track giving it real in-flight-use tracking as its own, cross-cutting fix. Update 4: fixed a sixth issue from the same re-review: DisposePackageVersions deletes a version's real Verdaccio content outright, so versions.has(version) alone could not tell a disposed version apart from one never retained at all, and the merge could add a disposed version straight back in from the real registry's own still-unaware listing, even pointing dist-tags.latest at it. An unpinned npm install could then select it, only to have the download correctly, but confusingly, fail. The merge now excludes any externally-named version this repository has marked Archived or Disposed, reusing the same requireContainerBackedVersionDownloadable check the native download route itself already enforces.
This commit is contained in:
1 parent
dfaab8ba4c
commit
b3bee2d407
13 files changed
+2121
-35
No files matched your search
@@ -83,8 +83,11 @@ retained version's own origin checked against any later asset request for the sa
|
||||
(rejecting one that would mix in a different connection's bytes), and a direct `mvn deploy` of a
|
||||
version already present in the connection rejected with `ConflictException`. See the
|
||||
upstream-resolution limitation further down for exactly what this does not yet cover (a
|
||||
repository-to-repository `upstreams` chain, for any format including Maven; npm/pypi/nuget's own
|
||||
external connections).
|
||||
repository-to-repository `upstreams` chain, for any format including Maven). npm's own `public:npmjs`
|
||||
external connection and NuGet's own `public:nuget-org` one resolve the same way, each against its
|
||||
own format's one real public connection and documented rules; see their own repository endpoint
|
||||
sections and the known-limitations entry below for exactly how. pypi's own external connection does
|
||||
not yet.
|
||||
|
||||
`PublishPackageVersion` creates a package version in the `Unfinished` state when the `unfinished`
|
||||
flag is set, and `Published` otherwise. While still `Unfinished`, publishing a new asset name is
|
||||
@@ -340,11 +343,11 @@ state.
|
||||
would mean isolating each sidecar on its own Docker network reachable only from Floci's own
|
||||
process, a change that would need to apply uniformly across all four sidecar-backed formats, not
|
||||
a one-off fix to any single proxy.
|
||||
- **Only the Maven endpoint's own external connection actually resolves; nothing else does.**
|
||||
- **The Maven, NuGet, and npm endpoints' own external connections resolve; pypi's does not.**
|
||||
On real CodeArtifact, a repository with another repository configured as an upstream
|
||||
(`UpdateRepository`'s `upstreams`) or with an `AssociateExternalConnection` to a public
|
||||
repository serves packages from those sources too, not just its own. Floci's Maven endpoint
|
||||
now does this for a direct external connection to one of the 5 real public Maven repositories
|
||||
does this for a direct external connection to one of the 5 real public Maven repositories
|
||||
(`public:maven-central`, `public:maven-clojars`, `public:maven-commonsware`,
|
||||
`public:maven-googleandroid`, `public:maven-gradleplugins`): a GET/HEAD miss fetches and
|
||||
retains the package version from the real public repository, following AWS's own documented
|
||||
@@ -352,13 +355,22 @@ state.
|
||||
name imported only on demand; a retained version's origin checked against any later asset
|
||||
fetched for it, rejecting one from a different connection; `upstream: BLOCK` respected). A real
|
||||
`mvn deploy` of a version already present in the external connection is also rejected (409),
|
||||
matching AWS's documented publish-side behavior. None of this applies to a repository-to-
|
||||
repository upstream (`UpdateRepository`'s `upstreams`, for any format including Maven, which is
|
||||
a materially different mechanism, not yet built) or to npm, pypi, or nuget's own external
|
||||
connections, which still 404 exactly as before: the pypi proxy's pypiserver container is
|
||||
started with `--disable-fallback`, and the nuget proxy's BaGetter container with
|
||||
`Mirror__Enabled=false`, specifically so neither ever silently redirects a missing package to
|
||||
the real, public PyPI or nuget.org.
|
||||
matching AWS's documented publish-side behavior. NuGet's own `public:nuget-org` external
|
||||
connection works the same way, against its own one real public connection and its own
|
||||
single-asset-per-version shape; a real `nuget push`/`dotnet nuget push` of a version already
|
||||
present in the connection is rejected the same way. npm's own `public:npmjs` external connection
|
||||
works differently, since `npm install <pkg>@<version>` never names a single version on the wire
|
||||
the way Maven's GAV layout or NuGet's content route do, only the bare package: a packument read
|
||||
merges the real registry's own versions and dist-tags into whatever this repository already
|
||||
knows (never written back to Verdaccio itself, since its publish protocol has no way to record a
|
||||
version's metadata without that version's real tarball bytes in the same call), and a tarball
|
||||
download for a version not yet genuinely retained triggers the real fetch and retention, using
|
||||
the same claim/fence/origin-tracking machinery. None of this applies to a repository-to-
|
||||
repository upstream (`UpdateRepository`'s `upstreams`, for any format including Maven, NuGet,
|
||||
and npm, which is a materially different mechanism, not yet built) or to pypi's own external
|
||||
connection, which still 404s exactly as before: the pypi proxy's pypiserver container is started
|
||||
with `--disable-fallback`, specifically so it never silently redirects a missing package to the
|
||||
real, public PyPI.
|
||||
- **Maven external-connection retention is the one place this emulator makes a real outbound
|
||||
call to the public internet**, rather than only ever talking to a container it started itself.
|
||||
An offline environment, or a real outage of the public repository being connected to, means a
|
||||
|
||||
Reference in new issue
Block a user