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
35 changes: 19 additions & 16 deletions src/main/java/com/github/dockerjava/api/model/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -28,50 +27,54 @@ public class AuthConfig {
private String email;

@JsonProperty("serveraddress")
private String serverAddress = DEFAULT_SERVER_ADDRESS;
private String registryAddress = DEFAULT_SERVER_ADDRESS;

@JsonProperty("auth")
private String auth;

public String getUsername() {
return username;
}

public void setUsername(String username) {
public AuthConfig withUsername(String username) {
this.username = username;
return this;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
public AuthConfig withPassword(String password) {
this.password = password;
return this;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
public AuthConfig withEmail(String email) {
this.email = email;
return this;
}

public String getServerAddress() {
return serverAddress;
public String getRegistryAddress() {
return registryAddress;
}

public void setServerAddress(String serverAddress) {
this.serverAddress = serverAddress;
public AuthConfig withRegistryAddress(String registryAddress) {
this.registryAddress = registryAddress;
return this;
}

@JsonIgnore
public String getAuth() {
return auth;
}

@JsonProperty("auth")
public void setAuth(String auth) {
public AuthConfig withAuth(String auth) {
this.auth = auth;
return this;
}

@Override
Expand All @@ -87,7 +90,7 @@ public int hashCode() {
result = prime * result + ((auth == null) ? 0 : auth.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((serverAddress == null) ? 0 : serverAddress.hashCode());
result = prime * result + ((registryAddress == null) ? 0 : registryAddress.hashCode());
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
Expand Down Expand Up @@ -116,10 +119,10 @@ public boolean equals(Object obj) {
return false;
} else if (!password.equals(other.password))
return false;
if (serverAddress == null) {
if (other.serverAddress != null)
if (registryAddress == null) {
if (other.registryAddress != null)
return false;
} else if (!serverAddress.equals(other.serverAddress))
} else if (!registryAddress.equals(other.registryAddress))
return false;
if (username == null) {
if (other.username != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AuthConfigurations {
private Map<String, AuthConfig> configs = new TreeMap<>();

public void addConfig(AuthConfig authConfig) {
configs.put(authConfig.getServerAddress(), authConfig);
configs.put(authConfig.getRegistryAddress(), authConfig);
}

public Map<String, AuthConfig> getConfigs() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/github/dockerjava/core/AuthConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AuthConfigFile() {
}

void addConfig(AuthConfig config) {
authConfigMap.put(config.getServerAddress(), config);
authConfigMap.put(config.getRegistryAddress(), config);
}

public AuthConfig resolveAuthConfig(String hostname) {
Expand Down Expand Up @@ -111,8 +111,8 @@ public static AuthConfigFile loadConfig(File confFile) throws IOException {
for (Map.Entry<String, AuthConfig> entry : configMap.entrySet()) {
AuthConfig authConfig = entry.getValue();
decodeAuth(authConfig.getAuth(), authConfig);
authConfig.setAuth(null);
authConfig.setServerAddress(entry.getKey());
authConfig.withAuth(null);
authConfig.withRegistryAddress(entry.getKey());
configFile.addConfig(authConfig);
}
} else {
Expand All @@ -131,7 +131,7 @@ public static AuthConfigFile loadConfig(File confFile) throws IOException {
if (origEmail.length != 2) {
throw new IOException("Invalid Auth config file");
}
config.setEmail(origEmail[1]);
config.withEmail(origEmail[1]);
configFile.addConfig(config);
}
return configFile;
Expand All @@ -144,8 +144,8 @@ static void decodeAuth(String auth, AuthConfig config) throws IOException {
if (parts.length != 2) {
throw new IOException("Invalid auth configuration file");
}
config.setUsername(parts[0]);
config.setPassword(parts[1]);
config.withUsername(parts[0]);
config.withPassword(parts[1]);
}

static String convertToHostname(String server) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/github/dockerjava/core/DockerClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ private AuthConfig getAuthConfig() {
AuthConfig authConfig = null;
if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryEmail() != null
&& getRegistryUrl() != null) {
authConfig = new AuthConfig();
authConfig.setUsername(getRegistryUsername());
authConfig.setPassword(getRegistryPassword());
authConfig.setEmail(getRegistryEmail());
authConfig.setServerAddress(getRegistryUrl());
authConfig = new AuthConfig()
.withUsername(getRegistryUsername())
.withPassword(getRegistryPassword())
.withEmail(getRegistryEmail())
.withRegistryAddress(getRegistryUrl());
}
return authConfig;
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/github/dockerjava/core/DockerClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ public AuthConfig authConfig() {
checkNotNull(dockerClientConfig.getRegistryUsername(), "Configured username is null.");
checkNotNull(dockerClientConfig.getRegistryUrl(), "Configured serverAddress is null.");

AuthConfig authConfig = new AuthConfig();
authConfig.setUsername(dockerClientConfig.getRegistryUsername());
authConfig.setPassword(dockerClientConfig.getRegistryPassword());
authConfig.setEmail(dockerClientConfig.getRegistryEmail());
authConfig.setServerAddress(dockerClientConfig.getRegistryUrl());

return authConfig;
return new AuthConfig()
.withUsername(dockerClientConfig.getRegistryUsername())
.withPassword(dockerClientConfig.getRegistryPassword())
.withEmail(dockerClientConfig.getRegistryEmail())
.withRegistryAddress(dockerClientConfig.getRegistryUrl());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* is malformed.
*
* On Windows, escaping is disabled. Instead, '\\' is treated as
* path separator.
AuthConfigTest * path separator.
* </pre>
*
* @author tedo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class AuthConfigTest {

@BeforeMethod
public void setUp() throws Exception {
authConfig = new AuthConfig();
authConfig.setEmail("foo");
authConfig.setPassword("bar");
authConfig.setServerAddress("baz");
authConfig.setUsername("qux");
authConfig = new AuthConfig()
.withEmail("foo")
.withPassword("bar")
.withRegistryAddress("baz")
.withUsername("qux");
}

@Test
public void defaultServerAddress() throws Exception {
assertEquals(new AuthConfig().getServerAddress(), "https://index.docker.io/v1/");
assertEquals(new AuthConfig().getRegistryAddress(), "https://index.docker.io/v1/");
}
}
32 changes: 16 additions & 16 deletions src/test/java/com/github/dockerjava/core/AuthConfigFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public void invalidLegacyEmailLine() throws IOException {

@Test
public void validJson() throws IOException {
AuthConfig authConfig1 = new AuthConfig();
authConfig1.setEmail("foo@example.com");
authConfig1.setUsername("foo");
authConfig1.setPassword("bar");
authConfig1.setServerAddress("quay.io");

AuthConfig authConfig2 = new AuthConfig();
authConfig2.setEmail("moo@example.com");
authConfig2.setUsername("foo1");
authConfig2.setPassword("bar1");
authConfig2.setServerAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
AuthConfig authConfig1 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("quay.io");

AuthConfig authConfig2 = new AuthConfig()
.withEmail("moo@example.com")
.withUsername("foo1")
.withPassword("bar1")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);

AuthConfigFile expected = new AuthConfigFile();
expected.addConfig(authConfig1);
Expand All @@ -70,11 +70,11 @@ public void validJson() throws IOException {

@Test
public void validLegacy() throws IOException {
AuthConfig authConfig = new AuthConfig();
authConfig.setEmail("foo@example.com");
authConfig.setUsername("foo");
authConfig.setPassword("bar");
authConfig.setServerAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
AuthConfig authConfig = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);

AuthConfigFile expected = new AuthConfigFile();
expected.addConfig(authConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,12 @@ public void testBuildFromPrivateRegistry() throws Exception {
// wait for registry to boot
Thread.sleep(3000);

AuthConfig authConfig = new AuthConfig();

// credentials as configured in /auth/htpasswd
authConfig.setUsername("testuser");
authConfig.setPassword("testpassword");
authConfig.setEmail("foo@bar.de");
authConfig.setServerAddress("localhost:5000");
AuthConfig authConfig = new AuthConfig()
.withUsername("testuser")
.withPassword("testpassword")
.withEmail("foo@bar.de")
.withRegistryAddress("localhost:5000");

dockerClient.authCmd().withAuthConfig(authConfig).exec();
dockerClient.tagImageCmd("busybox:latest", "localhost:5000/testuser/busybox", "latest").withForce().exec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,12 @@ public void testBuildFromPrivateRegistry() throws Exception {
// wait for registry to boot
Thread.sleep(3000);

AuthConfig authConfig = new AuthConfig();

// credentials as configured in /auth/htpasswd
authConfig.setUsername("testuser");
authConfig.setPassword("testpassword");
authConfig.setEmail("foo@bar.de");
authConfig.setServerAddress("localhost:5000");
AuthConfig authConfig = new AuthConfig()
.withUsername("testuser")
.withPassword("testpassword")
.withEmail("foo@bar.de")
.withRegistryAddress("localhost:5000");

dockerClient.authCmd().withAuthConfig(authConfig).exec();
dockerClient.tagImageCmd("busybox:latest", "localhost:5000/testuser/busybox", "latest").withForce().exec();
Expand Down