Search in sources :

Example 1 with EC2ContainerCredentialsProviderWrapper

use of com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper in project crate by crate.

the class S3Service method buildCredentials.

// pkg private for tests
static AWSCredentialsProvider buildCredentials(Logger logger, S3ClientSettings clientSettings) {
    final AWSCredentials credentials = clientSettings.credentials;
    if (credentials == null) {
        logger.debug("Using instance profile credentials");
        var ec2ContainerCredentialsProviderWrapper = new EC2ContainerCredentialsProviderWrapper();
        try {
            // Check if credentials are available
            ec2ContainerCredentialsProviderWrapper.getCredentials();
            return ec2ContainerCredentialsProviderWrapper;
        } catch (SdkClientException e) {
            throw new InvalidArgumentException("Cannot find required credentials to create a repository of type s3. " + "Credentials must be provided either as repository options access_key and secret_key or AWS IAM roles.");
        }
    } else {
        logger.debug("Using basic key/secret credentials");
        return new AWSStaticCredentialsProvider(credentials);
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) InvalidArgumentException(io.crate.exceptions.InvalidArgumentException) SdkClientException(com.amazonaws.SdkClientException) AWSCredentials(com.amazonaws.auth.AWSCredentials) EC2ContainerCredentialsProviderWrapper(com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper)

Aggregations

SdkClientException (com.amazonaws.SdkClientException)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 EC2ContainerCredentialsProviderWrapper (com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper)1 InvalidArgumentException (io.crate.exceptions.InvalidArgumentException)1