Search in sources :

Example 31 with AuthConfig

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

the class JibBuildService method getRegistryCredentials.

static Credential getRegistryCredentials(RegistryService.RegistryConfig registryConfig, boolean isPush, ImageConfiguration imageConfiguration, Logger log) throws MojoExecutionException {
    String registry;
    if (isPush) {
        registry = EnvUtil.firstRegistryOf(new ImageName(imageConfiguration.getName()).getRegistry(), imageConfiguration.getRegistry(), registryConfig.getRegistry());
    } else {
        registry = EnvUtil.firstRegistryOf(new ImageName(getBaseImage(imageConfiguration)).getRegistry(), registryConfig.getRegistry());
    }
    if (registry == null || DEFAULT_DOCKER_REGISTRIES.contains(registry)) {
        // Let's assume docker is default registry.
        registry = DOCKER_LOGIN_DEFAULT_REGISTRY;
    }
    AuthConfigFactory authConfigFactory = registryConfig.getAuthConfigFactory();
    AuthConfig standardAuthConfig = authConfigFactory.createAuthConfig(isPush, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, registry);
    Credential credentials = null;
    if (standardAuthConfig != null) {
        credentials = Credential.from(standardAuthConfig.getUsername(), standardAuthConfig.getPassword());
    }
    return credentials;
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Credential(com.google.cloud.tools.jib.api.Credential) AuthConfigFactory(io.fabric8.maven.docker.util.AuthConfigFactory) AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Example 32 with AuthConfig

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

the class RegistryService method pushImages.

/**
 * Push a set of images to a registry
 *
 * @param imageConfigs images to push (but only if they have a build configuration)
 * @param retries how often to retry
 * @param registryConfig a global registry configuration
 * @param skipTag flag to skip pushing tagged images
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
public void pushImages(Collection<ImageConfiguration> imageConfigs, int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException {
    for (ImageConfiguration imageConfig : imageConfigs) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        String name = imageConfig.getName();
        if (buildConfig != null) {
            if (buildConfig.skipPush()) {
                log.info("%s : Skipped pushing", imageConfig.getDescription());
                continue;
            }
            String configuredRegistry = EnvUtil.firstRegistryOf(new ImageName(imageConfig.getName()).getRegistry(), imageConfig.getRegistry(), registryConfig.getRegistry());
            AuthConfig authConfig = createAuthConfig(true, new ImageName(name).getUser(), configuredRegistry, registryConfig);
            long start = System.currentTimeMillis();
            docker.pushImage(name, authConfig, configuredRegistry, retries);
            log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));
            if (!skipTag) {
                for (String tag : imageConfig.getBuildConfiguration().getTags()) {
                    if (tag != null) {
                        docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
                    }
                }
            }
        }
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 33 with AuthConfig

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

the class JibBuildServiceTest method mockAuthConfigFactory.

private void mockAuthConfigFactory(boolean isPush, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException {
    new Expectations() {

        {
            authConfigFactory.createAuthConfig(anyBoolean, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, anyString);
            result = new AuthConfig("testuser" + (isPush ? "push" : "pull"), "testpass", "foo@example.com", null, null);
        }
    };
}
Also used : Expectations(mockit.Expectations) AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Example 34 with AuthConfig

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

the class JibBuildServiceTest method testGetRegistryCredentialsForPull.

@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPull() throws MojoExecutionException {
    // Given
    ImageConfiguration imageConfiguration = getImageConfiguration();
    RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
    mockAuthConfigFactory(false, registryConfig);
    // When
    Credential credential = JibBuildService.getRegistryCredentials(registryConfig, false, imageConfiguration, logger);
    // Then
    assertNotNull(credential);
    assertEquals("testuserpull", credential.getUsername());
    assertEquals("testpass", credential.getPassword());
}
Also used : Credential(com.google.cloud.tools.jib.api.Credential) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 35 with AuthConfig

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

the class AuthConfigTest method mapConstructor.

@Test
public void mapConstructor() {
    AuthConfig config = new AuthConfig("roland", "#>secrets??", "roland@jolokia.org", null);
    check(config);
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) 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