Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,20 @@ private void applyContextConfiguration(final String context) {
Optional.ofNullable(context)
.flatMap(ctx -> DockerContextMetaFile.resolveContextMetaFile(DockerClientConfig.getDefaultObjectMapper(),
new File(this.dockerConfig), ctx));
final Optional<File> dockerContextTLSFile =
Optional.ofNullable(context)
.flatMap(ctx -> DockerContextMetaFile.resolveContextTLSFile(new File(this.dockerConfig), ctx));

if (dockerContextMetaFile.isPresent()) {
final Optional<DockerContextMetaFile.Endpoints.Docker> dockerEndpoint =
dockerContextMetaFile.map(metaFile -> metaFile.endpoints).map(endpoint -> endpoint.docker);
if (this.dockerHost == null) {
this.dockerHost = dockerEndpoint.map(endpoint -> endpoint.host).map(URI::create).orElse(null);
}
if (this.dockerCertPath == null) {
this.dockerCertPath = dockerContextMetaFile.map(metaFile -> metaFile.storage)
.map(storage -> storage.tlsPath)
.filter(file -> new File(file).exists()).orElse(null);
if (this.dockerCertPath != null) {
this.dockerTlsVerify = dockerEndpoint.map(endpoint -> !endpoint.skipTLSVerify).orElse(true);
}
}
}
if (dockerContextTLSFile.isPresent() && this.dockerCertPath == null) {
this.dockerCertPath = dockerContextTLSFile.get().getAbsolutePath();
this.dockerTlsVerify = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class DockerContextMetaFile {
@JsonProperty("Endpoints")
Endpoints endpoints;

@JsonProperty("Storage")
Storage storage;

public static class Endpoints {
@JsonProperty("docker")
Expand All @@ -34,13 +32,6 @@ public static class Docker {
}
}

public static class Storage {

@JsonProperty("TLSPath")
String tlsPath;
@JsonProperty("MetadataPath")
String metadataPath;
}

public static Optional<DockerContextMetaFile> resolveContextMetaFile(ObjectMapper objectMapper, File dockerConfigPath, String context) {
final File path = dockerConfigPath.toPath()
Expand All @@ -52,6 +43,16 @@ public static Optional<DockerContextMetaFile> resolveContextMetaFile(ObjectMappe
return Optional.ofNullable(loadContextMetaFile(objectMapper, path));
}

public static Optional<File> resolveContextTLSFile(File dockerConfigPath, String context) {
final File path = dockerConfigPath.toPath()
.resolve("contexts")
.resolve("tls")
.resolve(metaHashFunction.hashString(context, StandardCharsets.UTF_8).toString())
.resolve("docker")
.toFile();
return Optional.ofNullable(path).filter(File::exists);
}

public static DockerContextMetaFile loadContextMetaFile(ObjectMapper objectMapper, File dockerContextMetaFile) {
try {
return parseContextMetaFile(objectMapper, dockerContextMetaFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public void dockerContextWithDockerHostAndTLS() {

assertEquals(URI.create("tcp://remote:2376"), config.getDockerHost());
assertTrue("SSL config is set", config.getSSLConfig() instanceof LocalDirectorySSLConfig);
assertEquals("target/test-classes/com/github/dockerjava/core/util/CertificateUtilsTest/allFilesExist",
((LocalDirectorySSLConfig)config.getSSLConfig()).getDockerCertPath());
assertTrue("SSL directory is set", ((LocalDirectorySSLConfig)config.getSSLConfig()).getDockerCertPath().endsWith("dockerContextHomeDir/.docker/contexts/tls/b71199ebd070b36beab7317920c2c2f1d777df8d05e5527d8458fda57cb17a7a/docker"));
}

@Test
Expand Down