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

io.linguarobot.aws.cdk.maven.context.AwsClientProviderBuilder Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 0.0.8
Show newest version
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