diff --git a/build.gradle.kts b/build.gradle.kts index 99a465a4..03e8fcea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,6 +29,26 @@ allprojects { } } +subprojects { + repositories { +// mavenLocal() +// listOf( +// "docker-client/docker-engine" +// ).forEach { repo -> +// fun findProperty(s: String) = project.findProperty(s) as String? +// maven { +// name = "github" +// setUrl("https://maven.pkg.github.com/$repo") +// credentials { +// username = System.getenv("PACKAGE_REGISTRY_USER") ?: findProperty("github.package-registry.username") +// password = System.getenv("PACKAGE_REGISTRY_TOKEN") ?: findProperty("github.package-registry.password") +// } +// } +// } + mavenCentral() + } +} + fun findProperty(s: String) = project.findProperty(s) as String? val isSnapshot = project.version == "unspecified" diff --git a/client/build.gradle.kts b/client/build.gradle.kts index b09a6a9a..d9321455 100644 --- a/client/build.gradle.kts +++ b/client/build.gradle.kts @@ -11,10 +11,6 @@ plugins { id("io.freefair.maven-central.validate-poms") } -repositories { - mavenCentral() -} - dependencies { constraints { implementation("org.slf4j:slf4j-api") { @@ -68,7 +64,7 @@ dependencies { } } - api("de.gesellix:docker-engine:2021-09-26T13-30-00") + api("de.gesellix:docker-engine:2021-09-26T18-50-00") api("de.gesellix:docker-compose:2021-09-21T08-00-00") implementation("org.codehaus.groovy:groovy:[2.5,)") diff --git a/client/src/main/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClient.groovy b/client/src/main/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClient.groovy index 465b1784..594287e3 100644 --- a/client/src/main/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClient.groovy +++ b/client/src/main/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClient.groovy @@ -1,6 +1,9 @@ package de.gesellix.docker.client.authentication import com.squareup.moshi.Moshi +import de.gesellix.docker.authentication.AuthConfig +import de.gesellix.docker.authentication.AuthConfigReader +import de.gesellix.docker.authentication.CredsStore import de.gesellix.docker.client.distribution.ReferenceParser import de.gesellix.docker.client.registry.RegistryElection import de.gesellix.docker.client.system.ManageSystem diff --git a/client/src/main/groovy/de/gesellix/docker/client/registry/RegistryElection.groovy b/client/src/main/groovy/de/gesellix/docker/client/registry/RegistryElection.groovy index acaad06c..7ca0bcf5 100644 --- a/client/src/main/groovy/de/gesellix/docker/client/registry/RegistryElection.groovy +++ b/client/src/main/groovy/de/gesellix/docker/client/registry/RegistryElection.groovy @@ -1,6 +1,6 @@ package de.gesellix.docker.client.registry -import de.gesellix.docker.client.authentication.AuthConfig +import de.gesellix.docker.authentication.AuthConfig import de.gesellix.docker.client.authentication.ManageAuthentication import de.gesellix.docker.client.system.ManageSystem import de.gesellix.docker.engine.DockerEnv diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfig.java b/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfig.java deleted file mode 100644 index 0006f8dc..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfig.java +++ /dev/null @@ -1,93 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import java.util.Objects; - -public class AuthConfig { - - public static final AuthConfig EMPTY_AUTH_CONFIG = new AuthConfig(); - - private String username; - private String password; - private String auth; - /** - * Email is an optional value associated with the username. - * - * @deprecated This field is deprecated and will be removed in a later version of docker. - */ - @Deprecated - private String email; - private String serveraddress; - private String identitytoken; - private String registrytoken; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getAuth() { - return auth; - } - - public void setAuth(String auth) { - this.auth = auth; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getServeraddress() { - return serveraddress; - } - - public void setServeraddress(String serveraddress) { - this.serveraddress = serveraddress; - } - - public String getIdentitytoken() { - return identitytoken; - } - - public void setIdentitytoken(String identitytoken) { - this.identitytoken = identitytoken; - } - - public String getRegistrytoken() { - return registrytoken; - } - - public void setRegistrytoken(String registrytoken) { - this.registrytoken = registrytoken; - } - - @Override - public boolean equals(Object o) { - if (this == o) {return true;} - if (o == null || getClass() != o.getClass()) {return false;} - AuthConfig that = (AuthConfig) o; - return Objects.equals(username, that.username) && Objects.equals(password, that.password) && Objects.equals(auth, that.auth) && - Objects.equals(email, that.email) && Objects.equals(serveraddress, that.serveraddress) && Objects.equals(identitytoken, that.identitytoken) && - Objects.equals(registrytoken, that.registrytoken); - } - - @Override - public int hashCode() { - return Objects.hash(username, password, auth, email, serveraddress, identitytoken, registrytoken); - } -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfigReader.java b/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfigReader.java deleted file mode 100644 index ed7d7fbf..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/AuthConfigReader.java +++ /dev/null @@ -1,85 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import com.squareup.moshi.Moshi; -import de.gesellix.docker.engine.DockerEnv; -import okio.Okio; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.text.MessageFormat; -import java.util.Collections; -import java.util.Map; - -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG; - -public class AuthConfigReader { - - private final static Logger log = LoggerFactory.getLogger(AuthConfigReader.class); - - private final Moshi moshi = new Moshi.Builder().build(); - - private final DockerEnv env; - - public AuthConfigReader() { - this(new DockerEnv()); - } - - public AuthConfigReader(DockerEnv env) { - this.env = env; - } - - // @Override - AuthConfig readDefaultAuthConfig() { - return readAuthConfig(null, env.getDockerConfigFile()); - } - - // @Override - AuthConfig readAuthConfig(String hostname, File dockerCfg) { - log.debug("read authConfig"); - - if (hostname == null || hostname.trim().isEmpty()) { - hostname = env.getIndexUrl_v1(); - } - - Map parsedDockerCfg = readDockerConfigFile(dockerCfg); - if (parsedDockerCfg == null || parsedDockerCfg.isEmpty()) { - return EMPTY_AUTH_CONFIG; - } - - CredsStore credsStore = getCredentialsStore(parsedDockerCfg, hostname); - return credsStore.getAuthConfig(hostname); - } - - Map readDockerConfigFile(File dockerCfg) { - if (dockerCfg == null) { - dockerCfg = env.getDockerConfigFile(); - } - if (dockerCfg == null || !dockerCfg.exists()) { - log.info("docker config '${dockerCfg}' doesn't exist"); - return Collections.emptyMap(); - } - log.debug("reading auth info from {}", dockerCfg); - try { - return moshi.adapter(Map.class).fromJson(Okio.buffer(Okio.source(dockerCfg))); - } - catch (Exception e) { - log.debug(MessageFormat.format("failed to read auth info from {}", dockerCfg), e); - return Collections.emptyMap(); - } - } - - CredsStore getCredentialsStore(Map parsedDockerCfg) { - return getCredentialsStore(parsedDockerCfg, ""); - } - - CredsStore getCredentialsStore(Map parsedDockerCfg, String hostname) { - if (parsedDockerCfg.containsKey("credHelpers") && hostname != null && !hostname.trim().isEmpty()) { - return new NativeStore((String) ((Map) parsedDockerCfg.get("credHelpers")).get(hostname)); - } - if (parsedDockerCfg.containsKey("credsStore")) { - return new NativeStore((String) parsedDockerCfg.get("credsStore")); - } - return new FileStore(parsedDockerCfg); - } -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStore.java b/client/src/main/java/de/gesellix/docker/client/authentication/CredsStore.java deleted file mode 100644 index 72ec09e2..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStore.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import java.util.Map; - -public interface CredsStore { - - AuthConfig getAuthConfig(String registry); - - Map getAuthConfigs(); -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelper.java b/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelper.java deleted file mode 100644 index 718eef57..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelper.java +++ /dev/null @@ -1,104 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import com.squareup.moshi.Moshi; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.text.MessageFormat; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -public class CredsStoreHelper { - - private static final Logger log = LoggerFactory.getLogger(CredsStoreHelper.class); - private final Moshi moshi = new Moshi.Builder().build(); - - public CredsStoreHelperResult getAuthentication(String credsStore, String hostname) { - Result result = execCredsHelper(credsStore, "get", hostname); - return toCredsStoreHelperResult(result, credsStore); - } - - public CredsStoreHelperResult getAuthentication(String credsStore) { - return getAuthentication(credsStore, "https://index.docker.io/v1/"); - } - - public CredsStoreHelperResult getAllAuthentications(String credsStore) { - Result result = execCredsHelper(credsStore, "list", "unused"); - return toCredsStoreHelperResult(result, credsStore); - } - - public CredsStoreHelperResult toCredsStoreHelperResult(Result result, String credsStore) { - if (!result.getSuccess()) { - return new CredsStoreHelperResult(result.getMessage()); - } - - try { - return new CredsStoreHelperResult(moshi.adapter(Map.class).fromJson(result.getMessage())); - } - catch (IOException exc) { - log.error(MessageFormat.format("cannot parse docker-credential-{0} result", credsStore), exc); - return new CredsStoreHelperResult(exc.getMessage()); - } - catch (Exception exc) { - log.error(MessageFormat.format("error trying to get credentials from docker-credential-{0}", credsStore), exc); - return new CredsStoreHelperResult(exc.getMessage()); - } - } - - private Result execCredsHelper(String credsStore, String command, String input) { - Process process; - try { - process = new ProcessBuilder(MessageFormat.format("docker-credential-{0}", credsStore), command).redirectErrorStream(true).redirectOutput(ProcessBuilder.Redirect.PIPE).start(); - } - catch (Exception exc) { - log.error(MessageFormat.format("error trying to execute docker-credential-{0} {1}", credsStore, command), exc); - return new Result(false, exc.getMessage()); - } - - BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream())); - - try { - process.getOutputStream().write((input == null ? "".getBytes() : input.getBytes())); - process.getOutputStream().flush(); - process.getOutputStream().close(); - - process.waitFor(10, TimeUnit.SECONDS); - } - catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - - if (process.exitValue() != 0) { - log.error(MessageFormat.format("docker-credential-{0} {1} failed", credsStore, command)); - } - - return new Result(process.exitValue() == 0, buffer.lines().collect(Collectors.joining())); - } - - public static class Result { - - private final boolean success; - private final String message; - - public Result(boolean success, String message) { - this.success = success; - this.message = message; - } - - public boolean getSuccess() { - return success; - } - - public boolean isSuccess() { - return success; - } - - public String getMessage() { - return message; - } - } -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelperResult.java b/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelperResult.java deleted file mode 100644 index 2408bb18..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/CredsStoreHelperResult.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import java.util.Map; -import java.util.Objects; - -public class CredsStoreHelperResult { - - private String error; - private Map data; - - public CredsStoreHelperResult(String error) { - this.error = error; - } - - public CredsStoreHelperResult(Map data) { - this.data = data; - } - - public String getError() { - return error; - } - - public Map getData() { - return data; - } - - @Override - public boolean equals(Object o) { - if (this == o) {return true;} - if (o == null || getClass() != o.getClass()) {return false;} - CredsStoreHelperResult that = (CredsStoreHelperResult) o; - return Objects.equals(error, that.error) && Objects.equals(data, that.data); - } - - @Override - public int hashCode() { - return Objects.hash(error, data); - } -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/FileStore.java b/client/src/main/java/de/gesellix/docker/client/authentication/FileStore.java deleted file mode 100644 index 4c5f0047..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/FileStore.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import java.util.Base64; -import java.util.Map; -import java.util.stream.Collectors; - -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG; - -public class FileStore implements CredsStore { - - private final Map config; - private transient Map allAuthConfigs; - - public FileStore(Map config) { - this.config = config.containsKey("auths") ? (Map) config.get("auths") : config; - } - - @Override - public AuthConfig getAuthConfig(String registry) { - final AuthConfig authConfig = getAuthConfigs().get(registry); - return authConfig != null ? authConfig : EMPTY_AUTH_CONFIG; - } - - @Override - public Map getAuthConfigs() { - if (allAuthConfigs == null) { - allAuthConfigs = config.entrySet().stream() - .filter((e) -> e.getValue() != null && e.getValue().get("auth") != null) - .collect(Collectors.toMap( - Map.Entry::getKey, - e -> { - String registry = e.getKey(); - Map value = e.getValue(); - String[] login = new String(Base64.getDecoder().decode((String) value.get("auth"))).split(":"); - String username = login[0]; - String password = login[1]; - - AuthConfig authConfig = new AuthConfig(); - authConfig.setServeraddress(registry); - authConfig.setUsername(username); - authConfig.setPassword(password); - authConfig.setEmail((String) value.get("email")); - return authConfig; - } - )); - } - return allAuthConfigs; - } -} diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/ManageAuthentication.java b/client/src/main/java/de/gesellix/docker/client/authentication/ManageAuthentication.java index 42a80763..d82ed7ca 100644 --- a/client/src/main/java/de/gesellix/docker/client/authentication/ManageAuthentication.java +++ b/client/src/main/java/de/gesellix/docker/client/authentication/ManageAuthentication.java @@ -1,5 +1,6 @@ package de.gesellix.docker.client.authentication; +import de.gesellix.docker.authentication.AuthConfig; import de.gesellix.docker.engine.EngineResponse; import java.io.File; diff --git a/client/src/main/java/de/gesellix/docker/client/authentication/NativeStore.java b/client/src/main/java/de/gesellix/docker/client/authentication/NativeStore.java deleted file mode 100644 index 8ea3a463..00000000 --- a/client/src/main/java/de/gesellix/docker/client/authentication/NativeStore.java +++ /dev/null @@ -1,88 +0,0 @@ -package de.gesellix.docker.client.authentication; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG; - -public class NativeStore implements CredsStore { - - private final static Logger log = LoggerFactory.getLogger(NativeStore.class); - - private final static String TOKEN_USERNAME = ""; - - private final String credStoreName; - - CredsStoreHelper credsStoreHelper; - - public NativeStore(String credStoreName) { - this.credStoreName = credStoreName; - this.credsStoreHelper = new CredsStoreHelper(); - } - - @Override - public AuthConfig getAuthConfig(String registry) { - CredsStoreHelperResult creds = credsStoreHelper.getAuthentication(credStoreName, registry); - if (creds.getError() != null && !creds.getError().trim().isEmpty()) { - log.info("Error reading credentials from 'credsStore={}' for authentication at {}: {}", credStoreName, registry, creds.getError()); - return EMPTY_AUTH_CONFIG; - } - else if (creds.getData() != null && !creds.getData().isEmpty()) { - log.info("Got credentials from 'credsStore={}'", credStoreName); - AuthConfig result = parseCreds(creds.getData()); - result.setServeraddress(registry); - return result; - } - else { - log.warn("Using 'credsStore={}' for authentication at {} is currently not supported", credStoreName, registry); - return EMPTY_AUTH_CONFIG; - } - } - - @Override - public Map getAuthConfigs() { - final Map result = new HashMap(); - CredsStoreHelperResult creds = credsStoreHelper.getAllAuthentications(credStoreName); - if (creds.getError() != null && !creds.getError().trim().isEmpty()) { - log.info("Error reading credentials from 'credsStore={}': {}", credStoreName, creds.getError()); - return result; - } - else if (creds.getData() != null && !creds.getData().isEmpty()) { - log.info("Got credentials from 'credsStore={}'", credStoreName); - return creds.getData().keySet() - .stream() - .collect(Collectors.toMap( - k -> k, - this::getAuthConfig - )); - } - else { - log.warn("Using 'credsStore={}' is currently not supported", credStoreName); - return result; - } - } - - private AuthConfig parseCreds(Map creds) { - AuthConfig authDetails; - if (TOKEN_USERNAME.equals(creds.get("Username"))) { - authDetails = new AuthConfig(); - authDetails.setIdentitytoken((String) creds.get("Secret")); - } - else { - authDetails = new AuthConfig(); - authDetails.setUsername((String) creds.get("Username")); - authDetails.setPassword((String) creds.get("Secret")); - } - - return authDetails; - } - - private static Value putAt0(Map propOwner, K key, Value value) { - propOwner.put(key, value); - return value; - } -} diff --git a/client/src/test/groovy/de/gesellix/docker/client/authentication/FileStoreTest.groovy b/client/src/test/groovy/de/gesellix/docker/client/authentication/FileStoreTest.groovy deleted file mode 100644 index 9ac9b437..00000000 --- a/client/src/test/groovy/de/gesellix/docker/client/authentication/FileStoreTest.groovy +++ /dev/null @@ -1,73 +0,0 @@ -package de.gesellix.docker.client.authentication - -import spock.lang.Specification - -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG - -class FileStoreTest extends Specification { - - def "getAuthConfig returns entry matching registry hostname"() { - given: - FileStore credsStore = new FileStore([auths: ["host.name": [auth: "Z2VzZWxsaXg6LXlldC1hbm90aGVyLXBhc3N3b3JkLQ==", email: "tobias@gesellix.de"]]]) - - when: - AuthConfig result = credsStore.getAuthConfig("host.name") - - then: - result == new AuthConfig( - username: "gesellix", - password: "-yet-another-password-", - email: "tobias@gesellix.de", - serveraddress: "host.name" - ) - } - - def "getAuthConfig returns empty AuthConfig for missing entry"() { - given: - FileStore credsStore = new FileStore([auths: ["host.name": [auth: "Z2VzZWxsaXg6LXlldC1hbm90aGVyLXBhc3N3b3JkLQ==", email: "tobias@gesellix.de"]]]) - - expect: - EMPTY_AUTH_CONFIG == credsStore.getAuthConfig("missing.host.name") - } - - def "getAuthConfig returns empty AuthConfig for empty entry"() { - given: - FileStore credsStore = new FileStore([auths: ["host.name": [:]]]) - - expect: - EMPTY_AUTH_CONFIG == credsStore.getAuthConfig("host.name") - } - - def "getAuthConfig returns empty AuthConfig for empty auth"() { - given: - FileStore credsStore = new FileStore([auths: ["host.name": [auth: null, email: "tobias@gesellix.de"]]]) - - expect: - EMPTY_AUTH_CONFIG == credsStore.getAuthConfig("host.name") - } - - def "getAuthConfigs all known AuthConfigs"() { - given: - FileStore credsStore = new FileStore([auths: [ - "host1.name": [auth: "Z2VzZWxsaXg6LXlldC1hbm90aGVyLXBhc3N3b3JkLQ==", email: "tobias@gesellix.de"], - "host2.name": [auth: "Z2VzZWxsaXg6LWEtcGFzc3dvcmQtZm9yLXF1YXkt", email: "tobias@gesellix.de"]]]) - - when: - Map result = credsStore.getAuthConfigs() - - then: - result.size() == 2 - result["host1.name"] == new AuthConfig( - username: "gesellix", - password: "-yet-another-password-", - email: "tobias@gesellix.de", - serveraddress: "host1.name" - ) - result["host2.name"] == new AuthConfig( - username: "gesellix", - password: "-a-password-for-quay-", - email: "tobias@gesellix.de", - serveraddress: "host2.name" - ) - } -} diff --git a/client/src/test/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClientTest.groovy b/client/src/test/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClientTest.groovy index 15ed45a6..61148909 100644 --- a/client/src/test/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClientTest.groovy +++ b/client/src/test/groovy/de/gesellix/docker/client/authentication/ManageAuthenticationClientTest.groovy @@ -2,6 +2,8 @@ package de.gesellix.docker.client.authentication import com.squareup.moshi.Moshi import com.squareup.moshi.Types +import de.gesellix.docker.authentication.AuthConfig +import de.gesellix.docker.authentication.AuthConfigReader import de.gesellix.docker.client.DockerClient import de.gesellix.docker.client.system.ManageSystem import de.gesellix.docker.engine.DockerEnv @@ -12,7 +14,7 @@ import spock.lang.Specification import java.lang.reflect.Type -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG +import static de.gesellix.docker.authentication.AuthConfig.EMPTY_AUTH_CONFIG class ManageAuthenticationClientTest extends Specification { diff --git a/client/src/test/groovy/de/gesellix/docker/client/authentication/NativeStoreTest.groovy b/client/src/test/groovy/de/gesellix/docker/client/authentication/NativeStoreTest.groovy deleted file mode 100644 index 1c93aca9..00000000 --- a/client/src/test/groovy/de/gesellix/docker/client/authentication/NativeStoreTest.groovy +++ /dev/null @@ -1,98 +0,0 @@ -package de.gesellix.docker.client.authentication - -import spock.lang.Specification -import spock.lang.Unroll - -import static de.gesellix.docker.client.authentication.AuthConfig.EMPTY_AUTH_CONFIG - -class NativeStoreTest extends Specification { - - NativeStore credsStore - CredsStoreHelper credsStoreHelper = Mock(CredsStoreHelper) - - def setup() { - credsStore = new NativeStore("test-helper") - credsStore.credsStoreHelper = credsStoreHelper - } - - def "getAuthConfig calls credsStoreHelper"() { - when: - credsStore.getAuthConfig("host.name") - then: - 1 * credsStoreHelper.getAuthentication("test-helper", "host.name") >> [:] - } - - @Unroll - def "getAuthConfig returns empty AuthConfig on invalid credsStoreHelperResponse #credsStoreHelperResponse"() { - given: - credsStoreHelper.getAuthentication("test-helper", "host.name") >> credsStoreHelperResponse - when: - AuthConfig result = credsStore.getAuthConfig("host.name") - then: - result == EMPTY_AUTH_CONFIG - where: - credsStoreHelperResponse << [new CredsStoreHelperResult("for-test"), new CredsStoreHelperResult((String) null)] - } - - def "getAuthConfig returns AuthConfig for valid username/password credentials"() { - given: - def credsStoreHelperResponse = new CredsStoreHelperResult([Username: "foo", Secret: "bar"]) - credsStoreHelper.getAuthentication("test-helper", "host.name") >> credsStoreHelperResponse - - when: - AuthConfig result = credsStore.getAuthConfig("host.name") - - then: - result == new AuthConfig(username: "foo", password: "bar", serveraddress: "host.name") - } - - def "getAuthConfig returns AuthConfig for valid identitytoken credentials"() { - given: - def credsStoreHelperResponse = new CredsStoreHelperResult([Username: "", Secret: "baz"]) - credsStoreHelper.getAuthentication("test-helper", "host.name") >> credsStoreHelperResponse - - when: - AuthConfig result = credsStore.getAuthConfig("host.name") - - then: - result == new AuthConfig(identitytoken: "baz", serveraddress: "host.name") - } - - def "getAuthConfigs calls credsStoreHelper"() { - when: - credsStore.getAuthConfigs() - then: - 1 * credsStoreHelper.getAllAuthentications("test-helper") >> [:] - } - - @Unroll - def "getAuthConfigs returns empty AuthConfig on invalid credsStoreHelperResponse #credsStoreHelperResponse"() { - when: - Map result = credsStore.getAuthConfigs() - - then: - 1 * credsStoreHelper.getAllAuthentications("test-helper") >> new CredsStoreHelperResult(["host1.name": "username", "host2.name": "username"]) - 1 * credsStoreHelper.getAuthentication("test-helper", "host1.name") >> new CredsStoreHelperResult([Username: "", Secret: "baz"]) - 1 * credsStoreHelper.getAuthentication("test-helper", "host2.name") >> credsStoreHelperResponse - 0 * credsStoreHelper._ - result.size() == 2 - result["host2.name"] == EMPTY_AUTH_CONFIG - - where: - credsStoreHelperResponse << [new CredsStoreHelperResult("for-test"), new CredsStoreHelperResult((String) null)] - } - - def "getAuthConfigs returns AuthConfigs for valid credsStoreHelperResponse"() { - when: - Map result = credsStore.getAuthConfigs() - - then: - 1 * credsStoreHelper.getAllAuthentications("test-helper") >> new CredsStoreHelperResult(["host1.name": "username", "host2.name": "username"]) - 1 * credsStoreHelper.getAuthentication("test-helper", "host1.name") >> new CredsStoreHelperResult([Username: "user-name", Secret: "password"]) - 1 * credsStoreHelper.getAuthentication("test-helper", "host2.name") >> new CredsStoreHelperResult([Username: "", Secret: "baz"]) - 0 * credsStoreHelper._ - result.size() == 2 - result["host1.name"] == new AuthConfig(username: "user-name", password: "password", serveraddress: "host1.name") - result["host2.name"] == new AuthConfig(identitytoken: "baz", serveraddress: "host2.name") - } -} diff --git a/client/src/test/groovy/de/gesellix/docker/client/image/ManageImageClientTest.groovy b/client/src/test/groovy/de/gesellix/docker/client/image/ManageImageClientTest.groovy index 66aab0b0..d0ba94c4 100644 --- a/client/src/test/groovy/de/gesellix/docker/client/image/ManageImageClientTest.groovy +++ b/client/src/test/groovy/de/gesellix/docker/client/image/ManageImageClientTest.groovy @@ -1,7 +1,7 @@ package de.gesellix.docker.client.image +import de.gesellix.docker.authentication.AuthConfig import de.gesellix.docker.client.DockerResponseHandler -import de.gesellix.docker.client.authentication.AuthConfig import de.gesellix.docker.client.authentication.ManageAuthentication import de.gesellix.docker.engine.EngineClient import de.gesellix.docker.engine.EngineResponse diff --git a/client/src/test/groovy/de/gesellix/docker/client/registry/RegistryElectionTest.groovy b/client/src/test/groovy/de/gesellix/docker/client/registry/RegistryElectionTest.groovy index c0d3e09d..1f9f31f8 100644 --- a/client/src/test/groovy/de/gesellix/docker/client/registry/RegistryElectionTest.groovy +++ b/client/src/test/groovy/de/gesellix/docker/client/registry/RegistryElectionTest.groovy @@ -1,6 +1,6 @@ package de.gesellix.docker.client.registry -import de.gesellix.docker.client.authentication.AuthConfig +import de.gesellix.docker.authentication.AuthConfig import de.gesellix.docker.client.authentication.ManageAuthentication import de.gesellix.docker.client.system.ManageSystem import de.gesellix.docker.engine.EngineResponse diff --git a/explore/build.gradle.kts b/explore/build.gradle.kts index cb406611..8c32604e 100644 --- a/explore/build.gradle.kts +++ b/explore/build.gradle.kts @@ -8,10 +8,6 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } -repositories { - mavenCentral() -} - dependencies { constraints { implementation("org.slf4j:slf4j-api") { diff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.kts index 50f0eb5d..9d5f8534 100644 --- a/integration-test/build.gradle.kts +++ b/integration-test/build.gradle.kts @@ -8,10 +8,6 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } -repositories { - mavenCentral() -} - dependencies { constraints { implementation("org.slf4j:slf4j-api") { diff --git a/integration-test/src/test/groovy/de/gesellix/docker/client/authentication/CredsStoreHelperIntegrationTest.groovy b/integration-test/src/test/groovy/de/gesellix/docker/client/authentication/CredsStoreHelperIntegrationTest.groovy deleted file mode 100644 index 5d94b64f..00000000 --- a/integration-test/src/test/groovy/de/gesellix/docker/client/authentication/CredsStoreHelperIntegrationTest.groovy +++ /dev/null @@ -1,119 +0,0 @@ -package de.gesellix.docker.client.authentication - -import de.gesellix.docker.engine.DockerEnv -import spock.lang.Requires -import spock.lang.Specification - -class CredsStoreHelperIntegrationTest extends Specification { - - CredsStoreHelper helper - - def setup() { - helper = new CredsStoreHelper() - println "--- ${System.properties['user.name']} on ${System.properties['os.name']}" - } - - @Requires({ System.properties['user.name'] == 'gesellix' && ['Mac OS X', 'Windows'].contains(System.properties['os.name']) }) - def "can get auth from desktop on Mac OS X and Windows"() { - when: - def result = helper.getAuthentication("desktop") - then: - result == new CredsStoreHelperResult( - data: [ - ServerURL: new DockerEnv().indexUrl_v1, - Username : "gesellix", - Secret : "-yet-another-password-" - ] - ) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && ['Mac OS X', 'Windows'].contains(System.properties['os.name']) }) - def "can list auths from desktop on Mac OS X and Windows"() { - when: - def result = helper.getAllAuthentications("desktop") - then: - result == new CredsStoreHelperResult(data: [(new DockerEnv().indexUrl_v1): "gesellix"]) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Mac OS X" }) - def "can get auth from osxkeychain on Mac OS X"() { - when: - def result = helper.getAuthentication("osxkeychain") - then: - result == new CredsStoreHelperResult( - data: [ - ServerURL: new DockerEnv().indexUrl_v1, - Username : "gesellix", - Secret : "-yet-another-password-" - ] - ) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Mac OS X" }) - def "can list auths from osxkeychain on Mac OS X"() { - when: - def result = helper.getAllAuthentications("osxkeychain") - then: - result == new CredsStoreHelperResult(data: [(new DockerEnv().indexUrl_v1): "gesellix"]) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Windows" }) - def "can get auth from wincred on Windows"() { - when: - def result = helper.getAuthentication("wincred") - then: - result == new CredsStoreHelperResult( - data: [ - ServerURL: new DockerEnv().indexUrl_v1, - Username : "gesellix", - Secret : "-yet-another-password-" - ] - ) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Windows" }) - def "can list auths from wincred on Windows"() { - when: - def result = helper.getAllAuthentications("wincred") - then: - result == new CredsStoreHelperResult(data: [(new DockerEnv().indexUrl_v1): "gesellix"]) - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Linux" }) - def "can get auth from secretservice on Linux"() { - when: - CredsStoreHelperResult result = helper.getAuthentication("secretservice") - then: - result.error == null - result.data.ServerURL == "" - result.data.Username == "gesellix" - result.data.Secret =~ ".+" - } - - @Requires({ System.properties['user.name'] == 'gesellix' && System.properties['os.name'] == "Linux" }) - def "can list auths from secretservice on Linux"() { - when: - def result = helper.getAllAuthentications("secretservice") - then: - result == new CredsStoreHelperResult(data: [(new DockerEnv().indexUrl_v1): "gesellix"]) - } - - @Requires({ System.properties['user.name'] == 'gesellix' }) - def "handles errors more or less gracefully"() { - when: - def result = helper.getAuthentication(System.properties['os.name'] == "Linux" ? "secretservice" : "osxkeychain", "foo") - then: - result.data == null - and: - result.error =~ ".*credentials not found in native keychain.*" - } - - def "handles missing docker-credential-helper more or less gracefully"() { - when: - def result = helper.getAuthentication("should-be-missing", "foo") - then: - result.data == null - and: - result.error =~ ".*Cannot run program \"docker-credential-should-be-missing\".*" - } -}