Search in sources :

Example 6 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactory method getAuthConfigFromSystemProperties.

private AuthConfig getAuthConfigFromSystemProperties(LookupMode lookupMode) throws MojoExecutionException {
    Properties props = System.getProperties();
    String userKey = lookupMode.asSysProperty(AuthConfig.AUTH_USERNAME);
    String passwordKey = lookupMode.asSysProperty(AuthConfig.AUTH_PASSWORD);
    if (props.containsKey(userKey)) {
        if (!props.containsKey(passwordKey)) {
            throw new MojoExecutionException("No " + passwordKey + " provided for username " + props.getProperty(userKey));
        }
        return new AuthConfig(props.getProperty(userKey), decrypt(props.getProperty(passwordKey)), props.getProperty(lookupMode.asSysProperty(AuthConfig.AUTH_EMAIL)), getAuthProperty(props, lookupMode));
    } else {
        return null;
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Properties(java.util.Properties)

Example 7 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testSystemProperty.

private void testSystemProperty(String prefix) throws Exception {
    System.setProperty(prefix + ".username", "roland");
    System.setProperty(prefix + ".password", "secret");
    System.setProperty(prefix + ".email", "roland@jolokia.org");
    try {
        AuthConfig config = factory.createAuthConfig(true, false, null, settings, null, null);
        verifyAuthConfig(config, "roland", "secret", "roland@jolokia.org");
    } finally {
        System.clearProperty(prefix + ".username");
        System.clearProperty(prefix + ".password");
        System.clearProperty(prefix + ".email");
    }
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Example 8 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testDockerSystemPropertyHasPrecedence.

@Test
public void testDockerSystemPropertyHasPrecedence() throws Exception {
    System.setProperty("docker.username", "roland");
    System.setProperty("docker.password", "secret");
    System.setProperty("docker.email", "roland@jolokia.org");
    System.setProperty("registry.username", "_roland");
    System.setProperty("registry.password", "_secret1");
    System.setProperty("registry.email", "_1roland@jolokia.org");
    try {
        AuthConfig config = factory.createAuthConfig(true, false, null, settings, null, null);
        verifyAuthConfig(config, "roland", "secret", "roland@jolokia.org");
    } finally {
        System.clearProperty("docker.username");
        System.clearProperty("docker.password");
        System.clearProperty("docker.email");
        System.clearProperty("registry.username");
        System.clearProperty("registry.password");
        System.clearProperty("registry.email");
    }
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 9 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method incompleteAwsCredentialsAreIgnored.

@Test
public void incompleteAwsCredentialsAreIgnored() throws MojoExecutionException {
    givenAwsSdkIsDisabled();
    environmentVariables.set("AWS_ACCESS_KEY_ID", randomUUID().toString());
    AuthConfig authConfig = factory.createAuthConfig(false, true, null, settings, "user", ECR_NAME);
    assertNull(authConfig);
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 10 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromPluginConfiguration.

@Test
public void testFromPluginConfiguration() throws MojoExecutionException {
    Map pluginConfig = new HashMap();
    pluginConfig.put("username", "roland");
    pluginConfig.put("password", "secret");
    pluginConfig.put("email", "roland@jolokia.org");
    AuthConfig config = factory.createAuthConfig(isPush, false, pluginConfig, settings, null, null);
    verifyAuthConfig(config, "roland", "secret", "roland@jolokia.org");
}
Also used : HashMap(java.util.HashMap) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Aggregations

AuthConfig (io.fabric8.maven.docker.access.AuthConfig)38 Test (org.junit.Test)26 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 ImageName (io.fabric8.maven.docker.util.ImageName)4 HashMap (java.util.HashMap)4 Credential (com.google.cloud.tools.jib.api.Credential)3 JsonObject (com.google.gson.JsonObject)3 IOException (java.io.IOException)3 Date (java.util.Date)3 Map (java.util.Map)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Expectations (mockit.Expectations)2 Verifications (mockit.Verifications)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 Gson (com.google.gson.Gson)1