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