Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for repository with 'https://' scheme #367

Merged
merged 1 commit into from
Jan 27, 2016
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
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