From c8dfeeed1168b2fb6b9be8eff20227a70b5430ed Mon Sep 17 00:00:00 2001 From: Richard North Date: Tue, 24 Apr 2018 13:46:50 +0100 Subject: [PATCH] Update following initial review --- CHANGELOG.md | 2 +- .../utility/RegistryAuthLocator.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7617a81e6d2..97c0d4d7baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ All notable changes to this project will be documented in this file. - Fixed `HostPortWaitStrategy` throws `NumberFormatException` when port is exposed but not mapped ([\#640](https://github.com/testcontainers/testcontainers-java/issues/640)) - Fixed log processing: multibyte unicode, linebreaks and ASCII color codes. Color codes can be turned on with `withRemoveAnsiCodes(false)` ([\#643](https://github.com/testcontainers/testcontainers-java/pull/643)) - Fixed Docker host IP detection within docker container (detect only if not explicitly set) ([\#648](https://github.com/testcontainers/testcontainers-java/pull/648)) -- Add support for private repositories using docker credential stores/helpers (fixes [\#567](https://github.com/testcontainers/testcontainers-java/issues/567)) +- Add support for private repositories using docker credential stores/helpers ([PR \#647](https://github.com/testcontainers/testcontainers-java/pull/647), fixes [\#567](https://github.com/testcontainers/testcontainers-java/issues/567)) ### Changed - Support multiple HTTP status codes for HttpWaitStrategy ([\#630](https://github.com/testcontainers/testcontainers-java/issues/630)) diff --git a/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java b/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java index 20646ae0c0a..b5b50b65f94 100644 --- a/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java +++ b/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.dockerjava.api.model.AuthConfig; import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.zeroturnaround.exec.ProcessExecutor; @@ -39,7 +38,9 @@ public class RegistryAuthLocator { */ public RegistryAuthLocator(AuthConfig defaultAuthConfig) { this.defaultAuthConfig = defaultAuthConfig; - this.configFile = new File(System.getProperty("user.home") + "/.docker/config.json"); + final String dockerConfigLocation = System.getenv().getOrDefault("DOCKER_CONFIG", + System.getProperty("user.home") + "/.docker"); + this.configFile = new File(dockerConfigLocation + "/config.json"); this.commandPathPrefix = ""; } @@ -62,6 +63,7 @@ public AuthConfig lookupAuthConfig(DockerImageName dockerImageName) { // auths/ is an empty dict - use a credential helper return authConfigUsingCredentialsStoreOrHelper(reposName, config); } + // otherwise, defaultAuthConfig should already contain any credentials available } catch (Exception e) { log.error("Failure when attempting to lookup auth config. Falling back to docker-java default behaviour", e); } @@ -70,13 +72,13 @@ public AuthConfig lookupAuthConfig(DockerImageName dockerImageName) { private AuthConfig authConfigUsingCredentialsStoreOrHelper(String hostName, JsonNode config) throws Exception { - final String credsStoreName = config.at("/credsStore").asText(); - final String credHelper = config.at("/credHelpers/" + hostName).asText(); + final JsonNode credsStoreName = config.at("/credsStore"); + final JsonNode credHelper = config.at("/credHelpers/" + hostName); - if (StringUtils.isNotBlank(credHelper)) { - return runCredentialProvider(hostName, credHelper); - } else if (StringUtils.isNotBlank(credsStoreName)) { - return runCredentialProvider(hostName, credsStoreName); + if (!credHelper.isMissingNode()) { + return runCredentialProvider(hostName, credHelper.asText()); + } else if (!credsStoreName.isMissingNode()) { + return runCredentialProvider(hostName, credsStoreName.asText()); } else { throw new UnsupportedOperationException(); }