Repository navigation
Description
While reviewing #1410 I came across a few older problems around manifest handling. #1410 didn't cause them, so I'm putting them here instead of holding up that PR. All three exist on both main and 5.x.x.
1. Manifest YAML is written with the platform default charset
ApplicationManifestUtils.write(OutputStream, ...) (line 113) and ApplicationManifestUtilsV3.write(OutputStream, ...) (line 111) both do:
try (Writer writer = new OutputStreamWriter(out)) {There's no charset, so it uses whatever the JVM default is. CAPI expects UTF-8. On Java 8 to 17 on Windows the default is usually cp1252, so any non-ASCII text in env values, labels, routes and so on gets mangled or turned into ?. pushManifestV3 uses this method to build the apply_manifest body, so this affects real pushes, not just files on disk.
Suggested fix, in both classes:
try (Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {2. pushManifestV3 throws instead of returning an error Mono
In DefaultApplications.pushManifestV3 the manifest is serialized right when the method is called, before anyone subscribes, and a failure is thrown as a plain RuntimeException:
byte[] manifestSerialized;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ApplicationManifestUtilsV3.write(baos, request.getManifest());
manifestSerialized = baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Could not serialize manifest", e);
}
return Mono.zip(this.cloudFoundryClient, this.spaceId)...So callers who handle errors with onErrorResume or doOnError never see this one. It just blows up while they're building the chain. It would be more consistent to do the work lazily:
Mono<byte[]> manifestSerialized =
Mono.fromCallable(
() -> {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ApplicationManifestUtilsV3.write(baos, request.getManifest());
return baos.toByteArray();
}
});and then use that in the existing chain (for example with Mono.zip(this.cloudFoundryClient, this.spaceId, manifestSerialized)).
3. Tests leave manifest files behind in the temp directory
ApplicationManifestUtilsTest (line 631) and ApplicationManifestUtilsV3Test (line 152) create files with Files.createTempFile("test-manifest-", ".yml") and never delete them. Every test run leaves more of them in /tmp, and once #1410 is merged some of them will contain docker credentials (dummy ones, but still).
Using JUnit's @TempDir takes care of this:
@TempDir Path tempDir;
private void assertSerializeDeserialize(ManifestV3 manifest) throws IOException {
Path file = tempDir.resolve("test-manifest.yml");
ApplicationManifestUtilsV3.write(file, manifest);
ManifestV3 read = ApplicationManifestUtilsV3.read(file);
assertEquals(manifest, read);
}I'm happy to open a PR for these if nobody objects.
Activity
fix: Write manifests as UTF-8 and serialize the V3 manifest lazily