Search in sources :

Example 16 with RegistryAuth

use of com.spotify.docker.client.messages.RegistryAuth in project docker-client by spotify.

the class PushPullIT method testPushHubPrivateImageWithAuth.

@Test
public void testPushHubPrivateImageWithAuth() throws Exception {
    // Push an image to a private repo on Docker Hub and check it succeeds
    final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
    final RegistryAuth registryAuth = RegistryAuth.builder().username(HUB_AUTH_USERNAME).password(HUB_AUTH_PASSWORD).build();
    final DockerClient client = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth)))).build();
    client.build(Paths.get(dockerDirectory), HUB_PRIVATE_IMAGE);
    client.push(HUB_PRIVATE_IMAGE);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 17 with RegistryAuth

use of com.spotify.docker.client.messages.RegistryAuth in project docker-client by spotify.

the class ConfigFileRegistryAuthSupplierTest method testAuthFor_Success.

@Test
public void testAuthFor_Success() throws Exception {
    final RegistryAuth auth = RegistryAuth.builder().username("abc123").build();
    when(reader.fromConfig(configFile.toPath(), "foo.example.net")).thenReturn(auth);
    assertThat(supplier.authFor("foo.example.net/bar:1.2.3"), is(equalTo(auth)));
}
Also used : RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 18 with RegistryAuth

use of com.spotify.docker.client.messages.RegistryAuth in project docker-client by spotify.

the class MultiRegistryAuthSupplierTest method testAuthFor.

@Test
public void testAuthFor() throws Exception {
    final String image1 = "foobar:latest";
    final RegistryAuth auth1 = RegistryAuth.builder().build();
    when(supplier1.authFor(image1)).thenReturn(auth1);
    assertThat(multiSupplier.authFor(image1), is(auth1));
    verify(supplier2, never()).authFor(image1);
    // test fallback
    final String image2 = "bizbat:1.2.3";
    final RegistryAuth auth2 = RegistryAuth.builder().email("foo@biz.com").build();
    when(supplier1.authFor(image2)).thenReturn(null);
    when(supplier2.authFor(image2)).thenReturn(auth2);
    assertThat(multiSupplier.authFor(image2), is(auth2));
}
Also used : RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 19 with RegistryAuth

use of com.spotify.docker.client.messages.RegistryAuth in project docker-client by spotify.

the class DefaultDockerClientTest method testMissingAuthParam.

@Test
public void testMissingAuthParam() throws Exception {
    requireDockerApiVersionLessThan("1.23", "https://github.com/docker/docker/issues/24093");
    final RegistryAuth badRegistryAuth = RegistryAuth.builder().username(AUTH_USERNAME).build();
    final int statusCode = sut.auth(badRegistryAuth);
    assertThat(statusCode, equalTo(500));
}
Also used : Endpoint(com.spotify.docker.client.messages.swarm.Endpoint) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 20 with RegistryAuth

use of com.spotify.docker.client.messages.RegistryAuth in project docker-client by spotify.

the class DockerConfigReaderTest method testFromDockerConfig_IncompleteConfig.

@Test
public void testFromDockerConfig_IncompleteConfig() throws Exception {
    final RegistryAuth registryAuth = reader.fromFirstConfig(getTestFilePath("dockerConfig/incompleteConfig.json"));
    final RegistryAuth expected = RegistryAuth.builder().email("dockerman@hub.com").serverAddress("https://different.docker.io/v1/").build();
    assertThat(registryAuth, is(expected));
}
Also used : RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Aggregations

RegistryAuth (com.spotify.docker.client.messages.RegistryAuth)28 Test (org.junit.Test)22 FixedRegistryAuthSupplier (com.spotify.docker.client.auth.FixedRegistryAuthSupplier)7 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 DockerClient (com.spotify.docker.client.DockerClient)4 Path (java.nio.file.Path)4 Endpoint (com.spotify.docker.client.messages.swarm.Endpoint)2 HashMap (java.util.HashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AccessToken (com.google.auth.oauth2.AccessToken)1 DockerException (com.spotify.docker.client.exceptions.DockerException)1 ProgressMessage (com.spotify.docker.client.messages.ProgressMessage)1 RegistryAuthV2 (com.spotify.docker.client.messages.RegistryAuthV2)1 RegistryConfigs (com.spotify.docker.client.messages.RegistryConfigs)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1