use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.
the class ContainerRegistryAuthSupplierTest method testAuthForBuild_ExceptionOnRefresh.
@Test
public void testAuthForBuild_ExceptionOnRefresh() throws Exception {
when(clock.currentTimeMillis()).thenReturn(expiration.minusSeconds(minimumExpirationSecs - 1).getMillis());
doThrow(new IOException("failure!!")).when(refresher).refresh(credentials);
final RegistryConfigs configs = supplier.authForBuild();
assertThat(configs.configs().values(), is(empty()));
}
use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.
the class DefaultDockerClient method build.
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
@Override
public String build(final Path directory, final String name, final String dockerfile, final ProgressHandler handler, final BuildParam... params) throws DockerException, InterruptedException, IOException {
checkNotNull(handler, "handler");
WebTarget resource = noTimeoutResource().path("build");
for (final BuildParam param : params) {
resource = resource.queryParam(param.name(), param.value());
}
if (name != null) {
resource = resource.queryParam("t", name);
}
if (dockerfile != null) {
resource = resource.queryParam("dockerfile", dockerfile);
}
// Convert auth to X-Registry-Config format
final RegistryConfigs registryConfigs = registryAuthSupplier.authForBuild();
try (final CompressedDirectory compressedDirectory = CompressedDirectory.create(directory);
final InputStream fileStream = Files.newInputStream(compressedDirectory.file());
final ProgressStream build = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Config", authRegistryHeader(registryConfigs)), Entity.entity(fileStream, "application/tar"))) {
String imageId = null;
while (build.hasNextMessage(POST, resource.getUri())) {
final ProgressMessage message = build.nextMessage(POST, resource.getUri());
final String id = message.buildImageId();
if (id != null) {
imageId = id;
}
handler.progress(message);
}
return imageId;
}
}
use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.
the class ContainerRegistryAuthSupplierTest method testAuthForBuild_RefreshNeeded.
@Test
public void testAuthForBuild_RefreshNeeded() throws Exception {
when(clock.currentTimeMillis()).thenReturn(expiration.minusSeconds(minimumExpirationSecs - 1).getMillis());
final RegistryConfigs configs = supplier.authForBuild();
assertThat(configs.configs().values(), is(not(empty())));
assertThat(configs.configs().values(), everyItem(matchesAccessToken(accessToken)));
verify(refresher).refresh(credentials);
}
use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.
the class DefaultDockerClientUnitTest method testBuildPassesMultipleRegistryConfigs.
@Test
public void testBuildPassesMultipleRegistryConfigs() throws Exception {
final RegistryConfigs registryConfigs = RegistryConfigs.create(ImmutableMap.of("server1", RegistryAuth.builder().serverAddress("server1").username("u1").password("p1").email("e1").build(), "server2", RegistryAuth.builder().serverAddress("server2").username("u2").password("p2").email("e2").build()));
final RegistryAuthSupplier authSupplier = mock(RegistryAuthSupplier.class);
when(authSupplier.authForBuild()).thenReturn(registryConfigs);
final DefaultDockerClient client = builder.registryAuthSupplier(authSupplier).build();
// build() calls /version to check what format of header to send
enqueueServerApiVersion("1.20");
// TODO (mbrown): what to return for build response?
server.enqueue(new MockResponse().setResponseCode(200));
final Path path = Paths.get(Resources.getResource("dockerDirectory").toURI());
client.build(path);
final RecordedRequest versionRequest = takeRequestImmediately();
assertThat(versionRequest.getMethod(), is("GET"));
assertThat(versionRequest.getPath(), is("/version"));
final RecordedRequest buildRequest = takeRequestImmediately();
assertThat(buildRequest.getMethod(), is("POST"));
assertThat(buildRequest.getPath(), is("/build"));
final String registryConfigHeader = buildRequest.getHeader("X-Registry-Config");
assertThat(registryConfigHeader, is(not(nullValue())));
// check that the JSON in the header is equivalent to what we mocked out above from
// the registryAuthSupplier
final JsonNode headerJsonNode = toJson(BaseEncoding.base64().decode(registryConfigHeader));
assertThat(headerJsonNode, is(toJson(registryConfigs.configs())));
}
use of com.spotify.docker.client.messages.RegistryConfigs in project docker-client by spotify.
the class MultiRegistryAuthSupplierTest method testAuthForBuild_ReturnsNull.
/**
* Test what happens if one of the Suppliers returns null for authForBuild().
*/
@Test
public void testAuthForBuild_ReturnsNull() throws Exception {
when(supplier1.authForBuild()).thenReturn(null);
final RegistryConfigs registryConfigs = RegistryConfigs.create(ImmutableMap.of("a", RegistryAuth.builder().username("1").serverAddress("a").build(), "b", RegistryAuth.builder().username("2").serverAddress("b").build()));
when(supplier2.authForBuild()).thenReturn(registryConfigs);
assertThat(multiSupplier.authForBuild(), is(registryConfigs));
}
Aggregations