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