|
1 | 1 | package com.github.dockerjava.jaxrs; |
2 | 2 |
|
| 3 | +import static com.github.dockerjava.core.RemoteApiVersion.UNKNOWN_VERSION; |
| 4 | +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_19; |
3 | 5 | import static com.google.common.base.Preconditions.checkNotNull; |
4 | 6 |
|
5 | 7 | import java.io.IOException; |
6 | 8 |
|
7 | 9 | import javax.ws.rs.client.WebTarget; |
8 | 10 |
|
| 11 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
9 | 12 | import org.apache.commons.codec.binary.Base64; |
10 | 13 |
|
11 | 14 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -46,10 +49,18 @@ protected String registryAuth(AuthConfig authConfig) { |
46 | 49 | protected String registryConfigs(AuthConfigurations authConfigs) { |
47 | 50 | try { |
48 | 51 | 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()); |
51 | 62 | } else { |
52 | | - json = new ObjectMapper().writeValueAsString(authConfigs); |
| 63 | + json = objectMapper.writeValueAsString(authConfigs); |
53 | 64 | } |
54 | 65 |
|
55 | 66 | return Base64.encodeBase64String(json.getBytes()); |
|
0 commit comments