All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.amazon.kms.runtime.KmsRecorder Maven / Gradle / Ivy

package io.quarkus.amazon.kms.runtime;

import io.quarkus.amazon.common.runtime.AwsConfig;
import io.quarkus.amazon.common.runtime.NettyHttpClientConfig;
import io.quarkus.amazon.common.runtime.SdkConfig;
import io.quarkus.amazon.common.runtime.SyncHttpClientConfig;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.services.kms.KmsAsyncClient;
import software.amazon.awssdk.services.kms.KmsAsyncClientBuilder;
import software.amazon.awssdk.services.kms.KmsClient;
import software.amazon.awssdk.services.kms.KmsClientBuilder;

@Recorder
public class KmsRecorder {

    public RuntimeValue getSyncConfig(KmsConfig config) {
        return new RuntimeValue<>(config.syncClient);
    }

    public RuntimeValue getAsyncConfig(KmsConfig config) {
        return new RuntimeValue<>(config.asyncClient);
    }

    public RuntimeValue getAwsConfig(KmsConfig config) {
        return new RuntimeValue<>(config.aws);
    }

    public RuntimeValue getSdkConfig(KmsConfig config) {
        return new RuntimeValue<>(config.sdk);
    }

    public RuntimeValue createSyncBuilder(KmsConfig config, RuntimeValue transport) {
        KmsClientBuilder builder = KmsClient.builder();
        if (transport != null) {
            builder.httpClientBuilder(transport.getValue());
        }
        return new RuntimeValue<>(builder);
    }

    public RuntimeValue createAsyncBuilder(KmsConfig config,
            RuntimeValue transport) {

        KmsAsyncClientBuilder builder = KmsAsyncClient.builder();
        if (transport != null) {
            builder.httpClientBuilder(transport.getValue());
        }
        return new RuntimeValue<>(builder);
    }

    public RuntimeValue buildClient(RuntimeValue builder,
            BeanContainer beanContainer,
            ShutdownContext shutdown) {
        KmsClientProducer producer = beanContainer.instance(KmsClientProducer.class);
        producer.setSyncConfiguredBuilder((KmsClientBuilder) builder.getValue());
        shutdown.addShutdownTask(producer::destroy);
        return new RuntimeValue<>(producer.client());
    }

    public RuntimeValue buildAsyncClient(RuntimeValue builder,
            BeanContainer beanContainer,
            ShutdownContext shutdown) {
        KmsClientProducer producer = beanContainer.instance(KmsClientProducer.class);
        producer.setAsyncConfiguredBuilder((KmsAsyncClientBuilder) builder.getValue());
        shutdown.addShutdownTask(producer::destroy);
        return new RuntimeValue<>(producer.asyncClient());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy