| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 18ad695 commit 41eea38
43 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,7 @@ public String getDockerConfigPath() { | |||
| 242 | 242 | public DockerConfigFile getDockerConfig() { | |
| 243 | 243 | if (dockerConfig == null) { | |
| 244 | 244 | try { | |
| 245 | - dockerConfig = DockerConfigFile.loadConfig(getDockerConfigPath()); | ||
| 245 | + dockerConfig = DockerConfigFile.loadConfig(getObjectMapper(), getDockerConfigPath()); | ||
| 246 | 246 | } catch (IOException e) { | |
| 247 | 247 | throw new DockerClientException("Failed to parse docker configuration file", e); | |
| 248 | 248 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | 6 | import java.net.URI; | |
| 7 | 7 | ||
| 8 | + import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| 9 | + import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 8 | 10 | import com.github.dockerjava.api.model.AuthConfig; | |
| 9 | 11 | import com.github.dockerjava.api.model.AuthConfigurations; | |
| 10 | 12 | ||
@@ -37,4 +39,20 @@ public interface DockerClientConfig { | |||
| 37 | 39 | */ | |
| 38 | 40 | SSLConfig getSSLConfig(); | |
| 39 | 41 | ||
| 42 | + default ObjectMapper getObjectMapper() { | ||
| 43 | + return DefaultObjectMapperHolder.INSTANCE.getObjectMapper(); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + enum DefaultObjectMapperHolder { | ||
| 48 | + INSTANCE; | ||
| 49 | + | ||
| 50 | + private final ObjectMapper objectMapper = new ObjectMapper() | ||
| 51 | + // TODO .setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL) | ||
| 52 | + // TODO .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) | ||
| 53 | + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
| 54 | + | ||
| 55 | + public ObjectMapper getObjectMapper() { | ||
| 56 | + return objectMapper; | ||
| 57 | + } | ||
| 40 | 58 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | package com.github.dockerjava.core; | |
| 2 | 2 | ||
| 3 | - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| 4 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; | |
| 5 | 4 | import com.fasterxml.jackson.core.type.TypeReference; | |
| 6 | 5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
@@ -20,12 +19,10 @@ | |||
| 20 | 19 | import java.util.List; | |
| 21 | 20 | import java.util.Map; | |
| 22 | 21 | ||
| 23 | - @JsonIgnoreProperties(ignoreUnknown = true) | ||
| 24 | 22 | public class DockerConfigFile { | |
| 25 | 23 | private static final String DOCKER_LEGACY_CFG = ".dockercfg"; | |
| 26 | 24 | private static final String DOCKER_CFG = "config.json"; | |
| 27 | 25 | ||
| 28 | - private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
| 29 | 26 | private static final TypeReference<Map<String, AuthConfig>> CONFIG_MAP_TYPE = new TypeReference<Map<String, AuthConfig>>() { | |
| 30 | 27 | }; | |
| 31 | 28 | ||
@@ -118,18 +115,24 @@ public String toString() { | |||
| 118 | 115 | } | |
| 119 | 116 | ||
| 120 | 117 | @Nonnull | |
| 118 | + @Deprecated | ||
| 121 | 119 | public static DockerConfigFile loadConfig(@CheckForNull String dockerConfigPath) throws IOException { | |
| 120 | + return loadConfig(DefaultObjectMapperHolder.INSTANCE.getObjectMapper(), dockerConfigPath); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + @Nonnull | ||
| 124 | + public static DockerConfigFile loadConfig(ObjectMapper objectMapper, @CheckForNull String dockerConfigPath) throws IOException { | ||
| 122 | 125 | // no any configs, but for empty auths return non null object | |
| 123 | 126 | if (dockerConfigPath == null) { | |
| 124 | 127 | return new DockerConfigFile(); | |
| 125 | 128 | } | |
| 126 | 129 | ||
| 127 | 130 | //parse new docker config file format | |
| 128 | - DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath); | ||
| 131 | + DockerConfigFile dockerConfig = loadCurrentConfig(objectMapper, dockerConfigPath); | ||
| 129 | 132 | ||
| 130 | 133 | //parse old auth config file format | |
| 131 | 134 | if (dockerConfig == null) { | |
| 132 | - dockerConfig = loadLegacyConfig(dockerConfigPath); | ||
| 135 | + dockerConfig = loadLegacyConfig(objectMapper, dockerConfigPath); | ||
| 133 | 136 | } | |
| 134 | 137 | ||
| 135 | 138 | //otherwise create default config | |
@@ -148,22 +151,22 @@ public static DockerConfigFile loadConfig(@CheckForNull String dockerConfigPath) | |||
| 148 | 151 | } | |
| 149 | 152 | ||
| 150 | 153 | @CheckForNull | |
| 151 | - private static DockerConfigFile loadCurrentConfig(@CheckForNull String dockerConfigPath) throws IOException { | ||
| 154 | + private static DockerConfigFile loadCurrentConfig(ObjectMapper objectMapper, @CheckForNull String dockerConfigPath) throws IOException { | ||
| 152 | 155 | File dockerCfgFile = new File(dockerConfigPath, DOCKER_CFG); | |
| 153 | 156 | ||
| 154 | 157 | if (!dockerCfgFile.exists() || !dockerCfgFile.isFile()) { | |
| 155 | 158 | return null; | |
| 156 | 159 | } | |
| 157 | 160 | ||
| 158 | 161 | try { | |
| 159 | - return MAPPER.readValue(dockerCfgFile, DockerConfigFile.class); | ||
| 162 | + return objectMapper.readValue(dockerCfgFile, DockerConfigFile.class); | ||
| 160 | 163 | } catch (IOException e) { | |
| 161 | 164 | throw new IOException("Failed to parse docker " + DOCKER_CFG, e); | |
| 162 | 165 | } | |
| 163 | 166 | } | |
| 164 | 167 | ||
| 165 | 168 | @CheckForNull | |
| 166 | - private static DockerConfigFile loadLegacyConfig(String dockerConfigPath) throws IOException { | ||
| 169 | + private static DockerConfigFile loadLegacyConfig(ObjectMapper objectMapper, String dockerConfigPath) throws IOException { | ||
| 167 | 170 | File dockerLegacyCfgFile = new File(dockerConfigPath, DOCKER_LEGACY_CFG); | |
| 168 | 171 | ||
| 169 | 172 | if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) { | |
@@ -172,7 +175,7 @@ private static DockerConfigFile loadLegacyConfig(String dockerConfigPath) throws | |||
| 172 | 175 | ||
| 173 | 176 | //parse legacy auth config file format | |
| 174 | 177 | try { | |
| 175 | - return new DockerConfigFile(MAPPER.<Map<String, AuthConfig>>readValue(dockerLegacyCfgFile, CONFIG_MAP_TYPE)); | ||
| 178 | + return new DockerConfigFile(objectMapper.<Map<String, AuthConfig>>readValue(dockerLegacyCfgFile, CONFIG_MAP_TYPE)); | ||
| 176 | 179 | } catch (IOException e) { | |
| 177 | 180 | // pass | |
| 178 | 181 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | import com.fasterxml.jackson.core.JsonFactory; | |
| 10 | 10 | import com.fasterxml.jackson.core.JsonParser; | |
| 11 | 11 | import com.fasterxml.jackson.core.JsonToken; | |
| 12 | + import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| 12 | 13 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 13 | 14 | import com.fasterxml.jackson.databind.node.ObjectNode; | |
| 14 | 15 | import com.github.dockerjava.api.async.ResultCallback; | |
@@ -22,30 +23,38 @@ public class JsonStreamProcessor<T> implements ResponseStreamProcessor<T> { | |||
| 22 | 23 | ||
| 23 | 24 | private static final JsonFactory JSON_FACTORY = new JsonFactory(); | |
| 24 | 25 | ||
| 25 | - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
| 26 | - | ||
| 27 | 26 | private final Class<T> clazz; | |
| 28 | 27 | ||
| 28 | + private final ObjectMapper objectMapper; | ||
| 29 | + | ||
| 30 | + @Deprecated | ||
| 29 | 31 | public JsonStreamProcessor(Class<T> clazz) { | |
| 32 | + this( | ||
| 33 | + new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES), | ||
| 34 | + clazz | ||
| 35 | + ); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public JsonStreamProcessor(ObjectMapper objectMapper, Class<T> clazz) { | ||
| 30 | 39 | this.clazz = clazz; | |
| 40 | + this.objectMapper = objectMapper.copy().enable(JsonParser.Feature.AUTO_CLOSE_SOURCE); | ||
| 31 | 41 | } | |
| 32 | 42 | ||
| 33 | 43 | @Override | |
| 34 | 44 | public void processResponseStream(InputStream response, ResultCallback<T> resultCallback) { | |
| 35 | 45 | ||
| 36 | 46 | resultCallback.onStart(response); | |
| 37 | - OBJECT_MAPPER.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true); | ||
| 38 | 47 | ||
| 39 | 48 | try { | |
| 40 | 49 | JsonParser jp = JSON_FACTORY.createParser(response); | |
| 41 | 50 | Boolean closed = jp.isClosed(); | |
| 42 | 51 | JsonToken nextToken = jp.nextToken(); | |
| 43 | 52 | while (!closed && nextToken != null && nextToken != JsonToken.END_OBJECT) { | |
| 44 | 53 | try { | |
| 45 | - ObjectNode objectNode = OBJECT_MAPPER.readTree(jp); | ||
| 54 | + ObjectNode objectNode = objectMapper.readTree(jp); | ||
| 46 | 55 | // exclude empty item serialization into class #461 | |
| 47 | 56 | if (!objectNode.isEmpty(null)) { | |
| 48 | - T next = OBJECT_MAPPER.treeToValue(objectNode, clazz); | ||
| 57 | + T next = objectMapper.treeToValue(objectNode, clazz); | ||
| 49 | 58 | resultCallback.onNext(next); | |
| 50 | 59 | } | |
| 51 | 60 | } catch (Exception e) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ public String toString() { | |||
| 44 | 44 | return ReflectionToStringBuilder.toString(this, ToStringStyle.SIMPLE_STYLE); | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | + @Deprecated | ||
| 47 | 48 | protected String registryAuth(AuthConfig authConfig) { | |
| 48 | 49 | try { | |
| 49 | 50 | return Base64.getEncoder().encodeToString(new ObjectMapper().writeValueAsBytes(authConfig)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ protected AuthConfigurations getBuildAuthConfigs() { | |||
| 42 | 42 | ||
| 43 | 43 | protected String registryAuth(@Nonnull AuthConfig authConfig) { | |
| 44 | 44 | try { | |
| 45 | - return BaseEncoding.base64Url().encode(new ObjectMapper().writeValueAsString(authConfig).getBytes()); | ||
| 45 | + return BaseEncoding.base64Url().encode(dockerClientConfig.getObjectMapper().writeValueAsString(authConfig).getBytes()); | ||
| 46 | 46 | } catch (IOException e) { | |
| 47 | 47 | throw new RuntimeException(e); | |
| 48 | 48 | } | |
@@ -52,8 +52,8 @@ protected String registryAuth(@Nonnull AuthConfig authConfig) { | |||
| 52 | 52 | protected String registryConfigs(@Nonnull AuthConfigurations authConfigs) { | |
| 53 | 53 | try { | |
| 54 | 54 | final String json; | |
| 55 | - final ObjectMapper objectMapper = new ObjectMapper(); | ||
| 56 | 55 | final RemoteApiVersion apiVersion = dockerClientConfig.getApiVersion(); | |
| 56 | + ObjectMapper objectMapper = dockerClientConfig.getObjectMapper(); | ||
| 57 | 57 | ||
| 58 | 58 | if (apiVersion.equals(UNKNOWN_VERSION)) { | |
| 59 | 59 | ObjectNode rootNode = objectMapper.valueToTree(authConfigs.getConfigs()); // all registries | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ public class CacheFromEncoder { | |||
| 13 | 13 | private CacheFromEncoder() { | |
| 14 | 14 | } | |
| 15 | 15 | ||
| 16 | + // This instance MUST NOT be used for domain-specific serialization of the docker-java types | ||
| 16 | 17 | private static final ObjectMapper MAPPER = new ObjectMapper(); | |
| 17 | 18 | ||
| 18 | 19 | public static String jsonEncode(Collection<String> imageIds) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ public class FiltersEncoder { | |||
| 16 | 16 | private FiltersEncoder() { | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | + // This instance MUST NOT be used for domain-specific serialization of the docker-java types | ||
| 19 | 20 | private static final ObjectMapper MAPPER = new ObjectMapper(); | |
| 20 | 21 | ||
| 21 | 22 | public static String jsonEncode(Map<String, List<String>> mapStringListString) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,11 +22,15 @@ public abstract class AbstrDockerCmdExec { | |||
| 22 | 22 | ||
| 23 | 23 | private final WebTarget baseResource; | |
| 24 | 24 | ||
| 25 | + protected final ObjectMapper objectMapper; | ||
| 26 | + | ||
| 25 | 27 | public AbstrDockerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { | |
| 26 | 28 | checkNotNull(baseResource, "baseResource was not specified"); | |
| 27 | 29 | checkNotNull(dockerClientConfig, "dockerClientConfig was not specified"); | |
| 28 | 30 | this.baseResource = baseResource; | |
| 29 | 31 | this.dockerClientConfig = dockerClientConfig; | |
| 32 | + this.objectMapper = dockerClientConfig.getObjectMapper(); | ||
| 33 | + checkNotNull(objectMapper, "objectMapper was not specified"); | ||
| 30 | 34 | } | |
| 31 | 35 | ||
| 32 | 36 | protected WebTarget getBaseResource() { | |
@@ -39,7 +43,7 @@ protected AuthConfigurations getBuildAuthConfigs() { | |||
| 39 | 43 | ||
| 40 | 44 | protected String registryAuth(AuthConfig authConfig) { | |
| 41 | 45 | try { | |
| 42 | - return BaseEncoding.base64Url().encode(new ObjectMapper().writeValueAsString(authConfig).getBytes()); | ||
| 46 | + return BaseEncoding.base64Url().encode(objectMapper.writeValueAsString(authConfig).getBytes()); | ||
| 43 | 47 | } catch (IOException e) { | |
| 44 | 48 | throw new RuntimeException(e); | |
| 45 | 49 | } | |
@@ -60,7 +64,6 @@ protected Invocation.Builder resourceWithOptionalAuthConfig(AuthConfig authConfi | |||
| 60 | 64 | protected String registryConfigs(AuthConfigurations authConfigs) { | |
| 61 | 65 | try { | |
| 62 | 66 | final String json; | |
| 63 | - final ObjectMapper objectMapper = new ObjectMapper(); | ||
| 64 | 67 | final RemoteApiVersion apiVersion = dockerClientConfig.getApiVersion(); | |
| 65 | 68 | ||
| 66 | 69 | if (apiVersion.equals(UNKNOWN_VERSION)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,6 @@ | |||
| 7 | 7 | import javax.ws.rs.client.WebTarget; | |
| 8 | 8 | import javax.ws.rs.core.MediaType; | |
| 9 | 9 | ||
| 10 | - import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 11 | - | ||
| 12 | 10 | import com.github.dockerjava.core.util.CacheFromEncoder; | |
| 13 | 11 | import org.glassfish.jersey.client.ClientProperties; | |
| 14 | 12 | import org.glassfish.jersey.client.RequestEntityProcessing; | |
@@ -32,8 +30,6 @@ public class BuildImageCmdExec extends AbstrAsyncDockerCmdExec<BuildImageCmd, Bu | |||
| 32 | 30 | BuildImageCmd.Exec { | |
| 33 | 31 | private static final Logger LOGGER = LoggerFactory.getLogger(BuildImageCmdExec.class); | |
| 34 | 32 | ||
| 35 | - private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
| 36 | - | ||
| 37 | 33 | public BuildImageCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { | |
| 38 | 34 | super(baseResource, dockerClientConfig); | |
| 39 | 35 | } | |
@@ -137,7 +133,7 @@ protected AbstractCallbackNotifier<BuildResponseItem> callbackNotifier(BuildImag | |||
| 137 | 133 | ||
| 138 | 134 | LOGGER.trace("POST: {}", webTarget); | |
| 139 | 135 | ||
| 140 | - return new POSTCallbackNotifier<>(new JsonStreamProcessor<>(BuildResponseItem.class), | ||
| 136 | + return new POSTCallbackNotifier<>(new JsonStreamProcessor<>(objectMapper, BuildResponseItem.class), | ||
| 141 | 137 | resultCallback, | |
| 142 | 138 | resourceWithOptionalAuthConfig(command, webTarget.request()).accept(MediaType.TEXT_PLAIN), | |
| 143 | 139 | entity(command.getTarInputStream(), "application/tar") | |
@@ -148,7 +144,7 @@ private WebTarget writeMap(WebTarget webTarget, String name, Map<String, String> | |||
| 148 | 144 | if (value != null && !value.isEmpty()) { | |
| 149 | 145 | try { | |
| 150 | 146 | return webTarget.queryParam(name, | |
| 151 | - URLEncoder.encode(MAPPER.writeValueAsString(value), "UTF-8").replaceAll("\\+", "%20")); | ||
| 147 | + URLEncoder.encode(objectMapper.writeValueAsString(value), "UTF-8").replaceAll("\\+", "%20")); | ||
| 152 | 148 | } catch (IOException e) { | |
| 153 | 149 | throw new RuntimeException(e); | |
| 154 | 150 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments