Search in sources :

Example 1 with AwsBasicCredentials

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

the class ClientBuilderFactoryTest method testCheckConfigurationUsingConfig.

@Test
public void testCheckConfigurationUsingConfig() {
    when(awsOptions.getAwsRegion()).thenReturn(null);
    when(awsOptions.getAwsCredentialsProvider()).thenReturn(null);
    ClientConfiguration noRegion = ClientConfiguration.builder().build();
    assertThatThrownBy(() -> defaultFactory().checkConfiguration(noRegion, awsOptions)).hasMessage("No AWS region available");
    ClientConfiguration noCredentials = ClientConfiguration.builder().region(US_WEST_1).build();
    assertThatThrownBy(() -> defaultFactory().checkConfiguration(noCredentials, awsOptions)).hasMessage("No AWS credentials provider available");
    AwsBasicCredentials credentials = AwsBasicCredentials.create("key", "secret");
    ClientConfiguration valid = ClientConfiguration.builder().region(US_WEST_1).credentialsProvider(StaticCredentialsProvider.create(credentials)).build();
    // finally success
    defaultFactory().checkConfiguration(valid, awsOptions);
    // awsOptions may be null
    defaultFactory().checkConfiguration(valid, null);
}
Also used : AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Test(org.junit.Test)

Example 2 with AwsBasicCredentials

use of software.amazon.awssdk.auth.credentials.AwsBasicCredentials in project cas by apereo.

the class ChainingAWSCredentialsProviderTests method verifyInstance.

@Test
public void verifyInstance() throws Exception {
    val path = File.createTempFile("props", ".txt").getCanonicalPath();
    val p = (AwsCredentialsProviderChain) ChainingAWSCredentialsProvider.getInstance("accesskey", "secretKey", "profilePath", path);
    val credentials = p.resolveCredentials();
    assertNotNull(credentials);
    assertTrue(credentials instanceof AwsBasicCredentials);
    assertNotNull(ChainingAWSCredentialsProvider.getInstance());
}
Also used : lombok.val(lombok.val) AwsCredentialsProviderChain(software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Test(org.junit.jupiter.api.Test)

Example 3 with AwsBasicCredentials

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

the class KinesisIOReadTest method testBuildWithBasicCredentials.

@Test
public void testBuildWithBasicCredentials() {
    Region region = Region.US_EAST_1;
    AwsBasicCredentials credentials = AwsBasicCredentials.create(KEY, SECRET);
    StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(credentials);
    Read read = KinesisIO.read().withAWSClientsProvider(KEY, SECRET, region);
    assertThat(read.getClientConfiguration()).isEqualTo(ClientConfiguration.create(credentialsProvider, region, null));
}
Also used : Read(org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Region(software.amazon.awssdk.regions.Region) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Test(org.junit.Test)

Example 4 with AwsBasicCredentials

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

the class KinesisIOReadTest method testBuildWithBasicCredentialsAndCustomEndpoint.

@Test
public void testBuildWithBasicCredentialsAndCustomEndpoint() {
    String customEndpoint = "localhost:9999";
    Region region = Region.US_WEST_1;
    AwsBasicCredentials credentials = AwsBasicCredentials.create("key", "secret");
    StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(credentials);
    Read read = KinesisIO.read().withAWSClientsProvider(KEY, SECRET, region, customEndpoint);
    assertThat(read.getClientConfiguration()).isEqualTo(ClientConfiguration.create(credentialsProvider, region, URI.create(customEndpoint)));
}
Also used : Read(org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Region(software.amazon.awssdk.regions.Region) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Test(org.junit.Test)

Example 5 with AwsBasicCredentials

use of software.amazon.awssdk.auth.credentials.AwsBasicCredentials in project fluency by komamitsu.

the class AwsS3Sender method buildClient.

@VisibleForTesting
protected S3Client buildClient(S3ClientBuilder s3ClientBuilder) {
    if (config.getEndpoint() != null) {
        try {
            URI uri = new URI(config.getEndpoint());
            s3ClientBuilder.endpointOverride(uri);
        } catch (URISyntaxException e) {
            throw new NonRetryableException(String.format("Invalid endpoint. %s", config.getEndpoint()), e);
        }
    }
    if (config.getRegion() != null) {
        s3ClientBuilder.region(Region.of(config.getRegion()));
    }
    if (config.getAwsAccessKeyId() != null && config.getAwsSecretAccessKey() != null) {
        AwsBasicCredentials credentials = AwsBasicCredentials.create(config.getAwsAccessKeyId(), config.getAwsSecretAccessKey());
        s3ClientBuilder.credentialsProvider(StaticCredentialsProvider.create(credentials));
    }
    return s3ClientBuilder.build();
}
Also used : NonRetryableException(org.komamitsu.fluency.NonRetryableException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) VisibleForTesting(org.msgpack.core.annotations.VisibleForTesting)

Aggregations

AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)5 Test (org.junit.Test)3 Read (org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read)2 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)2 Region (software.amazon.awssdk.regions.Region)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 lombok.val (lombok.val)1 Test (org.junit.jupiter.api.Test)1 NonRetryableException (org.komamitsu.fluency.NonRetryableException)1 VisibleForTesting (org.msgpack.core.annotations.VisibleForTesting)1 AwsCredentialsProviderChain (software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain)1