mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
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:
1 parent
a68e6bc768
commit
1ba977a14c
10 files changed
+345
-38
No files matched your search
@@ -268,19 +268,18 @@ state.
|
||||
itself has no JSON index support to pass through. Low practical risk in itself, since PEP 691
|
||||
requires clients to accept HTML as a fallback and pip/uv both do, but it is a real gap against
|
||||
AWS's documented surface, not just a quirk of the sidecar.
|
||||
- **`DescribePackageVersion` can't see Maven-, npm-, or pypi-uploaded package versions.** Those
|
||||
three formats' repository endpoints are deliberately metadata-free passthroughs straight to
|
||||
their sidecar container (Reposilite/Verdaccio/pypiserver) and never create the generic-format
|
||||
package-version record this action depends on (`CodeArtifactService.describePackageVersion`
|
||||
only ever looks up `packageVersions.getForAccount`, the record only the `generic` format's
|
||||
`PublishPackageVersion` flow creates). `GetPackageVersionAsset` no longer has this gap: it
|
||||
bridges to each format's own sidecar (via a new `RepositorySidecarManager.fetchPackageVersionAsset`
|
||||
method each sidecar client implements) when there's no generic-format record, so it now works
|
||||
uniformly across formats the way real CodeArtifact's does. `DescribePackageVersion` is a harder
|
||||
problem for the same bridge: it describes every asset and the status of a whole version, not one
|
||||
named file, and none of these sidecars expose that shape cheaply (Reposilite has no per-GAV
|
||||
metadata beyond file listings; Verdaccio's own registry API could answer it for npm but Maven and
|
||||
pypi have nothing equivalent), so it remains unbridged and still 404s for these three formats.
|
||||
- **`DescribePackageVersion` reports only format/namespace/packageName/version/revision/status/origin
|
||||
for Maven, npm, and pypi, same as it does for generic.** Real CodeArtifact's `PackageVersionDescription`
|
||||
can also carry `displayName`, `summary`, `homePage`, `sourceCodeRepository`, `licenses`, and
|
||||
`publishedTime`, extracted from the package's own metadata; none of those are populated for any
|
||||
format today, container-backed or generic. For Maven, npm, and pypi, the version's existence is
|
||||
confirmed directly against its sidecar (`RepositorySidecarManager.packageVersionExists`) rather
|
||||
than through the generic-format-only `packageVersions` record `GetPackageVersionAsset`'s own
|
||||
bridge also moved past, and the revision is synthesized the same deterministic way
|
||||
`GetPackageVersionAsset`'s bridge already does, so describing a version and then fetching one of
|
||||
its assets see the same revision. Every sidecar-backed version reports `Published`: none of
|
||||
these three formats' native publish paths (`mvn deploy`, `npm publish`, `twine upload`) can leave
|
||||
a version in any other status the way a generic publish deliberately can with `unfinished=true`.
|
||||
- **`DescribePackage`'s origin controls default to `publish: ALLOW`/`upstream: BLOCK`** (the
|
||||
default for a package whose first version was published directly, since Floci never ingests
|
||||
packages from an upstream source) **until a caller sets them explicitly with
|
||||
@@ -298,8 +297,9 @@ state.
|
||||
- **`DescribeDomain`'s `assetSizeBytes` only counts what was published after this field started
|
||||
being computed.** Generic-format bytes are summed live from the still-existing
|
||||
`PublishPackageVersion` records, so they're always current. Maven, npm, and pypi have no such
|
||||
record to sum (the same gap `DescribePackageVersion` has), so each proxy reports its own
|
||||
successfully-written byte count directly; a package published through one of those three formats
|
||||
record to sum (the same absent generic-format record `DescribePackageVersion`'s own bridge works
|
||||
around by asking the sidecar directly instead), so each proxy reports its own successfully-written
|
||||
byte count directly; a package published through one of those three formats
|
||||
before this accounting existed was never reported and is not retroactively counted. A genuine
|
||||
conflict or an idempotent no-op retry (any of the three formats' own duplicate-publish
|
||||
protection) correctly adds nothing either way. Both `DeleteRepository` and `DeletePackage` clean
|
||||
|
||||
+73
-23
@@ -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) {
|
||||
|
||||
+14
@@ -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
|
||||
|
||||
+30
@@ -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();
|
||||
|
||||
+15
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
|
||||
+51
@@ -409,6 +409,57 @@ class CodeArtifactMavenDockerIntegrationTest {
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code DescribePackageVersion} used to 404 for every
|
||||
* Maven-deployed version the same reason {@code GetPackageVersionAsset} did. Confirms the
|
||||
* bridge asks the real Reposilite sidecar (via its details API, not a mock) whether the
|
||||
* version directory itself exists, and that the synthesized revision matches what {@link
|
||||
* #getPackageVersionAssetBridgesToTheRealReposiliteSidecar} already got for the same
|
||||
* coordinates.
|
||||
*/
|
||||
@Test
|
||||
@Order(12)
|
||||
void describePackageVersionBridgesToTheRealReposiliteSidecar() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.body("packageVersion.status", equalTo("Published"))
|
||||
.body("packageVersion.namespace", equalTo("com.example"))
|
||||
.body("packageVersion.packageName", equalTo("spike"))
|
||||
.body("packageVersion.version", equalTo("1.0.0"));
|
||||
|
||||
String assetRevision = given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=1.0.0&asset=spike-1.0.0.jar")
|
||||
.then().statusCode(200)
|
||||
.extract().header("X-PackageVersionRevision");
|
||||
String describeRevision = given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("packageVersion.revision");
|
||||
assertEquals(assetRevision, describeRevision);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describePackageVersionRequiresANamespaceForMaven() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&package=spike&version=1.0.0")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void describePackageVersionReturns404ForAMavenVersionThatWasNeverDeployed() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=9.9.9")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* A throwaway groupId/artifactId, not {@link #GAV}: deleting it exercises Reposilite's real
|
||||
* directory delete (confirmed live before this was built: a single {@code DELETE} on the
|
||||
|
||||
+23
@@ -359,6 +359,29 @@ class CodeArtifactNpmDockerIntegrationTest {
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code DescribePackageVersion} used to 404 for every
|
||||
* npm-published version the same reason {@code GetPackageVersionAsset} did. Confirms the
|
||||
* bridge checks the real Verdaccio packument's own {@code versions} map (not a mock) for the
|
||||
* published version, and 404s for one that was never published.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void describePackageVersionBridgesToTheRealVerdaccioSidecar() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.body("packageVersion.status", equalTo("Published"))
|
||||
.body("packageVersion.packageName", equalTo(PACKAGE_NAME))
|
||||
.body("packageVersion.version", equalTo("1.0.0"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=9.9.9")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* A throwaway package, not {@link #PACKAGE_NAME}: deleting it exercises the real Verdaccio
|
||||
* unpublish-whole-package mechanism (GET the packument's own {@code _rev}, then {@code DELETE}
|
||||
|
||||
+23
@@ -373,6 +373,29 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code DescribePackageVersion} used to 404 for every
|
||||
* pypi-uploaded version the same reason {@code GetPackageVersionAsset} did. Confirms the
|
||||
* bridge reads the real pypiserver container's own per-project JSON listing (not a mock) to
|
||||
* confirm the version exists, and 404s for one that was never uploaded.
|
||||
*/
|
||||
@Test
|
||||
@Order(12)
|
||||
void describePackageVersionBridgesToTheRealPypiserverSidecar() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.body("packageVersion.status", equalTo("Published"))
|
||||
.body("packageVersion.packageName", equalTo(PACKAGE_NAME))
|
||||
.body("packageVersion.version", equalTo("1.0.0"));
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=9.9.9")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* pypiserver has no single whole-package delete route the way Verdaccio and Reposilite do, but
|
||||
* its own management endpoint ({@code POST /} with {@code :action=remove_pkg}) does delete a
|
||||
|
||||
+91
@@ -1389,6 +1389,97 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionBridgesToReposiliteForMavenSinceNoGenericRecordCanExist() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created =
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String repoId = created.getSidecarContainerIds().get("maven");
|
||||
when(reposiliteClient.packageVersionExists(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
|
||||
eq("my-artifact"), eq("1.0.0"))).thenReturn(true);
|
||||
|
||||
CodeArtifactPackageVersion pv = service.describePackageVersion(REGION, "dom", null, "repo", "maven",
|
||||
"com.example", "my-artifact", "1.0.0");
|
||||
|
||||
assertEquals("maven", pv.getFormat());
|
||||
assertEquals("com.example", pv.getNamespace());
|
||||
assertEquals("my-artifact", pv.getPackageName());
|
||||
assertEquals("1.0.0", pv.getVersion());
|
||||
assertEquals("Published", pv.getStatus());
|
||||
assertEquals(Digests.sha256Hex((repoId + "/com.example/my-artifact/1.0.0").getBytes(StandardCharsets.UTF_8)),
|
||||
pv.getRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionSynthesizesTheSameRevisionGetPackageVersionAssetWouldFor() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created =
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String repoId = created.getSidecarContainerIds().get("npm");
|
||||
when(verdaccioClient.packageVersionExists(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
|
||||
eq("1.0.0"))).thenReturn(true);
|
||||
when(verdaccioClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
|
||||
eq("1.0.0"), eq("my-pkg-1.0.0.tgz")))
|
||||
.thenReturn(Optional.of("tarball bytes".getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
CodeArtifactPackageVersion described = service.describePackageVersion(REGION, "dom", null, "repo", "npm",
|
||||
null, "my-pkg", "1.0.0");
|
||||
PackageVersionAssetResult asset = service.getPackageVersionAsset(REGION, "dom", null, "repo", "npm", null,
|
||||
"my-pkg", "1.0.0", "my-pkg-1.0.0.tgz", null);
|
||||
|
||||
assertEquals(described.getRevision(), asset.packageVersionRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionBridgesToPypiserver() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
when(pypiserverClient.packageVersionExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
|
||||
eq("1.0.0"))).thenReturn(true);
|
||||
|
||||
CodeArtifactPackageVersion pv = service.describePackageVersion(REGION, "dom", null, "repo", "pypi", null,
|
||||
"my-pkg", "1.0.0");
|
||||
|
||||
assertEquals("Published", pv.getStatus());
|
||||
assertEquals("my-pkg", pv.getPackageName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionReturns404WhenTheSidecarHasNoSuchVersionForAContainerBackedFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
when(pypiserverClient.packageVersionExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
|
||||
eq("2.0.0"))).thenReturn(false);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.describePackageVersion(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "2.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
assertEquals("2.0.0", e.getExtendedData().get("resourceId"));
|
||||
assertEquals("package-version", e.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionRequiresNamespaceForMaven() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.describePackageVersion(REGION, "dom", null,
|
||||
"repo", "maven", null, "my-artifact", "1.0.0"));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
verify(reposiliteClient, never()).packageVersionExists(any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageVersionRejectsANamespaceForPypi() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.describePackageVersion(REGION, "dom", null,
|
||||
"repo", "pypi", "ns", "my-pkg", "1.0.0"));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
verify(pypiserverClient, never()).packageVersionExists(any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePackageReportsTheDirectPublishDefaultsAndMatchesExactly() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
|
||||
Reference in new issue
Block a user