Search in sources :

Example 36 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project presto by prestodb.

the class GlueHiveMetastore method createAsyncGlueClient.

private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config, RequestMetricCollector metricsCollector) {
    ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections()).withMaxErrorRetry(config.getMaxGlueErrorRetries());
    AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard().withMetricsCollector(metricsCollector).withClientConfiguration(clientConfig);
    if (config.getGlueEndpointUrl().isPresent()) {
        checkArgument(config.getGlueRegion().isPresent(), "Glue region must be set when Glue endpoint URL is set");
        asyncGlueClientBuilder.setEndpointConfiguration(new EndpointConfiguration(config.getGlueEndpointUrl().get(), config.getGlueRegion().get()));
    } else if (config.getGlueRegion().isPresent()) {
        asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
    } else if (config.getPinGlueClientToCurrentRegion()) {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            asyncGlueClientBuilder.setRegion(currentRegion.getName());
        }
    }
    if (config.getAwsAccessKey().isPresent() && config.getAwsSecretKey().isPresent()) {
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.getAwsAccessKey().get(), config.getAwsSecretKey().get()));
        asyncGlueClientBuilder.setCredentials(credentialsProvider);
    } else if (config.getIamRole().isPresent()) {
        AWSCredentialsProvider credentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(config.getIamRole().get(), "roleSessionName").build();
        asyncGlueClientBuilder.setCredentials(credentialsProvider);
    }
    return asyncGlueClientBuilder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) Region(com.amazonaws.regions.Region) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 37 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project flink by apache.

the class AWSUtilTest method testGetCredentialsProvider.

@Test
public void testGetCredentialsProvider() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "WEB_IDENTITY_TOKEN");
    AWSCredentialsProvider credentialsProvider = AWSUtil.getCredentialsProvider(testConfig);
    assertTrue(credentialsProvider instanceof WebIdentityTokenCredentialsProvider);
}
Also used : WebIdentityTokenCredentialsProvider(com.amazonaws.auth.WebIdentityTokenCredentialsProvider) Properties(java.util.Properties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project flink by apache.

the class AWSUtilTest method testGetCredentialsProviderAuto.

@Test
public void testGetCredentialsProviderAuto() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "AUTO");
    AWSCredentialsProvider credentialsProvider = AWSUtil.getCredentialsProvider(testConfig);
    assertTrue(credentialsProvider instanceof DefaultAWSCredentialsProviderChain);
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) Properties(java.util.Properties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project flink by apache.

the class AWSUtilTest method testGetCredentialsProviderNamedProfile.

@Test
public void testGetCredentialsProviderNamedProfile() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "PROFILE");
    testConfig.setProperty(AWSConfigConstants.profileName(AWS_CREDENTIALS_PROVIDER), "foo");
    testConfig.setProperty(AWSConfigConstants.profilePath(AWS_CREDENTIALS_PROVIDER), "src/test/resources/profile");
    AWSCredentialsProvider credentialsProvider = AWSUtil.getCredentialsProvider(testConfig);
    assertTrue(credentialsProvider instanceof ProfileCredentialsProvider);
    AWSCredentials credentials = credentialsProvider.getCredentials();
    assertEquals("22222222222222222222", credentials.getAWSAccessKeyId());
    assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCY2222222222", credentials.getAWSSecretKey());
}
Also used : ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) Properties(java.util.Properties) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project flink by apache.

the class DynamoDBStreamsProxy method createKinesisClient.

/**
 * Creates an AmazonDynamoDBStreamsAdapterClient. Uses it as the internal client interacting
 * with the DynamoDB streams.
 *
 * @param configProps configuration properties
 * @return an AWS DynamoDB streams adapter client
 */
@Override
protected AmazonKinesis createKinesisClient(Properties configProps) {
    ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig();
    setAwsClientConfigProperties(awsClientConfig, configProps);
    AWSCredentialsProvider credentials = getCredentialsProvider(configProps);
    awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT, EnvironmentInformation.getVersion(), EnvironmentInformation.getRevisionInformation().commitId));
    AmazonDynamoDBStreamsAdapterClient adapterClient = new AmazonDynamoDBStreamsAdapterClient(credentials, awsClientConfig);
    if (configProps.containsKey(AWS_ENDPOINT)) {
        adapterClient.setEndpoint(configProps.getProperty(AWS_ENDPOINT));
    } else {
        adapterClient.setRegion(Region.getRegion(Regions.fromName(configProps.getProperty(AWS_REGION))));
    }
    return adapterClient;
}
Also used : AmazonDynamoDBStreamsAdapterClient(com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient) ClientConfigurationFactory(com.amazonaws.ClientConfigurationFactory) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)125 Test (org.junit.Test)75 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)26 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)20 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)19 AWSCredentials (com.amazonaws.auth.AWSCredentials)16 TestRunner (org.apache.nifi.util.TestRunner)15 ClientConfiguration (com.amazonaws.ClientConfiguration)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)12 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)8 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)7 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)7 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)7 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)7 ArrayList (java.util.ArrayList)7 Properties (java.util.Properties)7 Configuration (org.apache.hadoop.conf.Configuration)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7