Search in sources :

Example 21 with AwsCredentialsProvider

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

the class BasicSnsClientProviderTest method testSerialization.

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

Example 22 with AwsCredentialsProvider

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

the class DefaultS3ClientBuilderFactoryTest method testSetCredentialsProvider.

@Test
public void testSetCredentialsProvider() {
    AwsCredentialsProvider credentialsProvider = mock(AwsCredentialsProvider.class);
    when(s3Options.getAwsCredentialsProvider()).thenReturn(credentialsProvider);
    DefaultS3ClientBuilderFactory.createBuilder(builder, s3Options);
    verify(builder).credentialsProvider(credentialsProvider);
    verifyNoMoreInteractions(builder);
}
Also used : AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 23 with AwsCredentialsProvider

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

the class AwsModuleTest method testAwsCredentialsProviderSerializationDeserialization.

@Test
public void testAwsCredentialsProviderSerializationDeserialization() throws Exception {
    AwsCredentialsProvider provider = DefaultCredentialsProvider.create();
    AwsCredentialsProvider deserializedProvider = serializeAndDeserialize(provider);
    assertEquals(provider.getClass(), deserializedProvider.getClass());
    provider = EnvironmentVariableCredentialsProvider.create();
    deserializedProvider = serializeAndDeserialize(provider);
    assertEquals(provider.getClass(), deserializedProvider.getClass());
    provider = SystemPropertyCredentialsProvider.create();
    deserializedProvider = serializeAndDeserialize(provider);
    assertEquals(provider.getClass(), deserializedProvider.getClass());
    provider = ProfileCredentialsProvider.create();
    deserializedProvider = serializeAndDeserialize(provider);
    assertEquals(provider.getClass(), deserializedProvider.getClass());
    provider = ContainerCredentialsProvider.builder().build();
    deserializedProvider = serializeAndDeserialize(provider);
    assertEquals(provider.getClass(), deserializedProvider.getClass());
}
Also used : AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 24 with AwsCredentialsProvider

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

the class AwsModuleTest method testStsAssumeRoleCredentialsProviderSerializationDeserialization.

@Test
public void testStsAssumeRoleCredentialsProviderSerializationDeserialization() throws Exception {
    AssumeRoleRequest req = AssumeRoleRequest.builder().roleArn("roleArn").policy("policy").build();
    Supplier<AwsCredentialsProvider> provider = () -> StsAssumeRoleCredentialsProvider.builder().stsClient(StsClient.create()).refreshRequest(req).build();
    Properties overrides = new Properties();
    overrides.setProperty(AWS_REGION.property(), Regions.US_EAST_1.getName());
    overrides.setProperty(AWS_ACCESS_KEY_ID.property(), "key");
    overrides.setProperty(AWS_SECRET_ACCESS_KEY.property(), "secret");
    // Region and credentials for STS client are resolved using default providers
    AwsCredentialsProvider deserializedProvider = withSystemPropertyOverrides(overrides, () -> serializeAndDeserialize(provider.get()));
    Supplier<AssumeRoleRequest> requestSupplier = (Supplier<AssumeRoleRequest>) readField(deserializedProvider, "assumeRoleRequestSupplier", true);
    assertThat(requestSupplier.get()).isEqualTo(req);
}
Also used : AssumeRoleRequest(software.amazon.awssdk.services.sts.model.AssumeRoleRequest) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) ThrowingSupplier(org.apache.beam.sdk.util.ThrowingSupplier) Supplier(java.util.function.Supplier) Properties(java.util.Properties) Test(org.junit.Test)

Example 25 with AwsCredentialsProvider

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

the class AwsSerializableUtilsTest method testFailOnAwsCredentialsProviderSerialization.

@Test(expected = IllegalArgumentException.class)
public void testFailOnAwsCredentialsProviderSerialization() {
    AwsCredentialsProvider awsCredentialsProvider = new UnknownAwsCredentialsProvider();
    AwsSerializableUtils.serializeAwsCredentialsProvider(awsCredentialsProvider);
}
Also used : AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

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