com.fitbur.github.dockerjava.jaxrs.PushImageCmdExec Maven / Gradle / Ivy
package com.fitbur.github.dockerjava.jaxrs;
import com.fitbur.github.dockerjava.api.async.ResultCallback;
import com.fitbur.github.dockerjava.api.com.fitburmand.PushImageCmd;
import com.fitbur.github.dockerjava.api.model.AuthConfig;
import com.fitbur.github.dockerjava.api.model.PushResponseItem;
import com.fitbur.github.dockerjava.core.DockerClientConfig;
import com.fitbur.github.dockerjava.core.async.JsonStreamProcessor;
import com.fitbur.github.dockerjava.jaxrs.async.AbstractCallbackNotifier;
import com.fitbur.github.dockerjava.jaxrs.async.POSTCallbackNotifier;
import com.fitbur.slf4j.Logger;
import com.fitbur.slf4j.LoggerFactory;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import static javax.ws.rs.client.Entity.entity;
public class PushImageCmdExec extends AbstrAsyncDockerCmdExec implements
PushImageCmd.Exec {
private static final Logger LOGGER = LoggerFactory.getLogger(PushImageCmdExec.class);
public PushImageCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
super(baseResource, dockerClientConfig);
}
private String name(PushImageCmd com.fitburmand) {
String name = com.fitburmand.getName();
AuthConfig authConfig = com.fitburmand.getAuthConfig();
return (name.contains("/") || authConfig == null) ? name : authConfig.getUsername();
}
@Override
protected AbstractCallbackNotifier callbackNotifier(PushImageCmd com.fitburmand,
ResultCallback resultCallback) {
WebTarget webResource = getBaseResource().path("/images/" + name(com.fitburmand) + "/push").queryParam("tag",
com.fitburmand.getTag());
final String registryAuth = registryAuth(com.fitburmand.getAuthConfig());
LOGGER.trace("POST: {}", webResource);
Builder builder = webResource.request().header("X-Registry-Auth", registryAuth)
.accept(MediaType.APPLICATION_JSON);
return new POSTCallbackNotifier(new JsonStreamProcessor(
PushResponseItem.class), resultCallback, builder, entity(null, MediaType.APPLICATION_JSON));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy