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
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ public DockerConfigFile getDockerConfig() {

private AuthConfig getAuthConfig() {
AuthConfig authConfig = null;
if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryEmail() != null
&& getRegistryUrl() != null) {
if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryUrl() != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better fill all non-null values into authconfig without combining them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

AuthConfig authConfig = new AuthConfig;
if (getRegistryUsername() != null) {
    authConfig.setRegistryUsername(getRegistryUsername());
}
if(getRegistryPassword() != nul) {
    authConfig.setRegistryPassword(getRegistryPassword());
}
...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.nonNull() and even in one liner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but in effectiveAuthConfig() the return value of getAuthConfig() is checked for null. This will no longer work with your approach

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it will be empty, but not null...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and because it is not null the empty config will be used for authetification instead of getting the auth config from the docker config file. So in effectiveAuthConfig() we need to check if the auth config returned by getAuthConfig() is empty. Which I think is ugly.

Maybe we should change the && in ||:
if (getRegistryUsername() != null || getRegistryPassword() != null || getRegistryEmail() != null || getRegistryUrl() != null)

@KostyaSha What di you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, if email optional, then ok as is

authConfig = new AuthConfig()
.withUsername(getRegistryUsername())
.withPassword(getRegistryPassword())
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/github/dockerjava/cmd/PullImageCmdIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ public void testPullImageWithValidAuth() throws Exception {
.awaitCompletion(30, TimeUnit.SECONDS);
}

@Test
public void testPullImageWithValidAuthAndEmail() throws Exception {
AuthConfig authConfig = RegistryUtils.runPrivateRegistry(dockerRule.getClient())
.withEmail("foo@bar.de");

String imgName = RegistryUtils.createPrivateImage(dockerRule, "pull-image-with-valid-auth");

// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd(imgName)
.withAuthConfig(authConfig)
.exec(new PullImageResultCallback())
.awaitCompletion(30, TimeUnit.SECONDS);
}

@Test
public void testPullImageWithNoAuth() throws Exception {
RegistryUtils.runPrivateRegistry(dockerRule.getClient());
Expand All @@ -130,6 +144,7 @@ public void testPullImageWithNoAuth() throws Exception {
.awaitCompletion(30, TimeUnit.SECONDS);
}


@Test
public void testPullImageWithInvalidAuth() throws Exception {
AuthConfig validAuthConfig = RegistryUtils.runPrivateRegistry(dockerRule.getClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static synchronized AuthConfig runPrivateRegistry(DockerClient dockerClie
privateRegistryAuthConfig = new AuthConfig()
.withUsername("testuser")
.withPassword("testpassword")
.withEmail("foo@bar.de")
.withRegistryAddress("localhost:" + port);
}

Expand Down