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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations