Skip to content

Commit

Permalink
Check for repository with 'https://' scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Belyakov <belyakov.sergey@gmail.com>
  • Loading branch information
nakedpony committed Jan 27, 2016
1 parent 860d3e0 commit 33f18c4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
50 changes: 33 additions & 17 deletions src/main/java/org/jolokia/docker/maven/util/AuthConfigFactory.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.jolokia.docker.maven.util;

import java.io.*;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.settings.Server;
Expand All @@ -19,6 +13,18 @@
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Factory for creating docker specific authentication configuration
*
Expand Down Expand Up @@ -215,17 +221,27 @@ private AuthConfig getAuthConfigFromSettings(Settings settings, String user, Str

private AuthConfig getAuthConfigFromDockerConfig(String registry) throws MojoExecutionException {
JSONObject dockerConfig = readDockerConfig();
if (dockerConfig != null && dockerConfig.has("auths")) {
JSONObject auths = dockerConfig.getJSONObject("auths");
String registryToLookup = registry != null ? registry : DOCKER_LOGIN_DEFAULT_REGISTRY;
if (auths.has(registryToLookup)) {
JSONObject entry = auths.getJSONObject(registryToLookup);
if (entry.has("auth")) {
String auth = entry.getString("auth");
String email = entry.has("email") ? entry.getString("email") : null;
return new AuthConfig(auth,email);
}
}
if (dockerConfig == null || !dockerConfig.has("auths")) {
return null;
}
JSONObject auths = dockerConfig.getJSONObject("auths");
String registryToLookup = registry != null ? registry : DOCKER_LOGIN_DEFAULT_REGISTRY;
JSONObject credentials = getCredentialsNode(auths, registryToLookup);
if (credentials == null) {
return null;
}
String auth = credentials.getString("auth");
String email = credentials.has("email") ? credentials.getString("email") : null;
return new AuthConfig(auth,email);
}

private JSONObject getCredentialsNode(JSONObject auths, String registryToLookup) {
if (auths.has(registryToLookup)) {
return auths.getJSONObject(registryToLookup);
}
String registryWithScheme = "https://" + registryToLookup;
if (auths.has(registryWithScheme)) {
return auths.getJSONObject(registryWithScheme);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.jolokia.docker.maven.util;

import java.io.*;
import java.nio.file.Files;
import java.util.*;

import mockit.*;
import mockit.Mock;
import mockit.MockUp;
import mockit.Mocked;
import mockit.NonStrictExpectations;
import mockit.integration.junit4.JMockit;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.settings.Server;
Expand All @@ -21,6 +20,16 @@
import org.junit.runner.RunWith;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

/**
Expand Down Expand Up @@ -85,6 +94,7 @@ public void testDockerLogin() throws Exception {
public void exec(File homeDir) throws IOException, MojoExecutionException {
checkDockerLogin(homeDir,AuthConfigFactory.DOCKER_LOGIN_DEFAULT_REGISTRY,null);
checkDockerLogin(homeDir,"localhost:5000","localhost:5000");
checkDockerLogin(homeDir,"https://localhost:5000","localhost:5000");
}
});
}
Expand Down

0 comments on commit 33f18c4

Please sign in to comment.