Skip to content

Commit dc82c82

Browse files
authored
fix(auth): Non existing version command on credential helper is ignored (#1190)
Fixes #1159.
1 parent b414b9b commit dc82c82

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

doc/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ChangeLog
22

3-
* 0.28.1
3+
* **0.28-SNAPSHOT**
44
- Reintroduce minimal API-VERSION parameter in order to support docker versions below apiVersion 1.25
55
- docs: Correct default image naming
66
- Proxy settings are being ignored ([#1148](https://github.com/fabric8io/docker-maven-plugin/issues/1148))
@@ -13,6 +13,7 @@
1313
- Added 'autoRemove' option for running containers (#1179)
1414
- Added support for AWS EC2 instance roles when pushing to AWS ECR (#1186)
1515
- Add support for auto-pulling multiple base image for multi stage builds (#1057)
16+
- Fix usage of credential helper that do not support 'version' command (#1159)
1617

1718
* **0.28.0** (2018-12-13)
1819
- Update to JMockit 1.43

src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private AuthConfig createStandardAuthConfig(boolean isPush, Map authConfigMap, S
230230
log.debug("AuthConfig: credentials from ~/.m2/setting.xml");
231231
return ret;
232232
}
233-
233+
234234
// check EC2 instance role if registry is ECR
235235
if (EcrExtendedAuth.isAwsRegistry(registry)) {
236236
try {
@@ -253,8 +253,8 @@ private AuthConfig createStandardAuthConfig(boolean isPush, Map authConfigMap, S
253253
}
254254

255255
// ===================================================================================================
256-
257-
256+
257+
258258
// if the local credentials don't contain user and password, use EC2 instance
259259
// role credentials
260260
private AuthConfig getAuthConfigFromEC2InstanceRole() throws IOException {
@@ -310,7 +310,7 @@ private AuthConfig getAuthConfigFromEC2InstanceRole() throws IOException {
310310
}
311311
}
312312
}
313-
313+
314314
private AuthConfig getAuthConfigFromSystemProperties(LookupMode lookupMode) throws MojoExecutionException {
315315
Properties props = System.getProperties();
316316
String userKey = lookupMode.asSysProperty(AUTH_USERNAME);
@@ -423,9 +423,10 @@ private AuthConfig extractAuthConfigFromAuths(String registryToLookup, JsonObjec
423423

424424
private AuthConfig extractAuthConfigFromCredentialsHelper(String registryToLookup, String credConfig) throws MojoExecutionException {
425425
CredentialHelperClient credentialHelper = new CredentialHelperClient(log, credConfig);
426-
log.debug("AuthConfig: credentials from credential helper/store %s version %s",
426+
String version = credentialHelper.getVersion();
427+
log.debug("AuthConfig: credentials from credential helper/store %s%s",
427428
credentialHelper.getName(),
428-
credentialHelper.getVersion());
429+
version != null ? " version " + version : "");
429430
return credentialHelper.getAuthConfig(registryToLookup);
430431
}
431432

@@ -523,7 +524,7 @@ private AuthConfig validateMandatoryOpenShiftLogin(AuthConfig openShiftAuthConfi
523524
useOpenAuthModeProp, kubeConfigEnv != null ? kubeConfigEnv : "~/.kube/config"));
524525

525526
}
526-
527+
527528

528529
private Server checkForServer(Server server, String id, String registry, String user) {
529530

src/main/java/io/fabric8/maven/docker/util/CredentialHelperClient.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public String getName() {
2828
return credentialHelperName;
2929
}
3030

31-
public String getVersion() throws MojoExecutionException {
31+
public String getVersion() {
3232
try {
3333
return new VersionCommand().getVersion();
3434
} catch (IOException e) {
35-
throw new MojoExecutionException("Error getting the version of the configured credential helper",e);
35+
return null;
3636
}
3737
}
3838

@@ -79,9 +79,6 @@ protected void processLine(String line) {
7979

8080
public String getVersion() throws IOException {
8181
execute();
82-
if (version == null) {
83-
log.verbose("The credentials helper \"%s\" didn't return a version string",CredentialHelperClient.this.credentialHelperName);
84-
}
8582
return version;
8683
}
8784
}

src/test/java/io/fabric8/maven/docker/util/AuthConfigFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void exec(File homeDir) throws IOException, MojoExecutionException {
169169
expectedException.expect(MojoExecutionException.class);
170170
expectedException.expectCause(Matchers.<Throwable>allOf(
171171
instanceOf(IOException.class),
172-
hasProperty("message",startsWith("Failed to start 'docker-credential-credHelper1-does-not-exist version'"))
172+
hasProperty("message",startsWith("Failed to start 'docker-credential-credHelper1-does-not-exist get'"))
173173
));
174174
factory.createAuthConfig(isPush,false,null,settings,"roland","registry1");
175175
}
@@ -185,7 +185,7 @@ public void exec(File homeDir) throws IOException, MojoExecutionException {
185185
expectedException.expect(MojoExecutionException.class);
186186
expectedException.expectCause(Matchers.<Throwable>allOf(
187187
instanceOf(IOException.class),
188-
hasProperty("message",startsWith("Failed to start 'docker-credential-credsStore-does-not-exist version'"))
188+
hasProperty("message",startsWith("Failed to start 'docker-credential-credsStore-does-not-exist get'"))
189189
));
190190
factory.createAuthConfig(isPush,false,null,settings,"roland",null);
191191
}
@@ -201,7 +201,7 @@ public void exec(File homeDir) throws IOException, MojoExecutionException {
201201
expectedException.expect(MojoExecutionException.class);
202202
expectedException.expectCause(Matchers.<Throwable>allOf(
203203
instanceOf(IOException.class),
204-
hasProperty("message",startsWith("Failed to start 'docker-credential-credsStore-does-not-exist version'"))
204+
hasProperty("message",startsWith("Failed to start 'docker-credential-credsStore-does-not-exist get'"))
205205
));
206206
factory.createAuthConfig(isPush,false,null,settings,"roland","registry2");
207207
}

0 commit comments

Comments
 (0)