feat(codeartifact): bridge DescribePackageVersion to Maven/npm/pypi sidecars (#5715)

Maven, npm, and pypi publish straight to their own sidecar and never create
the generic-format packageVersions record DescribePackageVersion depended on,
so it always 404ed for those three formats. Real CodeArtifact's
PackageVersionDescription has no asset listing at all, so the bridge only
needs a cheap per-sidecar existence check for the exact version, not asset
enumeration: Verdaccio's packument already lists every version, Reposilite's
own details API answers directory existence the same way container
readiness probing already relies on, and pypiserver's per-project JSON
listing already groups files by version. The revision is synthesized the
same deterministic way GetPackageVersionAsset's own bridge already does, so
describing a version and fetching one of its assets see the same value.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-15 22:14:08 -05:00
1 parent a68e6bc768
commit 1ba977a14c
10 files changed
+345 -38

No files matched your search

@@ -771,12 +771,67 @@ public class CodeArtifactService implements Resettable {
validatePackageToken("namespace", namespace);
}
String owner = effectiveOwner(domainOwner);
// Maven, npm, and pypi are metadata-free passthroughs straight to their own sidecar, the
// same reason getPackageVersionAsset bridges to them (see
// getContainerBackedPackageVersionAsset): publish for these formats never goes through
// publishPackageVersion, so packageVersions can never hold a record for them.
if (CONTAINER_BACKED_FORMATS.contains(format)) {
return describeContainerBackedPackageVersion(region, domain, owner, repository, format, namespace,
packageName, version);
}
String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);
return packageVersions.getForAccount(owner, key)
.orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version"));
}
/**
* Unlike {@code GetPackageVersionAsset}, real CodeArtifact's {@code DescribePackageVersion}
* response has no asset listing at all (confirmed against the wire model: {@code
* PackageVersionDescription} has no such member; enumerating a version's files is {@code
* ListPackageVersionAssets}'s job, a separate, still-unimplemented action). All this needs
* from a sidecar is a yes/no answer to "does this exact version exist," which is cheap for
* every one of the three: Verdaccio's packument already lists every version it holds,
* Reposilite's own details API answers directory existence the same way {@link
* #ensureFormatContainerId}'s readiness probe already relies on, and pypiserver's per-project
* JSON listing already groups files by version the same way {@code deletePackage} already
* reads it.
*
* <p>A sidecar-backed version is always reported {@code Published}: nothing here ever leaves
* one in {@code Unfinished}, the way a generic publish deliberately can, since a real {@code
* mvn deploy}/{@code npm publish}/{@code twine upload} only ever lands a version by completing
* it in one shot.
*
* <p>Namespace is validated through the same shared {@link #validatePackageCoordinates} every
* other package-level operation already uses, rather than a one-off maven-only check: a pypi
* version genuinely has no namespace, so a caller-supplied one must be rejected outright, not
* silently ignored and echoed back in the response as though it belonged to the package.
*/
private CodeArtifactPackageVersion describeContainerBackedPackageVersion(String region, String domain,
String owner, String repository, String format, String namespace, String packageName, String version) {
validatePackageCoordinates(format, namespace, packageName, "describing a version of");
String repoId = ensureFormatContainerId(format, region, domain, owner, repository);
RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
.orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version"));
if (!manager.packageVersionExists(repoId, domain, repository, namespace, packageName, version)) {
throw notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version");
}
CodeArtifactPackageVersion pv = new CodeArtifactPackageVersion();
pv.setDomainName(domain);
pv.setDomainOwner(owner);
pv.setRegion(region);
pv.setRepositoryName(repository);
pv.setFormat(format);
pv.setNamespace(namespace);
pv.setPackageName(packageName);
pv.setVersion(version);
pv.setStatus("Published");
pv.setRevision(synthesizeContainerBackedRevision(repoId, namespace, packageName, version));
return pv;
}
/**
* Floci never ingests packages from an upstream source, so every package it holds was first
* published directly. That is the one case where CodeArtifact's default origin controls are
@@ -1085,25 +1140,6 @@ public class CodeArtifactService implements Resettable {
return new PackageVersionAssetResult(asset, pv.getRevision());
}
/**
* There's no stored revision for a sidecar-backed format to compare against, so one is
* synthesized from the version coordinate itself (this repository's own sidecar container id,
* plus namespace/package/version), not the fetched asset's own bytes: a real revision is
* shared by every asset of one package version (a Maven version's JAR and POM alike), so
* hashing per-asset content would give a client that described the version once, then tried
* to fetch a second asset at that same revision, a spurious not-found on the second call even
* though both assets genuinely exist. Keying on the sidecar container id, not just the bare
* namespace/package/version strings, keeps two different repositories (even two with the
* identical coordinates) from ever synthesizing the same revision.
*
* <p>Doesn't change when a new asset is published to the version afterward, unlike a real
* stored revision: tracking that would mean enumerating every asset a sidecar holds for a
* version on every call, the same capability {@code DescribePackageVersion} would need and
* doesn't have either for these formats (see the Known limitations doc). Accepted for the
* same reason: nothing before this change ever let a client obtain a revision for these
* formats in the first place (not even a stale one), so this isn't a regression against any
* previously working staleness check.
*/
private PackageVersionAssetResult getContainerBackedPackageVersionAsset(String region, String domain,
String owner, String repository, String format, String namespace, String packageName, String version,
String assetName, String packageVersionRevision) {
@@ -1132,10 +1168,24 @@ public class CodeArtifactService implements Resettable {
}
/**
* The same synthesized revision {@link #getContainerBackedPackageVersionAsset} uses, shared
* so {@link #getPackageVersionReadme}'s npm/pypi answers report a revision consistent with
* whatever {@code GetPackageVersionAsset} would already report for the same version
* coordinate, rather than two independently-computed stand-ins that happen to differ.
* There's no stored revision for a sidecar-backed format to compare against, so one is
* synthesized from the version coordinate itself (this repository's own sidecar container id,
* plus namespace/package/version), not the fetched asset's own bytes: a real revision is
* shared by every asset of one package version (a Maven version's JAR and POM alike), so
* hashing per-asset content would give a client that described the version once, then tried
* to fetch a second asset at that same revision, a spurious not-found on the second call even
* though both assets genuinely exist. Keying on the sidecar container id, not just the bare
* namespace/package/version strings, keeps two different repositories (even two with the
* identical coordinates) from ever synthesizing the same revision.
*
* <p>Shared by {@link #getContainerBackedPackageVersionAsset}, {@link
* #describeContainerBackedPackageVersion}, and {@link #getPackageVersionReadme}'s npm/pypi
* answers, so a client calling any two of them for the same version coordinate always sees one
* consistent revision rather than independently-computed stand-ins that happen to differ.
* Doesn't change when a new asset is published to the version afterward, unlike a real stored
* revision would: nothing before this helper existed ever let a client obtain a revision for
* these formats in the first place (not even a stale one), so this isn't a regression against
* any previously working staleness check.
*/
private static String synthesizeContainerBackedRevision(String repoId, String namespace, String packageName,
String version) {
@@ -122,6 +122,20 @@ public class PypiserverSidecarClient implements RepositorySidecarManager {
return simpleIndex(baseUrl, packageName).isPresent();
}
/**
* Reuses the same per-project JSON listing {@link #deletePackage} already reads (grouped by
* release the same way the real PyPI JSON API is), rather than the simple index: the simple
* index has no per-file version field of its own to group by, only filenames that would need
* the same version-boundary parsing {@link #filenameEmbedsVersion} does for a known asset name,
* which isn't available here.
*/
@Override
public boolean packageVersionExists(String repositoryContainerId, String domain, String repository,
String namespace, String packageName, String version) {
String baseUrl = ensureReady(repositoryContainerId, null);
return packageFiles(baseUrl, packageName).stream().anyMatch(file -> file.version().equals(version));
}
/**
* Removes a whole package, every version at once, confirmed against a live container: the pinned
* image's management endpoint ({@code POST /} with {@code :action=remove_pkg}) deletes one exact
@@ -181,6 +181,36 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
return path.toString();
}
/**
* Reposilite has no per-GAV metadata beyond a directory listing, so this asks its own details
* API (the same one {@link #isRepositoryServable} already relies on to distinguish "repository
* not provisioned yet" from "path genuinely not there") for the version directory itself,
* rather than any one file inside it: a clean 200 there, directory listing or not, is enough to
* confirm the version exists, since Reposilite only serves a directory's details for a path it
* actually has.
*/
@Override
public boolean packageVersionExists(String repositoryContainerId, String domain, String repository,
String namespace, String packageName, String version) {
String baseUrl = manager.ensureReady();
String path = "/api/maven/details" + packageDirectoryPath(repositoryContainerId, namespace, packageName)
+ SidecarUriUtils.encodeSegment(version);
HttpRequest request = HttpRequest.newBuilder(SidecarUriUtils.combine(URI.create(baseUrl), path))
.timeout(Duration.ofSeconds(30))
.header("Authorization", manager.basicAuthHeader())
.GET()
.build();
int status = send(request, BodyHandlers.discarding()).statusCode();
if (status == 404) {
return false;
}
if (status != 200) {
throw new IllegalStateException("Could not look up " + packageName + " " + version + " on the "
+ "Reposilite sidecar: upstream returned " + status);
}
return true;
}
/** Ensures a Reposilite repository named {@code repoId} exists, creating it if not. */
public void ensureRepository(String repoId) {
String baseUrl = manager.ensureReady();
@@ -65,6 +65,21 @@ public interface RepositorySidecarManager {
boolean packageExists(String repositoryContainerId, String domain, String repository, String namespace,
String packageName);
/**
* {@code true} when this sidecar holds exactly the named version of the named package, for
* bridging {@code DescribePackageVersion} when there is no generic-format record to describe:
* Maven, npm, and pypi are metadata-free passthroughs straight to their sidecar, so nothing in
* {@code CodeArtifactService}'s own package-version store ever records what they hold, the
* same reason {@link #fetchPackageVersionAsset} exists. Unlike that method, there is no asset
* name to confirm against: real CodeArtifact's own {@code DescribePackageVersion} response has
* no asset listing at all, so a cheap existence check is all this needs. {@code namespace}
* follows the same convention as {@link #fetchPackageVersionAsset}: {@code null} for a format
* that has none. A repository that was never started for this format holds nothing, so this is
* {@code false}.
*/
boolean packageVersionExists(String repositoryContainerId, String domain, String repository, String namespace,
String packageName, String version);
/**
* Deletes every version of the named package from this sidecar's own backing storage. Every
* sidecar Floci currently backs (Reposilite, Verdaccio, pypiserver) can do this; the default
@@ -100,6 +100,16 @@ public class VerdaccioSidecarClient implements RepositorySidecarManager {
return fetchPackageDocument(baseUrl, namespace, packageName).isPresent();
}
/** Verdaccio's own packument already lists every version it holds, keyed by version string. */
@Override
public boolean packageVersionExists(String repositoryContainerId, String domain, String repository,
String namespace, String packageName, String version) {
String baseUrl = ensureReady(repositoryContainerId, publicUrl(domain, repository));
return fetchPackageDocument(baseUrl, namespace, packageName)
.map(document -> document.path("versions").has(version))
.orElse(false);
}
/**
* Removes a whole package, every version at once, the same way the real npm CLI's final
* unpublish step does: fetch the packument for its current {@code _rev}, then {@code DELETE} the