X Tutup
Skip to content

Commit a0ec66f

Browse files
committed
Fix versioning Auth issues for unknown API connections.
Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
1 parent b1d77c5 commit a0ec66f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/main/java/com/github/dockerjava/core/RemoteApiVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class RemoteApiVersion implements Serializable {
6060
/**
6161
* Unknown, docker doesn't reflect reality. I.e. we implemented method, but for javadoc it not clear when it was added.
6262
*/
63-
private static final RemoteApiVersion UNKNOWN_VERSION = new RemoteApiVersion(0, 0) {
63+
public static final RemoteApiVersion UNKNOWN_VERSION = new RemoteApiVersion(0, 0) {
6464

6565
@Override
6666
public boolean isGreaterOrEqual(final RemoteApiVersion other) {

src/main/java/com/github/dockerjava/jaxrs/AbstrDockerCmdExec.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.github.dockerjava.jaxrs;
22

3+
import static com.github.dockerjava.core.RemoteApiVersion.UNKNOWN_VERSION;
4+
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_19;
35
import static com.google.common.base.Preconditions.checkNotNull;
46

57
import java.io.IOException;
68

79
import javax.ws.rs.client.WebTarget;
810

11+
import com.fasterxml.jackson.databind.node.ObjectNode;
912
import org.apache.commons.codec.binary.Base64;
1013

1114
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -46,10 +49,18 @@ protected String registryAuth(AuthConfig authConfig) {
4649
protected String registryConfigs(AuthConfigurations authConfigs) {
4750
try {
4851
final String json;
49-
if (dockerClientConfig.getApiVersion().isGreaterOrEqual(RemoteApiVersion.VERSION_1_19)) {
50-
json = new ObjectMapper().writeValueAsString(authConfigs.getConfigs());
52+
final ObjectMapper objectMapper = new ObjectMapper();
53+
final RemoteApiVersion apiVersion = dockerClientConfig.getApiVersion();
54+
55+
if (apiVersion.equals(UNKNOWN_VERSION)) {
56+
ObjectNode rootNode = objectMapper.valueToTree(authConfigs.getConfigs()); // all registries
57+
final ObjectNode authNodes = objectMapper.valueToTree(authConfigs); // wrapped in "configs":{}
58+
rootNode.setAll(authNodes); // merge 2 variants
59+
json = rootNode.toString();
60+
} else if (apiVersion.isGreaterOrEqual(VERSION_1_19)) {
61+
json = objectMapper.writeValueAsString(authConfigs.getConfigs());
5162
} else {
52-
json = new ObjectMapper().writeValueAsString(authConfigs);
63+
json = objectMapper.writeValueAsString(authConfigs);
5364
}
5465

5566
return Base64.encodeBase64String(json.getBytes());

0 commit comments

Comments
 (0)
X Tutup