本文整理汇总了Java中com.spotify.docker.client.DockerCertificates类的典型用法代码示例。如果您正苦于以下问题:Java DockerCertificates类的具体用法?Java DockerCertificates怎么用?Java DockerCertificates使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DockerCertificates类属于com.spotify.docker.client包,在下文中一共展示了DockerCertificates类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupCerts
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
private static void setupCerts(PluginSettings pluginSettings, DefaultDockerClient.Builder builder) throws IOException, DockerCertificateException {
if (isBlank(pluginSettings.getDockerCACert()) || isBlank(pluginSettings.getDockerClientCert()) || isBlank(pluginSettings.getDockerClientKey())) {
LOG.warn("Missing docker certificates, will attempt to connect without certificates");
return;
}
Path certificateDir = Files.createTempDirectory(UUID.randomUUID().toString());
File tempDirectory = certificateDir.toFile();
try {
FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CA_CERT_NAME), pluginSettings.getDockerCACert(), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_CERT_NAME), pluginSettings.getDockerClientCert(), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_KEY_NAME), pluginSettings.getDockerClientKey(), StandardCharsets.UTF_8);
builder.dockerCertificates(new DockerCertificates(certificateDir));
} finally {
FileUtils.deleteDirectory(tempDirectory);
}
}
示例2: DockerWrapper
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
/**
* Constructor.
* @param dockerHost String. The docker host ex: https://something:2376
* @param certPath String. The certificate path
* @param feedBackLevel String. The logging level: q = ERROR, v = DEBUG, i = info (default)
* @throws DockerCertificateException
*/
public DockerWrapper(String dockerHost, String certPath, String feedBackLevel) throws DockerCertificateException {
this.dockerHost = dockerHost;
this.certPath = certPath;
this.docker = DefaultDockerClient.builder()
.uri(URI.create(this.dockerHost))
.dockerCertificates(new DockerCertificates(Paths.get(this.certPath)))
.build();
if (feedBackLevel.equalsIgnoreCase("q")) {
Logger.getRootLogger().setLevel(Level.ERROR);
logger.setLevel(Level.ERROR);
}
else if (feedBackLevel.equalsIgnoreCase("v")) {
Logger.getRootLogger().setLevel(Level.DEBUG);
logger.setLevel(Level.DEBUG);
}
}
示例3: createClient
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
private DefaultDockerClient createClient() {
DefaultDockerClient dockerClient;
Optional<DockerCertificates> certs = Optional.absent();
if (mccySettings.getDockerCertPath() != null) {
try {
certs = DockerCertificates.builder()
.dockerCertPath(Paths.get(mccySettings.getDockerCertPath())).build();
} catch (DockerCertificateException e) {
throw new IllegalArgumentException("Unable to initialize Docker certificates with given configuration");
}
}
final DefaultDockerClient.Builder clientBuilder = DefaultDockerClient.builder();
if (certs.isPresent()) {
clientBuilder
.dockerCertificates(certs.get());
}
dockerClient = clientBuilder
.uri(mccySettings.getDockerHostUri())
.build();
return dockerClient;
}
示例4: getDockerClient
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
public DockerClient getDockerClient() throws DockerCertificateException {
DockerClient client = null;
if (this.isUseDefault()) {
client = DefaultDockerClient.builder()
.uri(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT).build();
} else {
if (this.isUseUnixSocket()) {
client = DefaultDockerClient.builder().uri(getSocketPath())
.build();
} else if (isUseHTTPS()) {
if (isEnableAuth()) {
client = DefaultDockerClient
.builder()
.dockerCertificates(
new DockerCertificates(Paths
.get(getAuthPath())))
.uri(getHost()).build();
} else {
client = DefaultDockerClient.builder().uri(getHost())
.build();
}
}
}
return client;
}
示例5: DockerClientSpotify
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
public DockerClientSpotify() {
messageConsole = new DockerClientMessageConsole(Constants.CONSOLE_NAME);
dockerConfig = new DockerConfig();
final String endpoint = dockerConfig.getUri();
final String dockerCertPath = dockerConfig.getDockerCertPath();
final DefaultDockerClient.Builder builder = new DefaultDockerClient.Builder();
builder.uri(endpoint);
builder.readTimeoutMillis(DefaultDockerClient.NO_TIMEOUT);
if (dockerCertPath != null && !dockerCertPath.isEmpty()) {
try {
builder.dockerCertificates(new DockerCertificates(Paths
.get(dockerCertPath)));
} catch (DockerCertificateException e) {
messageConsole.getDockerConsoleOut().println(
"[ERROR] " + e.toString());
}
}
dockerClient = builder.build();
}
示例6: connect
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
@Override
public DockerHost connect() throws IOException {
try {
final DockerHost connected;
if(this.dockerHost.isEmpty() || this.certPath.isEmpty()) {
connected = new RtDockerHost(
DefaultDockerClient.fromEnv().build(),
this.dockerHost, this.certPath
);
} else {
connected = new RtDockerHost(
DefaultDockerClient
.builder()
.uri(this.dockerHost)
.dockerCertificates(
new DockerCertificates(Paths.get(this.certPath))
).build(),
this.dockerHost, this.certPath
);
}
return connected;
} catch (final DockerCertificateException ex) {
throw new IOException(
"DockerCertificateException when trying to connect", ex
);
}
}
示例7: createSettings
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
protected PluginSettings createSettings() throws IOException {
PluginSettings settings = new PluginSettings();
settings.setMaxDockerContainers(1);
settings.setDockerURI(builder.uri().toString());
if (settings.getDockerURI().startsWith("https://")) {
settings.setDockerCACert(FileUtils.readFileToString(Paths.get(getenv("DOCKER_CERT_PATH"), DockerCertificates.DEFAULT_CA_CERT_NAME).toFile(), StandardCharsets.UTF_8));
settings.setDockerClientCert(FileUtils.readFileToString(Paths.get(getenv("DOCKER_CERT_PATH"), DockerCertificates.DEFAULT_CLIENT_CERT_NAME).toFile(), StandardCharsets.UTF_8));
settings.setDockerClientKey(FileUtils.readFileToString(Paths.get(getenv("DOCKER_CERT_PATH"), DockerCertificates.DEFAULT_CLIENT_KEY_NAME).toFile(), StandardCharsets.UTF_8));
}
return settings;
}
示例8: getDockerClient
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
@Bean
public DockerClient getDockerClient() {
try {
return DefaultDockerClient.builder()
.dockerCertificates(DockerCertificates.builder().dockerCertPath(Paths.get(environment.getProperty("shiny.proxy.docker.cert-path", ""))).build().orNull())
.uri(environment.getProperty("shiny.proxy.docker.url"))
.build();
} catch (DockerCertificateException e) {
throw new ShinyProxyException("Failed to initialize docker client", e);
}
}
示例9: build
import com.spotify.docker.client.DockerCertificates; //导入依赖的package包/类
@Override
public DefaultDockerClient.Builder build(HttpsRestApiHost host) {
DefaultDockerClient.Builder builder = DefaultDockerClient.builder();
builder.uri(host.getUri());
try {
builder.dockerCertificates(new DockerCertificates(Paths.get(host.getCertPath())));
} catch(DockerCertificateException ex) {
throw new IllegalArgumentException("Certificates could not be resolved", ex);
}
return builder;
}