fabric8io / docker-client

11 stars 13 forks source link

Docker config file with any extra properties cannot be read #106

Open ljnelson opened 6 years ago

ljnelson commented 6 years ago

My ~/.docker/config file can't be read by the docker-client project because of overly strict JSON mapping. I receive the following error:

SEVERE: Could not load docker config file from /Users/ljnelson/.docker/config.json
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "HttpHeaders" (class io.fabric8.docker.api.model.DockerConfig), not marked as ignorable (one known property: "auths"])
     at [Source: /Users/ljnelson/.docker/config.json; line: 25, column: 20] (through reference chain: io.fabric8.docker.api.model.DockerConfig["HttpHeaders"])

This is because my (perfectly valid) ~/.docker/config file contains (among other valid things):

"HttpHeaders" : {
  "User-Agent" : "Docker-Client/17.09.0-ce (darwin)"
},
"credsStore" : "osxkeychain"

Leaving aside code generation, building, etc. if the DockerConfig.java file were edited in such a way to include @JsonIgnoreProperties(ignoreUnknown = true) that would be a quick fix.

ljnelson commented 6 years ago

The following hack invoked from, say, a static initializer works around the problem:

private static final void hack() throws ReflectiveOperationException {
    final Field jsonMapperField = Config.class.getDeclaredField("JSON_MAPPER");
    assert jsonMapperField != null;
    jsonMapperField.setAccessible(true);
    final ObjectMapper objectMapper = (ObjectMapper)jsonMapperField.get(null);
    assert objectMapper != null;
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}