driven-adapter.kms-reactive.kms-config.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaffold-clean-architecture Show documentation
Show all versions of scaffold-clean-architecture Show documentation
Gradle plugin to create a clean application in Java that already works, It follows our best practices!
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}}
}