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);
}
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()));
}
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"));
}
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));
}
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);
}
Aggregations