Skip to content

Commit

Permalink
Update following initial review
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Apr 24, 2018
1 parent 365f943 commit eb5558b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = "";
}

Expand All @@ -62,6 +63,7 @@ public AuthConfig lookupAuthConfig(DockerImageName dockerImageName) {
// auths/<registry> 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);
}
Expand All @@ -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();
}
Expand Down

0 comments on commit eb5558b

Please sign in to comment.