Skip to content

Commit eeaab6d

Browse files
committed
Simplify format handling
Signed-off-by: hojooo <ghwn5833@gmail.com>
1 parent 1ff9c5b commit eeaab6d

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void exportLayers(ImageReference reference, @Nullable ImagePlatform platf
344344
if (platform != null) {
345345
if (getApiVersion().supports(EXPORT_PLATFORM_API_VERSION)) {
346346
uri = buildUrl(EXPORT_PLATFORM_API_VERSION, "/images/" + reference + "/get", "platform",
347-
platform.toQueryParameter(getApiVersion()));
347+
platform.toJson());
348348
}
349349
}
350350
try (Response response = http().get(uri)) {
@@ -385,7 +385,7 @@ private Image inspect(ApiVersion apiVersion, ImageReference reference, @Nullable
385385
throws IOException {
386386
Assert.notNull(reference, "'reference' must not be null");
387387
URI imageUri = (platform != null)
388-
? buildUrl(apiVersion, "/images/" + reference + "/json", "platform", platform.toQueryParameter(getApiVersion()))
388+
? buildUrl(apiVersion, "/images/" + reference + "/json", "platform", platform.toJson())
389389
: buildUrl(apiVersion, "/images/" + reference + "/json");
390390
try (Response response = http().get(imageUri)) {
391391
return Image.of(response.getContent());

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImagePlatform.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,21 @@ public static ImagePlatform from(Image image) {
102102
}
103103

104104
/**
105-
* Return the value to use for the Docker API {@code platform} query parameter for the
106-
* given API version.
107-
*
108-
* For API versions that support JSON (1.49 and above), this method returns a JSON
109-
* object in the form {@code {"os":"...","architecture":"...","variant":"..."}}.
110-
* For lower API versions, the legacy string representation {@code os[/arch[/variant]]}
111-
* is returned.
112-
* @param apiVersion the Docker API version to target
113-
* @return the query parameter value to use for {@code platform}
105+
* Return a JSON-encoded representation of this platform for use with Docker Engine
106+
* API 1.48+ endpoints that require the platform parameter in JSON format
107+
* (e.g., image inspect and export operations).
108+
* @return a JSON object in the form {@code {"os":"...","architecture":"...","variant":"..."}}
114109
*/
115-
public String toQueryParameter(ApiVersion apiVersion) {
116-
Assert.notNull(apiVersion, "'apiVersion' must not be null");
117-
if (apiVersion.supports(ApiVersion.of(1, 49))) {
118-
StringBuilder json = new StringBuilder("{");
119-
json.append("\"os\":\"").append(this.os).append("\"");
120-
if (this.architecture != null && !this.architecture.isEmpty()) {
121-
json.append(",\"architecture\":\"").append(this.architecture).append("\"");
122-
}
123-
if (this.variant != null && !this.variant.isEmpty()) {
124-
json.append(",\"variant\":\"").append(this.variant).append("\"");
125-
}
126-
json.append("}");
127-
return json.toString();
110+
public String toJson() {
111+
StringBuilder json = new StringBuilder("{");
112+
json.append("\"os\":\"").append(this.os).append("\"");
113+
if (this.architecture != null && !this.architecture.isEmpty()) {
114+
json.append(",\"architecture\":\"").append(this.architecture).append("\"");
128115
}
129-
return toString();
116+
if (this.variant != null && !this.variant.isEmpty()) {
117+
json.append(",\"variant\":\"").append(this.variant).append("\"");
118+
}
119+
json.append("}");
120+
return json.toString();
130121
}
131122
}

0 commit comments

Comments
 (0)