| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -446,21 +446,20 @@ private void applyContextConfiguration(final String context) { | |||
| 446 | 446 | Optional.ofNullable(context) | |
| 447 | 447 | .flatMap(ctx -> DockerContextMetaFile.resolveContextMetaFile(DockerClientConfig.getDefaultObjectMapper(), | |
| 448 | 448 | new File(this.dockerConfig), ctx)); | |
| 449 | + final Optional<File> dockerContextTLSFile = | ||
| 450 | + Optional.ofNullable(context) | ||
| 451 | + .flatMap(ctx -> DockerContextMetaFile.resolveContextTLSFile(new File(this.dockerConfig), ctx)); | ||
| 449 | 452 | ||
| 450 | 453 | if (dockerContextMetaFile.isPresent()) { | |
| 451 | 454 | final Optional<DockerContextMetaFile.Endpoints.Docker> dockerEndpoint = | |
| 452 | 455 | dockerContextMetaFile.map(metaFile -> metaFile.endpoints).map(endpoint -> endpoint.docker); | |
| 453 | 456 | if (this.dockerHost == null) { | |
| 454 | 457 | this.dockerHost = dockerEndpoint.map(endpoint -> endpoint.host).map(URI::create).orElse(null); | |
| 455 | 458 | } | |
| 456 | - if (this.dockerCertPath == null) { | ||
| 457 | - this.dockerCertPath = dockerContextMetaFile.map(metaFile -> metaFile.storage) | ||
| 458 | - .map(storage -> storage.tlsPath) | ||
| 459 | - .filter(file -> new File(file).exists()).orElse(null); | ||
| 460 | - if (this.dockerCertPath != null) { | ||
| 461 | - this.dockerTlsVerify = dockerEndpoint.map(endpoint -> !endpoint.skipTLSVerify).orElse(true); | ||
| 462 | - } | ||
| 463 | - } | ||
| 459 | + } | ||
| 460 | + if (dockerContextTLSFile.isPresent() && this.dockerCertPath == null) { | ||
| 461 | + this.dockerCertPath = dockerContextTLSFile.get().getAbsolutePath(); | ||
| 462 | + this.dockerTlsVerify = true; | ||
| 464 | 463 | } | |
| 465 | 464 | } | |
| 466 | 465 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,6 @@ public class DockerContextMetaFile { | |||
| 18 | 18 | @JsonProperty("Endpoints") | |
| 19 | 19 | Endpoints endpoints; | |
| 20 | 20 | ||
| 21 | - @JsonProperty("Storage") | ||
| 22 | - Storage storage; | ||
| 23 | 21 | ||
| 24 | 22 | public static class Endpoints { | |
| 25 | 23 | @JsonProperty("docker") | |
@@ -34,13 +32,6 @@ public static class Docker { | |||
| 34 | 32 | } | |
| 35 | 33 | } | |
| 36 | 34 | ||
| 37 | - public static class Storage { | ||
| 38 | - | ||
| 39 | - @JsonProperty("TLSPath") | ||
| 40 | - String tlsPath; | ||
| 41 | - @JsonProperty("MetadataPath") | ||
| 42 | - String metadataPath; | ||
| 43 | - } | ||
| 44 | 35 | ||
| 45 | 36 | public static Optional<DockerContextMetaFile> resolveContextMetaFile(ObjectMapper objectMapper, File dockerConfigPath, String context) { | |
| 46 | 37 | final File path = dockerConfigPath.toPath() | |
@@ -52,6 +43,16 @@ public static Optional<DockerContextMetaFile> resolveContextMetaFile(ObjectMappe | |||
| 52 | 43 | return Optional.ofNullable(loadContextMetaFile(objectMapper, path)); | |
| 53 | 44 | } | |
| 54 | 45 | ||
| 46 | + public static Optional<File> resolveContextTLSFile(File dockerConfigPath, String context) { | ||
| 47 | + final File path = dockerConfigPath.toPath() | ||
| 48 | + .resolve("contexts") | ||
| 49 | + .resolve("tls") | ||
| 50 | + .resolve(metaHashFunction.hashString(context, StandardCharsets.UTF_8).toString()) | ||
| 51 | + .resolve("docker") | ||
| 52 | + .toFile(); | ||
| 53 | + return Optional.ofNullable(path).filter(File::exists); | ||
| 54 | + } | ||
| 55 | + | ||
| 55 | 56 | public static DockerContextMetaFile loadContextMetaFile(ObjectMapper objectMapper, File dockerContextMetaFile) { | |
| 56 | 57 | try { | |
| 57 | 58 | return parseContextMetaFile(objectMapper, dockerContextMetaFile); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,8 +129,7 @@ public void dockerContextWithDockerHostAndTLS() { | |||
| 129 | 129 | ||
| 130 | 130 | assertEquals(URI.create("tcp://remote:2376"), config.getDockerHost()); | |
| 131 | 131 | assertTrue("SSL config is set", config.getSSLConfig() instanceof LocalDirectorySSLConfig); | |
| 132 | - assertEquals("target/test-classes/com/github/dockerjava/core/util/CertificateUtilsTest/allFilesExist", | ||
| 133 | - ((LocalDirectorySSLConfig)config.getSSLConfig()).getDockerCertPath()); | ||
| 132 | + assertTrue("SSL directory is set", ((LocalDirectorySSLConfig)config.getSSLConfig()).getDockerCertPath().endsWith("dockerContextHomeDir/.docker/contexts/tls/b71199ebd070b36beab7317920c2c2f1d777df8d05e5527d8458fda57cb17a7a/docker")); | ||
| 134 | 133 | } | |
| 135 | 134 | ||
| 136 | 135 | @Test | |
| Back | FazBrowse Home | New Git URL |
0 commit comments