Skip to content
Closed
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 @@ -238,7 +238,7 @@ public String getDockerConfigPath() {
public DockerConfigFile getDockerConfig() {
if (dockerConfig == null) {
try {
dockerConfig = DockerConfigFile.loadConfig(new File(getDockerConfigPath()));
dockerConfig = DockerConfigFile.loadConfig(new File(System.getProperty("user.home")), new File(getDockerConfigPath()));
} catch (IOException e) {
throw new DockerClientException("Failed to parse docker configuration file", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public String toString() {
return "DockerConfigFile [auths=" + auths + "]";
}

public static DockerConfigFile loadConfig(File dockerConfigPath) throws IOException {
public static DockerConfigFile loadConfig(File userHome, File dockerConfigPath) throws IOException {
//parse new docker config file format
DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath);

//parse old auth config file format
if (dockerConfig == null) {
dockerConfig = loadLegacyConfig(dockerConfigPath);
dockerConfig = loadLegacyConfig(userHome);
}

//otherwise create default config
Expand Down Expand Up @@ -150,8 +150,8 @@ private static DockerConfigFile loadCurrentConfig(File dockerConfigPath) throws
}
}

private static DockerConfigFile loadLegacyConfig(File dockerConfigPath) throws IOException {
File dockerLegacyCfgFile = new File(dockerConfigPath, File.separator + DOCKER_LEGACY_CFG);
private static DockerConfigFile loadLegacyConfig(File userHome) throws IOException {
File dockerLegacyCfgFile = new File(userHome, DOCKER_LEGACY_CFG);

if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public void withDockerTlsVerify() throws Exception {
@Test
public void testGetAuthConfigurationsFromDockerCfg() throws URISyntaxException {
File cfgFile = new File(Resources.getResource("com.github.dockerjava.core/registry.v1").toURI());
System.setProperty("user.home", cfgFile.getAbsolutePath());
DefaultDockerClientConfig clientConfig = new DefaultDockerClientConfig(URI.create(
"unix://foo"), cfgFile.getAbsolutePath(), "apiVersion", "registryUrl", "registryUsername", "registryPassword",
"registryEmail", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void nonExistent() throws IOException {
}

private DockerConfigFile runTest(String testFileName) throws IOException {
return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName));
return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName), new File(FILESROOT, testFileName));
}

}