Search in sources :

Example 1 with AwsCredentials

use of software.amazon.awssdk.auth.credentials.AwsCredentials in project flink by apache.

the class AWSGeneralUtilTest method testGetCredentialsProviderNamedProfile.

@Test
public void testGetCredentialsProviderNamedProfile() {
    Properties properties = TestUtil.properties(AWS_CREDENTIALS_PROVIDER, "PROFILE");
    properties.setProperty(AWSConfigConstants.profileName(AWS_CREDENTIALS_PROVIDER), "foo");
    properties.setProperty(AWSConfigConstants.profilePath(AWS_CREDENTIALS_PROVIDER), "src/test/resources/profile");
    AwsCredentialsProvider credentialsProvider = AWSGeneralUtil.getCredentialsProvider(properties);
    assertTrue(credentialsProvider instanceof ProfileCredentialsProvider);
    AwsCredentials credentials = credentialsProvider.resolveCredentials();
    assertEquals("22222222222222222222", credentials.accessKeyId());
    assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCY2222222222", credentials.secretAccessKey());
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) ProfileCredentialsProvider(software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with AwsCredentials

use of software.amazon.awssdk.auth.credentials.AwsCredentials in project flink by apache.

the class AWSGeneralUtilTest method testGetCredentialsProviderBasic.

@Test
public void testGetCredentialsProviderBasic() {
    Properties properties = TestUtil.properties(AWS_CREDENTIALS_PROVIDER, "BASIC");
    properties.setProperty(AWSConfigConstants.accessKeyId(AWS_CREDENTIALS_PROVIDER), "ak");
    properties.setProperty(AWSConfigConstants.secretKey(AWS_CREDENTIALS_PROVIDER), "sk");
    AwsCredentials credentials = AWSGeneralUtil.getCredentialsProvider(properties).resolveCredentials();
    assertEquals("ak", credentials.accessKeyId());
    assertEquals("sk", credentials.secretAccessKey());
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with AwsCredentials

use of software.amazon.awssdk.auth.credentials.AwsCredentials in project flink by apache.

the class AWSGeneralUtilTest method testGetCredentialsProviderProfile.

@Test
public void testGetCredentialsProviderProfile() {
    Properties properties = TestUtil.properties(AWS_CREDENTIALS_PROVIDER, "PROFILE");
    properties.put(AWSConfigConstants.profileName(AWS_CREDENTIALS_PROVIDER), "default");
    properties.put(AWSConfigConstants.profilePath(AWS_CREDENTIALS_PROVIDER), "src/test/resources/profile");
    AwsCredentialsProvider credentialsProvider = AWSGeneralUtil.getCredentialsProvider(properties);
    assertTrue(credentialsProvider instanceof ProfileCredentialsProvider);
    AwsCredentials credentials = credentialsProvider.resolveCredentials();
    assertEquals("11111111111111111111", credentials.accessKeyId());
    assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCY1111111111", credentials.secretAccessKey());
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) ProfileCredentialsProvider(software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with AwsCredentials

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

the class AwsSerializableUtilsTest method testAwsCredentialsProviderSerialization.

@Test
public void testAwsCredentialsProviderSerialization() {
    AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
    String awsCredentialsProviderSerialized = AwsSerializableUtils.serializeAwsCredentialsProvider(awsCredentialsProvider);
    AwsCredentialsProvider awsCredentialsProviderDeserialized = AwsSerializableUtils.deserializeAwsCredentialsProvider(awsCredentialsProviderSerialized);
    assertTrue(awsCredentialsProviderDeserialized instanceof StaticCredentialsProvider);
    AwsCredentials awsCredentials = awsCredentialsProviderDeserialized.resolveCredentials();
    assertEquals(ACCESS_KEY_ID, awsCredentials.accessKeyId());
    assertEquals(SECRET_ACCESS_KEY, awsCredentials.secretAccessKey());
}
Also used : StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Test(org.junit.Test)

Example 5 with AwsCredentials

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

the class KinesisIOIT method runWrite.

/**
 * Write test dataset into Kinesis stream.
 */
private void runWrite() {
    ITOptions options = env.options();
    AwsCredentials credentials = options.getAwsCredentialsProvider().resolveCredentials();
    writePipeline.apply("Generate Sequence", GenerateSequence.from(0).to(options.getNumberOfRows())).apply("Prepare TestRows", ParDo.of(new TestRow.DeterministicallyConstructTestRowFn())).apply("Prepare Kinesis input records", ParDo.of(new ConvertToBytes())).apply("Write to Kinesis", org.apache.beam.sdk.io.kinesis.KinesisIO.write().withStreamName(options.getKinesisStream()).withPartitioner(new RandomPartitioner()).withAWSClientsProvider(credentials.accessKeyId(), credentials.secretAccessKey(), Regions.fromName(options.getAwsRegion().id()), options.getEndpoint() != null ? options.getEndpoint().toString() : null, !options.getUseLocalstack()));
    writePipeline.run().waitUntilFinish();
}
Also used : AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials)

Aggregations

AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)6 Test (org.junit.Test)4 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)4 Properties (java.util.Properties)3 ProfileCredentialsProvider (software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider)2 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)1 Region (software.amazon.awssdk.regions.Region)1