use of org.eclipse.che.plugin.docker.client.dto.AuthConfig in project che by eclipse.
the class DockerConnectorTest method shouldThrowIOExceptionWhenBuildImageButNoSuccessMessageInResponse.
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Docker image build failed. Image id not found in build output.")
public void shouldThrowIOExceptionWhenBuildImageButNoSuccessMessageInResponse() throws IOException, InterruptedException {
AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
Map<String, AuthConfig> auth = new HashMap<>();
auth.put("auth", authConfig);
authConfigs.setConfigs(auth);
BuildImageParams getEventsParams = BuildImageParams.create(dockerfile).withAuthConfigs(authConfigs);
doReturn(new ByteArrayInputStream("c96d378b4911: Already exists".getBytes())).when(dockerResponse).getInputStream();
dockerConnector.buildImage(getEventsParams, progressMonitor);
verify(dockerResponse).getInputStream();
}
use of org.eclipse.che.plugin.docker.client.dto.AuthConfig in project che by eclipse.
the class UserSpecificDockerRegistryCredentialsProviderTest method shouldParseCredentialsFromUserPreferences.
@Test
public void shouldParseCredentialsFromUserPreferences() throws ServerException {
String base64encodedCredentials = "eyJyZWdpc3RyeS5jb206NTAwMCI6eyJ1c2VybmFtZSI6ImxvZ2luIiwicGFzc3dvcmQiOiJwYXNzIn19";
setCredentialsIntoPreferences(base64encodedCredentials);
String registry = "registry.com:5000";
AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class).withUsername("login").withPassword("pass");
AuthConfigs parsedAuthConfigs = dockerCredentials.getCredentials();
AuthConfig parsedAuthConfig = parsedAuthConfigs.getConfigs().get(registry);
assertNotNull(parsedAuthConfig);
assertEquals(parsedAuthConfig.getUsername(), authConfig.getUsername());
assertEquals(parsedAuthConfig.getPassword(), authConfig.getPassword());
}
use of org.eclipse.che.plugin.docker.client.dto.AuthConfig in project che by eclipse.
the class DockerRegistryAuthResolver method getXRegistryAuthHeaderValue.
/**
* Looks for auth credentials for specified registry and encode it in base64.
* First searches in the passed params and then in the configured credentials.
* If nothing found, empty encoded json will be returned.
*
* @param registry
* registry to which API call will be applied
* @param paramAuthConfigs
* credentials for provided registry
* @return base64 encoded X-Registry-Auth header value
*/
public String getXRegistryAuthHeaderValue(@Nullable String registry, @Nullable AuthConfigs paramAuthConfigs) {
String normalizedRegistry = DEFAULT_REGISTRY_SYNONYMS.contains(registry) ? DEFAULT_REGISTRY : registry;
AuthConfig authConfig = null;
if (paramAuthConfigs != null && paramAuthConfigs.getConfigs() != null) {
authConfig = normalizeDockerHubRegistryUrl(paramAuthConfigs.getConfigs()).get(normalizedRegistry);
}
if (authConfig == null) {
authConfig = normalizeDockerHubRegistryUrl(initialAuthConfig.getAuthConfigs().getConfigs()).get(normalizedRegistry);
}
if (authConfig == null) {
authConfig = dynamicAuthResolver.getXRegistryAuth(registry);
}
String authConfigJson;
if (authConfig == null) {
// empty auth config
authConfigJson = "{}";
} else {
authConfigJson = JsonHelper.toJson(authConfig);
}
return Base64.getEncoder().encodeToString(authConfigJson.getBytes());
}
use of org.eclipse.che.plugin.docker.client.dto.AuthConfig in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToBuildImageWithAdditionalQueryParameters.
@Test
public void shouldBeAbleToBuildImageWithAdditionalQueryParameters() throws IOException, InterruptedException {
AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
Map<String, AuthConfig> auth = new HashMap<>();
auth.put("auth", authConfig);
authConfigs.setConfigs(auth);
final String imageId = "37a7da3b7edc";
final String repository = "repo/name";
final String tag = "tag";
final boolean rm = true;
final boolean forcerm = true;
final long memory = 2147483648L;
final long memswap = 3221225472L;
final boolean pull = true;
final String dockerfile = "path/Dockerfile";
final boolean nocache = true;
final boolean q = true;
final String cpusetcpus = "4-5";
final long cpuperiod = 10000L;
final long cpuquota = 5000L;
final Map<String, String> buildargs = new HashMap<>();
buildargs.put("constraint:label.com!", "value");
BuildImageParams buildImageParams = BuildImageParams.create(this.dockerfile).withAuthConfigs(authConfigs).withRepository(repository).withTag(tag).withRemoveIntermediateContainers(rm).withForceRemoveIntermediateContainers(forcerm).withMemoryLimit(memory).withMemorySwapLimit(memswap).withDoForcePull(pull).withDockerfile(dockerfile).withNoCache(nocache).withQuiet(q).withCpusetCpus(cpusetcpus).withCpuPeriod(cpuperiod).withCpuQuota(cpuquota).withBuildArgs(buildargs);
doReturn(new ByteArrayInputStream(("{\"stream\":\"Successfully built " + imageId + "\"}").getBytes())).when(dockerResponse).getInputStream();
String returnedImageId = dockerConnector.buildImage(buildImageParams, progressMonitor);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_POST);
verify(dockerConnection).path("/build");
verify(dockerConnection).header("Content-Type", "application/x-compressed-tar");
verify(dockerConnection).header(eq("Content-Length"), anyInt());
verify(dockerConnection).entity(any(InputStream.class));
verify(dockerConnection).header(eq("X-Registry-Config"), any(byte[].class));
verify(dockerConnection).request();
verify(dockerResponse).getStatus();
verify(dockerResponse).getInputStream();
verify(dockerConnection).query(eq("rm"), eq(1));
verify(dockerConnection).query(eq("forcerm"), eq(1));
verify(dockerConnection).query(eq("memory"), eq(memory));
verify(dockerConnection).query(eq("memswap"), eq(memswap));
verify(dockerConnection).query(eq("pull"), eq(1));
verify(dockerConnection).query(eq("dockerfile"), eq(dockerfile));
verify(dockerConnection).query(eq("nocache"), eq(1));
verify(dockerConnection).query(eq("q"), eq(1));
verify(dockerConnection).query(eq("cpusetcpus"), eq(cpusetcpus));
verify(dockerConnection).query(eq("cpuperiod"), eq(cpuperiod));
verify(dockerConnection).query(eq("cpuquota"), eq(cpuquota));
verify(dockerConnection).query(eq("t"), eq(repository + ':' + tag));
verify(dockerConnection).query(eq("buildargs"), eq(URLEncoder.encode(GSON.toJson(buildargs), "UTF-8")));
assertEquals(returnedImageId, imageId);
}
use of org.eclipse.che.plugin.docker.client.dto.AuthConfig in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToBuildImage.
@Test
public void shouldBeAbleToBuildImage() throws IOException, InterruptedException {
AuthConfigs authConfigs = DtoFactory.newDto(AuthConfigs.class);
AuthConfig authConfig = DtoFactory.newDto(AuthConfig.class);
Map<String, AuthConfig> auth = new HashMap<>();
auth.put("auth", authConfig);
authConfigs.setConfigs(auth);
final String imageId = "37a7da3b7edc";
BuildImageParams buildImageParams = BuildImageParams.create(dockerfile).withAuthConfigs(authConfigs);
doReturn(new ByteArrayInputStream(("{\"stream\":\"Successfully built " + imageId + "\"}").getBytes())).when(dockerResponse).getInputStream();
String returnedImageId = dockerConnector.buildImage(buildImageParams, progressMonitor);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_POST);
verify(dockerConnection).path("/build");
verify(dockerConnection).header("Content-Type", "application/x-compressed-tar");
verify(dockerConnection).header(eq("Content-Length"), anyInt());
verify(dockerConnection).entity(any(InputStream.class));
verify(dockerConnection, never()).header(eq("remote"), anyString());
verify(dockerConnection).header(eq("X-Registry-Config"), any(byte[].class));
verify(dockerConnection).request();
verify(dockerResponse).getStatus();
verify(dockerResponse).getInputStream();
assertEquals(returnedImageId, imageId);
}
Aggregations