io.linguarobot.aws.cdk.maven.context.AwsClientProviderBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-cdk-maven-plugin Show documentation
Show all versions of aws-cdk-maven-plugin Show documentation
The AWS CDK Maven plugin produces and deploys CloudFormation templates based on the cloud infrastructure defined
by means of CDK. The goal of the project is to improve the experience of Java developers while working with
CDK by eliminating the need for installing Node.js and interacting with the CDK application by means of CDK
Toolkit.
package io.linguarobot.aws.cdk.maven.context;
import com.google.common.collect.ImmutableMap;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.core.SdkClient;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class AwsClientProviderBuilder {
private final Map, Function> factories;
public AwsClientProviderBuilder() {
this.factories = new HashMap<>();
}
public , C extends SdkClient> AwsClientProviderBuilder withClientFactory(Class clientType,
Function factory) {
factories.put(clientType, factory);
return this;
}
public AwsClientProvider build() {
Map, Function> clientFactories = ImmutableMap.copyOf(factories);
return new AwsClientProvider() {
@Override
public T getClient(Class clientType, String environment) {
Function clientFactory = clientFactories.get(clientType);
if (clientFactory == null) {
throw new IllegalArgumentException("There's no factory registered for " + clientType.getSimpleName() + " client");
}
return clientType.cast(clientFactory.apply(environment));
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy