Search in sources :

Example 1 with AuthConfigFactory

use of io.fabric8.maven.docker.util.AuthConfigFactory in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method containerSetup.

@Before
public void containerSetup() throws ComponentLookupException {
    final SecDispatcher secDispatcher = new MockSecDispatcher();
    new Expectations() {

        {
            container.lookup(SecDispatcher.ROLE, "maven");
            minTimes = 0;
            result = secDispatcher;
        }
    };
    factory = new AuthConfigFactory(container);
    factory.setLog(log);
    gsonBuilder = new GsonBuilder();
}
Also used : Expectations(mockit.Expectations) GsonBuilder(com.google.gson.GsonBuilder) SecDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher) AwsSdkAuthConfigFactory(io.fabric8.maven.docker.util.aws.AwsSdkAuthConfigFactory) Before(org.junit.Before)

Example 2 with AuthConfigFactory

use of io.fabric8.maven.docker.util.AuthConfigFactory in project docker-maven-plugin by fabric8io.

the class JibBuildServiceTest method testGetRegistryCredentialsForPush.

@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPush() throws MojoExecutionException {
    // Given
    ImageConfiguration imageConfiguration = getImageConfiguration();
    RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
    mockAuthConfigFactory(true, registryConfig);
    // When
    Credential credential = JibBuildService.getRegistryCredentials(registryConfig, true, imageConfiguration, logger);
    // Then
    assertNotNull(credential);
    assertEquals("testuserpush", 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 3 with AuthConfigFactory

use of io.fabric8.maven.docker.util.AuthConfigFactory 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 4 with AuthConfigFactory

use of io.fabric8.maven.docker.util.AuthConfigFactory in project docker-maven-plugin by fabric8io.

the class JibBuildServiceTest method testPushWithConfiguration.

@Test
public void testPushWithConfiguration(@Mocked JibServiceUtil jibServiceUtil) throws Exception {
    // Given
    File projectBaseDir = Files.createTempDirectory("test").toFile();
    setupServiceHubExpectations(projectBaseDir);
    final ImageConfiguration imageConfiguration = getImageConfiguration();
    final RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfigFactory(authConfigFactory).build();
    mockAuthConfigFactory(true, registryConfig);
    // When
    new JibBuildService(serviceHub, params, logger).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false);
    // Then
    // @formatter:off
    new Verifications() {

        {
            JibServiceUtil.jibPush(imageConfiguration, Credential.from("testuserpush", "testpass"), (File) any, logger);
            times = 1;
        }
    };
// @formatter:on
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Verifications(mockit.Verifications) File(java.io.File) Test(org.junit.Test)

Example 5 with AuthConfigFactory

use of io.fabric8.maven.docker.util.AuthConfigFactory 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)

Aggregations

Credential (com.google.cloud.tools.jib.api.Credential)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 Test (org.junit.Test)3 GsonBuilder (com.google.gson.GsonBuilder)1 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)1 AuthConfigFactory (io.fabric8.maven.docker.util.AuthConfigFactory)1 ImageName (io.fabric8.maven.docker.util.ImageName)1 AwsSdkAuthConfigFactory (io.fabric8.maven.docker.util.aws.AwsSdkAuthConfigFactory)1 File (java.io.File)1 Expectations (mockit.Expectations)1 Verifications (mockit.Verifications)1 Before (org.junit.Before)1 SecDispatcher (org.sonatype.plexus.components.sec.dispatcher.SecDispatcher)1