use of io.kubernetes.client.util.credentials.ClientCertificateAuthentication in project java by kubernetes-client.
the class ClientBuilder method build.
public ApiClient build() {
final ApiClient client = new ApiClient();
client.setHttpClient(client.getHttpClient().newBuilder().protocols(protocols).readTimeout(this.readTimeout).pingInterval(pingInterval).build());
if (basePath != null) {
if (basePath.endsWith("/")) {
basePath = basePath.substring(0, basePath.length() - 1);
}
client.setBasePath(basePath);
}
client.setVerifyingSsl(verifyingSsl);
if (authentication != null) {
if (StringUtils.isNotEmpty(keyStorePassphrase)) {
if (authentication instanceof KubeconfigAuthentication) {
if (((KubeconfigAuthentication) authentication).getDelegateAuthentication() instanceof ClientCertificateAuthentication) {
((ClientCertificateAuthentication) (((KubeconfigAuthentication) authentication).getDelegateAuthentication())).setPassphrase(keyStorePassphrase);
}
}
}
authentication.provide(client);
}
// TODO: Add a test to ensure that this works correctly...
if (caCertBytes != null) {
client.setSslCaCert(new ByteArrayInputStream(caCertBytes));
}
return client;
}
use of io.kubernetes.client.util.credentials.ClientCertificateAuthentication in project java by kubernetes-client.
the class ClientBuilder method fromCertificateSigningRequest.
/**
* Returns a new ApiClient instance reading from CertificateSigningRequest.
*
* <p>It will create a CertificateSigningRequest object to the cluster if it doesn't exist, and
* waits until the request is approved.
*
* @param bootstrapApiClient the bootstrap api client
* @param privateKey the private key
* @param csr the csr
* @return the api client
* @throws IOException the io exception
* @throws CSRNotApprovedException the csr not approved exception
* @throws ApiException the api exception
*/
public static ApiClient fromCertificateSigningRequest(ApiClient bootstrapApiClient, PrivateKey privateKey, V1CertificateSigningRequest csr) throws IOException, CSRNotApprovedException, ApiException {
byte[] certificateData = CSRUtils.createAndWaitUntilCertificateSigned(bootstrapApiClient, csr);
InputStream is = bootstrapApiClient.getSslCaCert();
is.reset();
ClientBuilder newBuilder = new ClientBuilder();
newBuilder.setAuthentication(new ClientCertificateAuthentication(certificateData, SSLUtils.dumpKey(privateKey)));
newBuilder.setBasePath(bootstrapApiClient.getBasePath());
newBuilder.setVerifyingSsl(bootstrapApiClient.isVerifyingSsl());
newBuilder.setCertificateAuthority(IOUtils.toByteArray(is));
return newBuilder.build();
}
Aggregations