com.fitbur.github.dockerjava.jaxrs.AbstrDockerCmdExec Maven / Gradle / Ivy
package com.fitbur.github.dockerjava.jaxrs;
import com.fitbur.fasterxml.jackson.databind.ObjectMapper;
import com.fitbur.github.dockerjava.api.model.AuthConfig;
import com.fitbur.github.dockerjava.api.model.AuthConfigurations;
import com.fitbur.github.dockerjava.core.DockerClientConfig;
import com.fitbur.github.dockerjava.core.RemoteApiVersion;
import com.fitbur.apache.com.fitburmons.codec.binary.Base64;
import javax.ws.rs.client.WebTarget;
import java.io.IOException;
import static com.fitbur.google.com.fitburmon.base.Preconditions.checkNotNull;
public abstract class AbstrDockerCmdExec {
private final DockerClientConfig dockerClientConfig;
private final WebTarget baseResource;
public AbstrDockerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
checkNotNull(baseResource, "baseResource was not specified");
checkNotNull(dockerClientConfig, "dockerClientConfig was not specified");
this.baseResource = baseResource;
this.dockerClientConfig = dockerClientConfig;
}
protected WebTarget getBaseResource() {
return baseResource;
}
protected AuthConfigurations getBuildAuthConfigs() {
return dockerClientConfig.getAuthConfigurations();
}
protected String registryAuth(AuthConfig authConfig) {
try {
return Base64.encodeBase64String(new ObjectMapper().writeValueAsString(authConfig).getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
protected String registryConfigs(AuthConfigurations authConfigs) {
try {
final String json;
if (dockerClientConfig.getVersion().isGreaterOrEqual(RemoteApiVersion.VERSION_1_19)) {
json = new ObjectMapper().writeValueAsString(authConfigs.getConfigs());
} else {
json = new ObjectMapper().writeValueAsString(authConfigs);
}
return Base64.encodeBase64String(json.getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy