Search in sources :

Example 16 with AwsCredentialsProvider

use of software.amazon.awssdk.auth.credentials.AwsCredentialsProvider in project beam by apache.

the class ClientBuilderFactoryTest method testValidate.

@Test
public void testValidate() {
    AwsCredentialsProvider mock = mock(AwsCredentialsProvider.class);
    when(awsOptions.getAwsCredentialsProvider()).thenReturn(mock);
    when(mock.resolveCredentials()).thenReturn(mock(AwsCredentials.class));
    // finally success
    validate(awsOptions, ClientConfiguration.builder().build());
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 17 with AwsCredentialsProvider

use of software.amazon.awssdk.auth.credentials.AwsCredentialsProvider in project beam by apache.

the class ClientBuilderFactoryTest method testCheckConfigurationUsingOptions.

@Test
public void testCheckConfigurationUsingOptions() {
    ClientConfiguration config = ClientConfiguration.builder().build();
    when(awsOptions.getAwsRegion()).thenReturn(null);
    assertThatThrownBy(() -> defaultFactory().checkConfiguration(config, awsOptions)).hasMessage("No AWS region available");
    when(awsOptions.getAwsRegion()).thenReturn(EU_WEST_2);
    when(awsOptions.getAwsCredentialsProvider()).thenReturn(null);
    assertThatThrownBy(() -> defaultFactory().checkConfiguration(config, awsOptions)).hasMessage("No AWS credentials provider available");
    AwsCredentialsProvider mock = mock(AwsCredentialsProvider.class);
    when(awsOptions.getAwsCredentialsProvider()).thenReturn(mock);
    when(mock.resolveCredentials()).thenReturn(mock(AwsCredentials.class));
    // finally success
    defaultFactory().checkConfiguration(config, awsOptions);
    when(mock.resolveCredentials()).thenThrow(new RuntimeException("Error resolving credentials"));
    assertThatThrownBy(() -> defaultFactory().checkConfiguration(config, awsOptions)).hasMessage("Error resolving credentials");
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 18 with AwsCredentialsProvider

use of software.amazon.awssdk.auth.credentials.AwsCredentialsProvider in project beam by apache.

the class DynamoDBIOReadTest method testBuildWithCredentialsProviderAndRegion.

@Test
public void testBuildWithCredentialsProviderAndRegion() {
    Region region = Region.US_EAST_1;
    AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.create();
    Read<Object> read = DynamoDBIO.read().withDynamoDbClientProvider(credentialsProvider, region.id());
    assertThat(read.getClientConfiguration()).isEqualTo(ClientConfiguration.create(credentialsProvider, region, null));
}
Also used : AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Region(software.amazon.awssdk.regions.Region) Test(org.junit.Test)

Example 19 with AwsCredentialsProvider

use of software.amazon.awssdk.auth.credentials.AwsCredentialsProvider in project beam by apache.

the class BasicSnsAsyncClientProviderTest method testSerialization.

@Test
public void testSerialization() {
    AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("ACCESS_KEY_ID", "SECRET_ACCESS_KEY"));
    BasicSnsAsyncClientProvider snsAsyncClientProvider = new BasicSnsAsyncClientProvider(awsCredentialsProvider, "us-east-1", null);
    byte[] serializedBytes = SerializableUtils.serializeToByteArray(snsAsyncClientProvider);
    BasicSnsAsyncClientProvider snsAsyncClientProviderDeserialized = (BasicSnsAsyncClientProvider) SerializableUtils.deserializeFromByteArray(serializedBytes, "Aws Credentials Provider");
    assertEquals(snsAsyncClientProvider, snsAsyncClientProviderDeserialized);
}
Also used : AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 20 with AwsCredentialsProvider

use of software.amazon.awssdk.auth.credentials.AwsCredentialsProvider in project ddf by codice.

the class MetacardS3StorageRoute method getS3Client.

private S3Client getS3Client() {
    Region region = Region.of(getS3Region());
    if (StringUtils.isNotBlank(s3AccessKey)) {
        AwsCredentials awsCredentials = AwsBasicCredentials.create(s3AccessKey, s3SecretKey);
        AwsCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(awsCredentials);
        return S3Client.builder().credentialsProvider(credentialsProvider).endpointOverride(URI.create(s3Endpoint)).region(region).build();
    }
    return S3Client.builder().endpointOverride(URI.create(s3Endpoint)).region(region).build();
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Region(software.amazon.awssdk.regions.Region)

Aggregations

AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)40 Test (org.junit.Test)39 Region (software.amazon.awssdk.regions.Region)14 Properties (java.util.Properties)8 URI (java.net.URI)6 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)6 GlueSchemaRegistryDeserializationFacade (com.amazonaws.services.schemaregistry.deserializers.GlueSchemaRegistryDeserializationFacade)4 HashMap (java.util.HashMap)2 Read (org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read)2 Read (org.apache.beam.sdk.io.aws2.sqs.SqsIO.Read)2 Write (org.apache.beam.sdk.io.aws2.sqs.SqsIO.Write)2 DefaultCredentialsProvider (software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider)2 ProfileCredentialsProvider (software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider)2 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)2 Supplier (java.util.function.Supplier)1 SerializableUtils.deserializeFromByteArray (org.apache.beam.sdk.util.SerializableUtils.deserializeFromByteArray)1 SerializableUtils.serializeToByteArray (org.apache.beam.sdk.util.SerializableUtils.serializeToByteArray)1 ThrowingSupplier (org.apache.beam.sdk.util.ThrowingSupplier)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)1