Search in sources :

Example 1 with RegistryAuth

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

the class ContainerRegistryAuthSupplier method authForBuild.

@Override
public RegistryConfigs authForBuild() throws DockerException {
    final AccessToken accessToken;
    try {
        accessToken = getAccessToken();
    } catch (IOException e) {
        // do not fail as the GCR access token may not be necessary for building the image currently
        // being built
        log.warn("unable to get access token for Google Container Registry, " + "configuration for building image will not contain RegistryAuth for GCR", e);
        return RegistryConfigs.empty();
    }
    final Map<String, RegistryAuth> configs = new HashMap<>(GCR_REGISTRIES.size());
    for (String serverName : GCR_REGISTRIES) {
        configs.put(serverName, authForAccessToken(accessToken));
    }
    return RegistryConfigs.create(configs);
}
Also used : HashMap(java.util.HashMap) AccessToken(com.google.auth.oauth2.AccessToken) IOException(java.io.IOException) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth)

Example 2 with RegistryAuth

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

the class DefaultDockerClientTest method testBuildImageIdWithAuth.

@Test
public void testBuildImageIdWithAuth() throws Exception {
    final Path dockerDirectory = getResource("dockerDirectory");
    final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();
    final RegistryAuth registryAuth = RegistryAuth.builder().username(AUTH_USERNAME).password(AUTH_PASSWORD).build();
    final DockerClient sut2 = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap("", registryAuth)))).build();
    final String returnedImageId = sut2.build(dockerDirectory, "test", new ProgressHandler() {

        @Override
        public void progress(ProgressMessage message) throws DockerException {
            final String imageId = message.buildImageId();
            if (imageId != null) {
                imageIdFromMessage.set(imageId);
            }
        }
    });
    assertThat(returnedImageId, is(imageIdFromMessage.get()));
}
Also used : Path(java.nio.file.Path) DockerException(com.spotify.docker.client.exceptions.DockerException) ProgressMessage(com.spotify.docker.client.messages.ProgressMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 3 with RegistryAuth

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

the class DockerConfigReaderTest method testFromDockerConfig_AddressProtocol.

@Test
public void testFromDockerConfig_AddressProtocol() throws IOException {
    final Path path = getTestFilePath("dockerConfig/protocolMissing.json");
    // Server address matches exactly what's in the config file
    final RegistryAuth noProto = reader.fromConfig(path, "docker.example.com");
    assertThat(noProto.serverAddress(), equalTo("docker.example.com"));
    // Server address doesn't have a protocol but the entry in the config file does (https)
    final RegistryAuth httpsProto = reader.fromConfig(path, "repo.example.com");
    assertThat(httpsProto.serverAddress(), equalTo("https://repo.example.com"));
    // Server address doesn't have a protocol but the entry in the config file does (http)
    final RegistryAuth httpProto = reader.fromConfig(path, "local.example.com");
    assertThat(httpProto.serverAddress(), equalTo("http://local.example.com"));
}
Also used : Path(java.nio.file.Path) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 4 with RegistryAuth

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

the class DockerConfigReaderTest method testFromDockerConfig_IdentityToken.

@Test
public void testFromDockerConfig_IdentityToken() throws Exception {
    final RegistryAuth authConfig = reader.fromFirstConfig(getTestFilePath("dockerConfig/identityTokenConfig.json"));
    assertThat(authConfig, equalTo(IDENTITY_TOKEN_AUTH_CONFIG));
}
Also used : RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 5 with RegistryAuth

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

the class DockerConfigReaderTest method testFromDockerConfig_CredsStore.

@Test
public void testFromDockerConfig_CredsStore() throws Exception {
    assumeTrue("Need to have a credential store.", getAuthCredentialsExist());
    String domain1 = "https://test.fakedomain.com";
    String domain2 = "https://test.fakedomain2.com";
    String testAuth1 = "{\n" + "\t\"ServerURL\": \"" + domain1 + "\",\n" + "\t\"Username\": \"david\",\n" + "\t\"Secret\": \"passw0rd1\"\n" + "}";
    String testAuth2 = "{\n" + "\t\"ServerURL\": \"" + domain2 + "\",\n" + "\t\"Username\": \"carl\",\n" + "\t\"Secret\": \"myPassword\"\n" + "}";
    storeAuthCredential(testAuth1);
    storeAuthCredential(testAuth2);
    final Path path = getTestFilePath("dockerConfig/" + getCredsStoreFileName());
    final RegistryConfigs configs = reader.fromConfig(path);
    for (RegistryAuth authConfigs : configs.configs().values()) {
        if (domain1.equals(authConfigs.serverAddress())) {
            assertThat(authConfigs.username(), equalTo("david"));
            assertThat(authConfigs.password(), equalTo("passw0rd1"));
        } else if (domain2.equals(authConfigs.serverAddress())) {
            assertThat(authConfigs.username(), equalTo("carl"));
            assertThat(authConfigs.password(), equalTo("myPassword"));
        }
    }
    eraseAuthCredential(domain1);
    eraseAuthCredential(domain2);
}
Also used : Path(java.nio.file.Path) RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) 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