Skip to content

Commit 5139cd8

Browse files
committed
Normalize the authConfig handling in the different commands
1 parent 9a937a3 commit 5139cd8

9 files changed

Lines changed: 28 additions & 72 deletions

File tree

src/main/java/com/github/dockerjava/api/command/AuthCmd.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.github.dockerjava.api.command;
22

3-
import javax.annotation.CheckForNull;
4-
import javax.annotation.Nonnull;
5-
63
import com.github.dockerjava.api.exception.UnauthorizedException;
74
import com.github.dockerjava.api.model.AuthConfig;
85
import com.github.dockerjava.api.model.AuthResponse;
96

7+
import javax.annotation.CheckForNull;
8+
109
/**
1110
*
1211
* Authenticate with the server, useful for checking authentication.
@@ -17,7 +16,7 @@ public interface AuthCmd extends SyncDockerCmd<AuthResponse> {
1716
@CheckForNull
1817
AuthConfig getAuthConfig();
1918

20-
AuthCmd withAuthConfig(@Nonnull AuthConfig authConfig);
19+
AuthCmd withAuthConfig(AuthConfig authConfig);
2120

2221
/**
2322
* @return The status. Based on it's value you may mean you need to authorise your account, e.g.: "Account created. Please see the

src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerResponse> {
2626

27+
@CheckForNull
2728
AuthConfig getAuthConfig();
2829

2930
@CheckForNull

src/main/java/com/github/dockerjava/api/command/PullImageCmd.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.github.dockerjava.api.command;
22

3-
import javax.annotation.CheckForNull;
4-
import javax.annotation.Nonnull;
5-
63
import com.github.dockerjava.api.model.AuthConfig;
74
import com.github.dockerjava.api.model.PullResponseItem;
85

6+
import javax.annotation.CheckForNull;
7+
import javax.annotation.Nonnull;
8+
99
/**
1010
*
1111
* Pull image from repository.
@@ -22,6 +22,7 @@ public interface PullImageCmd extends AsyncDockerCmd<PullImageCmd, PullResponseI
2222
@CheckForNull
2323
String getRegistry();
2424

25+
@CheckForNull
2526
AuthConfig getAuthConfig();
2627

2728
PullImageCmd withRepository(@Nonnull String repository);

src/main/java/com/github/dockerjava/core/DockerClientImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ public PullImageCmd pullImageCmd(String repository) {
238238

239239
@Override
240240
public PushImageCmd pushImageCmd(String name) {
241-
PushImageCmd cmd = new PushImageCmdImpl(getDockerCmdExecFactory().createPushImageCmdExec(), name);
242-
243-
AuthConfig cfg = dockerClientConfig.effectiveAuthConfig(name);
244-
if (cfg != null) {
245-
cmd.withAuthConfig(cfg);
246-
}
241+
PushImageCmd cmd = new PushImageCmdImpl(getDockerCmdExecFactory().createPushImageCmdExec(),
242+
dockerClientConfig.effectiveAuthConfig(name), name);
247243
return cmd;
248244
}
249245

src/main/java/com/github/dockerjava/core/command/AbstrAuthCfgDockerCmd.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/main/java/com/github/dockerjava/core/command/AuthCmdImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* Authenticate with the server, useful for checking authentication.
1111
*
1212
*/
13-
public class AuthCmdImpl extends AbstrAuthCfgDockerCmd<AuthCmd, AuthResponse> implements AuthCmd {
13+
public class AuthCmdImpl extends AbstrDockerCmd<AuthCmd, AuthResponse> implements AuthCmd {
14+
15+
private AuthConfig authConfig;
1416

1517
public AuthCmdImpl(AuthCmd.Exec exec, AuthConfig authConfig) {
1618
super(exec);
@@ -21,4 +23,13 @@ public AuthCmdImpl(AuthCmd.Exec exec, AuthConfig authConfig) {
2123
public AuthResponse exec() throws UnauthorizedException {
2224
return super.exec();
2325
}
26+
27+
public AuthConfig getAuthConfig() {
28+
return authConfig;
29+
}
30+
31+
public AuthCmd withAuthConfig(AuthConfig authConfig) {
32+
this.authConfig = authConfig;
33+
return this;
34+
}
2435
}

src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd<CreateContainerCmd, C
133133
public CreateContainerCmdImpl(CreateContainerCmd.Exec exec, AuthConfig authConfig, String image) {
134134
super(exec);
135135
checkNotNull(image, "image was not specified");
136-
withOptionalAuthConfig(authConfig);
136+
withAuthConfig(authConfig);
137137
withImage(image);
138138
}
139139

@@ -142,11 +142,6 @@ public AuthConfig getAuthConfig() {
142142
}
143143

144144
public CreateContainerCmd withAuthConfig(AuthConfig authConfig) {
145-
checkNotNull(authConfig, "authConfig was not specified");
146-
return withOptionalAuthConfig(authConfig);
147-
}
148-
149-
private CreateContainerCmd withOptionalAuthConfig(AuthConfig authConfig) {
150145
this.authConfig = authConfig;
151146
return this;
152147
}

src/main/java/com/github/dockerjava/core/command/PullImageCmdImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.github.dockerjava.core.command;
22

3-
import static com.google.common.base.Preconditions.checkNotNull;
4-
53
import com.github.dockerjava.api.command.PullImageCmd;
64
import com.github.dockerjava.api.model.AuthConfig;
75
import com.github.dockerjava.api.model.PullResponseItem;
86

7+
import static com.google.common.base.Preconditions.checkNotNull;
8+
99
/**
1010
*
1111
* Pull image from repository.
@@ -19,7 +19,7 @@ public class PullImageCmdImpl extends AbstrAsyncDockerCmd<PullImageCmd, PullResp
1919

2020
public PullImageCmdImpl(PullImageCmd.Exec exec, AuthConfig authConfig, String repository) {
2121
super(exec);
22-
withOptionalAuthConfig(authConfig);
22+
withAuthConfig(authConfig);
2323
withRepository(repository);
2424
}
2525

@@ -28,11 +28,6 @@ public AuthConfig getAuthConfig() {
2828
}
2929

3030
public PullImageCmd withAuthConfig(AuthConfig authConfig) {
31-
checkNotNull(authConfig, "authConfig was not specified");
32-
return withOptionalAuthConfig(authConfig);
33-
}
34-
35-
private PullImageCmd withOptionalAuthConfig(AuthConfig authConfig) {
3631
this.authConfig = authConfig;
3732
return this;
3833
}

src/main/java/com/github/dockerjava/core/command/PushImageCmdImpl.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public class PushImageCmdImpl extends AbstrAsyncDockerCmd<PushImageCmd, PushResp
2020

2121
private AuthConfig authConfig;
2222

23-
public PushImageCmdImpl(PushImageCmd.Exec exec, String name) {
23+
public PushImageCmdImpl(PushImageCmd.Exec exec, AuthConfig authConfig, String name) {
2424
super(exec);
2525
withName(name);
26+
withAuthConfig(authConfig);
2627
}
2728

2829
@Override
@@ -62,13 +63,7 @@ public AuthConfig getAuthConfig() {
6263
}
6364

6465
public PushImageCmd withAuthConfig(AuthConfig authConfig) {
65-
checkNotNull(authConfig, "authConfig was not specified");
66-
return withOptionalAuthConfig(authConfig);
67-
}
68-
69-
private PushImageCmd withOptionalAuthConfig(AuthConfig authConfig) {
7066
this.authConfig = authConfig;
7167
return this;
7268
}
73-
7469
}

0 commit comments

Comments
 (0)