Search in sources :

Example 1 with Log

use of lombok.extern.java.Log in project bundlebee by yupiik.

the class HttpKubeClient method init.

@PostConstruct
private void init() {
    client = new DelegatingClient(doConfigure(HttpClient.newBuilder().executor(dontUseAtRuntime.executor().orElseGet(ForkJoinPool::commonPool))).build()) {

        @Override
        public <T> CompletableFuture<HttpResponse<T>> sendAsync(final HttpRequest request, final HttpResponse.BodyHandler<T> responseBodyHandler) {
            final OnKubeRequest kubeRequest = new OnKubeRequest(request);
            onKubeRequestEvent.fire(kubeRequest);
            if (kubeRequest.getUserResponse() != null) {
                return CompletableFuture.class.cast(kubeRequest.getUserResponse().toCompletableFuture());
            }
            if (kubeRequest.getUserRequest() != null) {
                return doSendAsync(kubeRequest.getUserRequest(), responseBodyHandler);
            }
            return doSendAsync(request, responseBodyHandler);
        }

        private <T> CompletableFuture<HttpResponse<T>> doSendAsync(final HttpRequest request, final HttpResponse.BodyHandler<T> responseBodyHandler) {
            return super.sendAsync(request, responseBodyHandler).whenCompleteAsync((r, t) -> {
            }, client.executor().orElseGet(ForkJoinPool::commonPool));
        }
    };
    if (dryRun) {
        client = new LoggingClient(log, new DryRunClient(client, skipDryRunForGet));
    } else if (verbose) {
        client = new LoggingClient(log, client);
    }
    if (loadedKubeConfig == null || loadedKubeConfig.getClusters() == null || loadedKubeConfig.getClusters().isEmpty()) {
        final var c = new KubeConfig.Cluster();
        c.setServer(baseApi);
        final var cluster = new KubeConfig.NamedCluster();
        cluster.setName("default");
        cluster.setCluster(c);
        loadedKubeConfig = new KubeConfig();
        loadedKubeConfig.setClusters(List.of(cluster));
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) CertificateFactory(java.security.cert.CertificateFactory) Optional.of(java.util.Optional.of) JsonbException(javax.json.bind.JsonbException) UNSET(io.yupiik.bundlebee.core.command.Executable.UNSET) TrustManager(javax.net.ssl.TrustManager) KeyStoreException(java.security.KeyStoreException) SecureRandom(java.security.SecureRandom) BundleBee(io.yupiik.bundlebee.core.qualifier.BundleBee) GeneralSecurityException(java.security.GeneralSecurityException) ByteArrayInputStream(java.io.ByteArrayInputStream) DryRunClient(io.yupiik.bundlebee.core.http.DryRunClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) BigInteger(java.math.BigInteger) URI(java.net.URI) LoggingClient(io.yupiik.bundlebee.core.http.LoggingClient) HttpResponse(java.net.http.HttpResponse) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) StandardCharsets(java.nio.charset.StandardCharsets) KeyFactory(java.security.KeyFactory) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) PrivateKey(java.security.PrivateKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PostConstruct(javax.annotation.PostConstruct) JsonException(javax.json.JsonException) Function.identity(java.util.function.Function.identity) Description(io.yupiik.bundlebee.core.configuration.Description) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Yaml2JsonConverter(io.yupiik.bundlebee.core.yaml.Yaml2JsonConverter) PRIVATE(lombok.AccessLevel.PRIVATE) Getter(lombok.Getter) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) HttpRequest(java.net.http.HttpRequest) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) UnrecoverableKeyException(java.security.UnrecoverableKeyException) Objects.requireNonNull(java.util.Objects.requireNonNull) HttpClient(java.net.http.HttpClient) Event(javax.enterprise.event.Event) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) ConfigHolder(io.yupiik.bundlebee.core.lang.ConfigHolder) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) Log(lombok.extern.java.Log) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) KeyManager(javax.net.ssl.KeyManager) OnKubeRequest(io.yupiik.bundlebee.core.event.OnKubeRequest) DelegatingClient(io.yupiik.bundlebee.core.http.DelegatingClient) StringReader(java.io.StringReader) Paths(java.nio.file.Paths) X509TrustManager(javax.net.ssl.X509TrustManager) ForkJoinPool(java.util.concurrent.ForkJoinPool) Data(lombok.Data) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) BufferedReader(java.io.BufferedReader) AllArgsConstructor(lombok.AllArgsConstructor) NoArgsConstructor(lombok.NoArgsConstructor) InputStream(java.io.InputStream) LoggingClient(io.yupiik.bundlebee.core.http.LoggingClient) OnKubeRequest(io.yupiik.bundlebee.core.event.OnKubeRequest) HttpResponse(java.net.http.HttpResponse) DelegatingClient(io.yupiik.bundlebee.core.http.DelegatingClient) CompletableFuture(java.util.concurrent.CompletableFuture) DryRunClient(io.yupiik.bundlebee.core.http.DryRunClient) UNSET(io.yupiik.bundlebee.core.command.Executable.UNSET) ForkJoinPool(java.util.concurrent.ForkJoinPool) PostConstruct(javax.annotation.PostConstruct)

Aggregations

UNSET (io.yupiik.bundlebee.core.command.Executable.UNSET)1 Description (io.yupiik.bundlebee.core.configuration.Description)1 OnKubeRequest (io.yupiik.bundlebee.core.event.OnKubeRequest)1 DelegatingClient (io.yupiik.bundlebee.core.http.DelegatingClient)1 DryRunClient (io.yupiik.bundlebee.core.http.DryRunClient)1 LoggingClient (io.yupiik.bundlebee.core.http.LoggingClient)1 ConfigHolder (io.yupiik.bundlebee.core.lang.ConfigHolder)1 BundleBee (io.yupiik.bundlebee.core.qualifier.BundleBee)1 Yaml2JsonConverter (io.yupiik.bundlebee.core.yaml.Yaml2JsonConverter)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 HttpClient (java.net.http.HttpClient)1 HttpRequest (java.net.http.HttpRequest)1 HttpResponse (java.net.http.HttpResponse)1 StandardCharsets (java.nio.charset.StandardCharsets)1