Search in sources :

Example 31 with User

use of io.fabric8.openshift.api.model.User in project docker-maven-plugin by fabric8io.

the class AuthConfigFactory method createAuthConfig.

/**
 * Create an authentication config object which can be used for communication with a Docker registry
 *
 * The authentication information is looked up at various places (in this order):
 *
 * <ul>
 *    <li>From system properties</li>
 *    <li>From the provided map which can contain key-value pairs</li>
 *    <li>From the openshift settings in ~/.config/kube</li>
 *    <li>From the Maven settings stored typically in ~/.m2/settings.xml</li>
 *    <li>From the Docker settings stored in ~/.docker/config.json</li>
 * </ul>
 *
 * The following properties (prefix with 'docker.') and config key are evaluated:
 *
 * <ul>
 *     <li>username: User to authenticate</li>
 *     <li>password: Password to authenticate. Can be encrypted</li>
 *     <li>email: Optional EMail address which is send to the registry, too</li>
 * </ul>
 *
 *  If the repository is in an aws ecr registry and skipExtendedAuth is not true, if found
 *  credentials are not from docker settings, they will be interpreted as iam credentials
 *  and exchanged for ecr credentials.
 *
 * @param isPush if true this AuthConfig is created for a push, if false it's for a pull
 * @param skipExtendedAuth if true, do not execute extended authentication methods
 * @param authConfig String-String Map holding configuration info from the plugin's configuration. Can be <code>null</code> in
 *                   which case the settings are consulted.
 * @param settings the global Maven settings object
 * @param user user to check for
 * @param registry registry to use, might be null in which case a default registry is checked,
 * @return the authentication configuration or <code>null</code> if none could be found
 *
 * @throws MojoFailureException
 */
public AuthConfig createAuthConfig(boolean isPush, boolean skipExtendedAuth, Map authConfig, Settings settings, String user, String registry) throws MojoExecutionException {
    AuthConfig ret = createStandardAuthConfig(isPush, authConfig, settings, user, registry);
    if (ret != null) {
        if (registry == null || skipExtendedAuth) {
            return ret;
        }
        try {
            return extendedAuthentication(ret, registry);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    // Finally check ~/.docker/config.json
    ret = getAuthConfigFromDockerConfig(registry);
    if (ret != null) {
        log.debug("AuthConfig: credentials from ~/.docker/config.json");
        return ret;
    }
    log.debug("AuthConfig: no credentials found");
    return null;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) IOException(java.io.IOException)

Example 32 with User

use of io.fabric8.openshift.api.model.User 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 33 with User

use of io.fabric8.openshift.api.model.User in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method awsStaticCredentialsArePickedUpFromEnvironment.

@Test
public void awsStaticCredentialsArePickedUpFromEnvironment() throws MojoExecutionException {
    givenAwsSdkIsDisabled();
    String accessKeyId = randomUUID().toString();
    String secretAccessKey = randomUUID().toString();
    environmentVariables.set("AWS_ACCESS_KEY_ID", accessKeyId);
    environmentVariables.set("AWS_SECRET_ACCESS_KEY", secretAccessKey);
    AuthConfig authConfig = factory.createAuthConfig(false, true, null, settings, "user", ECR_NAME);
    verifyAuthConfig(authConfig, accessKeyId, secretAccessKey, null, null);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 34 with User

use of io.fabric8.openshift.api.model.User in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveUserHomeVolumePath.

/**
 * Resolving arbitrary user home paths, e.g. represented as {@code ~user}, is not supported.
 */
@Test(expected = IllegalArgumentException.class)
public void testResolveUserHomeVolumePath() {
    String volumeString = format(BIND_STRING_FMT, USER_HOME, CONTAINER_PATH);
    // '~user:/path/to/container/dir' to '/home/user:/path/to/container/dir'
    String relativizedVolumeString = resolveRelativeVolumeBinding(new File("ignored"), volumeString);
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) Test(org.junit.Test)

Example 35 with User

use of io.fabric8.openshift.api.model.User in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveUserVolumePath.

/**
 * Insures that a host volume binding string that contains a path relative to the user's home directory resolves to
 * the user's home directory and not the supplied base directory.
 */
@Test
public void testResolveUserVolumePath() {
    String volumeString = format(BIND_STRING_FMT, USER_PATH, CONTAINER_PATH);
    // '~/rel:/path/to/container/dir' to '/user/home/rel:/path/to/container/dir'
    String relativizedVolumeString = resolveRelativeVolumeBinding(new File("ignored"), volumeString);
    String expectedBindingString = format(BIND_STRING_FMT, new File(System.getProperty("user.home"), PathTestUtil.stripLeadingTilde(USER_PATH)), CONTAINER_PATH);
    assertEquals(expectedBindingString, relativizedVolumeString);
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 File (java.io.File)19 IOException (java.io.IOException)17 HashMap (java.util.HashMap)16 Git (org.eclipse.jgit.api.Git)12 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)10 Map (java.util.Map)10 LinkedList (java.util.LinkedList)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 ObjectId (org.eclipse.jgit.lib.ObjectId)7 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)6 ArrayList (java.util.ArrayList)6 PatchException (io.fabric8.patch.management.PatchException)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 URL (java.net.URL)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3