Search in sources :

Example 1 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs 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);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) InputStream(java.io.InputStream) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Matchers.anyString(org.mockito.Matchers.anyString) BuildImageParams(org.eclipse.che.plugin.docker.client.params.BuildImageParams) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs 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();
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Matchers.anyString(org.mockito.Matchers.anyString) BuildImageParams(org.eclipse.che.plugin.docker.client.params.BuildImageParams) Test(org.testng.annotations.Test)

Example 3 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs 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());
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) Test(org.testng.annotations.Test)

Example 4 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class UserSpecificDockerRegistryCredentialsProviderTest method shouldReturnNullIfDataFormatIsWrong.

@Test
public void shouldReturnNullIfDataFormatIsWrong() throws ServerException {
    String base64encodedCredentials = "eyJpbnZhbGlkIjoianNvbiJ9";
    setCredentialsIntoPreferences(base64encodedCredentials);
    AuthConfigs parsedAuthConfigs = dockerCredentials.getCredentials();
    assertNull(parsedAuthConfigs);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) Test(org.testng.annotations.Test)

Example 5 with AuthConfigs

use of org.eclipse.che.plugin.docker.client.dto.AuthConfigs in project che by eclipse.

the class UserSpecificDockerRegistryCredentialsProviderTest method shouldReturnNullIfDataFormatIsCorruptedInPreferences.

@Test
public void shouldReturnNullIfDataFormatIsCorruptedInPreferences() throws ServerException {
    String base64encodedCredentials = "sdJfpwJwkek59kafj239lFfkHjhek5l1";
    setCredentialsIntoPreferences(base64encodedCredentials);
    AuthConfigs parsedAuthConfigs = dockerCredentials.getCredentials();
    assertNull(parsedAuthConfigs);
}
Also used : AuthConfigs(org.eclipse.che.plugin.docker.client.dto.AuthConfigs) Test(org.testng.annotations.Test)

Aggregations

AuthConfigs (org.eclipse.che.plugin.docker.client.dto.AuthConfigs)9 Test (org.testng.annotations.Test)9 AuthConfig (org.eclipse.che.plugin.docker.client.dto.AuthConfig)6 HashMap (java.util.HashMap)5 BuildImageParams (org.eclipse.che.plugin.docker.client.params.BuildImageParams)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)3 URI (java.net.URI)3 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)3