Skip to content

Commit

Permalink
fix: Lookup of registry failed when using index.docker.io
Browse files Browse the repository at this point in the history
Fixes #946, too
  • Loading branch information
rhuss committed Apr 14, 2018
1 parent 49badf4 commit 83d9dcb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Expand Up @@ -355,7 +355,7 @@ private JSONObject getCredentialsNode(JSONObject auths,String registryToLookup)
if (auths.has(registryToLookup)) {
return auths.getJSONObject(registryToLookup);
}
String registryWithScheme = "https://" + registryToLookup;
String registryWithScheme = EnvUtil.ensureRegistryHttpUrl(registryToLookup);
if (auths.has(registryWithScheme)) {
return auths.getJSONObject(registryWithScheme);
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public String getVersion() throws MojoExecutionException {
public AuthConfig getAuthConfig(String registryToLookup) throws MojoExecutionException {
try {
final GetCommand getCommand = new GetCommand();
return toAuthConfig(getCommand.getCredentialNode("https://" + registryToLookup));
return toAuthConfig(getCommand.getCredentialNode(EnvUtil.ensureRegistryHttpUrl(registryToLookup)));
} catch (IOException e) {
throw new MojoExecutionException("Error getting the credentials for " + registryToLookup + " from the configured credential helper",e);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ protected String[] getArgs() {

@Override
protected void processLine(String line) {
log.info("Credentials helper reply for \"%s\" is %s",CredentialHelperClient.this.credentialHelperName,line);
log.verbose("Credentials helper reply for \"%s\" is %s",CredentialHelperClient.this.credentialHelperName,line);
version = line;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/fabric8/maven/docker/util/EnvUtil.java
Expand Up @@ -374,6 +374,15 @@ public static String fistRegistryOf(String ... checkFirst) {
return System.getenv("DOCKER_REGISTRY");
}

// sometimes registries might be specified with https? schema, sometimes not
public static String ensureRegistryHttpUrl(String registry) {
if (registry.toLowerCase().startsWith("http")) {
return registry;
}
// Default to https:// schema
return "https://" + registry;
}

public static File prepareAbsoluteOutputDirPath(MojoParameters params, String dir, String path) {
return prepareAbsolutePath(params, new File(params.getOutputDirectory(), dir).toString(), path);
}
Expand Down
20 changes: 17 additions & 3 deletions src/test/java/io/fabric8/maven/docker/util/EnvUtilTest.java
Expand Up @@ -174,14 +174,14 @@ public void fixupPath() throws Exception {


}

@Test
public void isValidWindowsFileName() {

assertFalse(EnvUtil.isValidWindowsFileName("/Dockerfile"));
assertTrue(EnvUtil.isValidWindowsFileName("Dockerfile"));
assertFalse(EnvUtil.isValidWindowsFileName("Dockerfile/"));
}
}

private Properties getTestProperties(String ... vals) {
Properties ret = new Properties();
Expand All @@ -192,4 +192,18 @@ private Properties getTestProperties(String ... vals) {
}

private Object $(Object ... o) { return o; }

@Test
public void ensureRegistryHttpUrl() {
String[] data = {
"https://index.docker.io/v1/", "https://index.docker.io/v1/",
"index.docker.io/v1/", "https://index.docker.io/v1/",
"http://index.docker.io/v1/", "http://index.docker.io/v1/",
"registry.fuse-ignite.openshift.com", "https://registry.fuse-ignite.openshift.com"
};

for (int i = 0; i < data.length; i +=2) {
assertEquals(">> " + data[i], data[i+1], EnvUtil.ensureRegistryHttpUrl(data[i]));
}
}
}

0 comments on commit 83d9dcb

Please sign in to comment.