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

driven-adapter.kms-reactive.kms-config.mustache Maven / Gradle / Ivy

Go to download

Gradle plugin to create a clean application in Java that already works, It follows our best practices!

There is a newer version: 3.17.22
Show newest version
package {{package}}.kms.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
{{#metrics}}
import software.amazon.awssdk.metrics.MetricPublisher;
{{/metrics}}
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.kms.KmsAsyncClient;
import software.amazon.awssdk.services.kms.KmsAsyncClientBuilder;
import {{package}}.kms.config.model.KmsConnectionProperties;

import java.net.URI;

@Configuration
public class KmsConfig {

    {{#metrics}}
    @Profile({"dev", "cer", "pdn"})
    @Bean
    public KmsAsyncClient kmsAsyncClient(KmsConnectionProperties kmsProperties, MetricPublisher publisher) {
        return getBuilder(kmsProperties, publisher).build();
    }

    @Profile("local")
    @Bean
    public KmsAsyncClient localKmsAsyncClient(KmsConnectionProperties kmsProperties, MetricPublisher publisher) {
        return getBuilder(kmsProperties, publisher)
                .endpointOverride(URI.create(kmsProperties.getEndpoint()))
                .build();
    }

    private KmsAsyncClientBuilder getBuilder(KmsConnectionProperties kmsProperties, MetricPublisher publisher) {
        return KmsAsyncClient.builder()
                .overrideConfiguration(o -> o.addMetricPublisher(publisher))
                .region(Region.of(kmsProperties.getRegion()));
    }
    {{/metrics}}
    {{^metrics}}
    @Profile({"dev", "cer", "pdn"})
    @Bean
    public KmsAsyncClient kmsAsyncClient(KmsConnectionProperties kmsProperties) {
        return getBuilder(kmsProperties).build();
    }

    @Profile("local")
    @Bean
    public KmsAsyncClient localKmsAsyncClient(KmsConnectionProperties kmsProperties) {
        return getBuilder(kmsProperties)
                .endpointOverride(URI.create(kmsProperties.getEndpoint()))
                .build();
    }

    private KmsAsyncClientBuilder getBuilder(KmsConnectionProperties kmsProperties) {
        return KmsAsyncClient.builder().region(Region.of(kmsProperties.getRegion()));
    }
    {{/metrics}}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy