Search in sources :

Example 66 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project kafka-connect-file-pulse by streamthoughts.

the class AmazonS3ClientUtils method newCredentialsProvider.

@VisibleForTesting
static AWSCredentialsProvider newCredentialsProvider(final AmazonS3ClientConfig config) {
    final String accessKeyId = config.getAwsAccessKeyId().value();
    final String secretKey = config.getAwsSecretAccessKey().value();
    final String sessionToken = config.getAwsSecretSessionToken().value();
    if (isNotBlank(accessKeyId) && isNotBlank(secretKey)) {
        AWSCredentials credentials;
        if (isNotBlank(sessionToken)) {
            LOG.info("Creating new credentials provider using the access key id, " + "the secret access key and the session token that were passed " + "through the connector's configuration");
            credentials = new BasicSessionCredentials(accessKeyId, secretKey, sessionToken);
        } else {
            LOG.info("Creating new credentials provider using the access key id and " + "the secret access key that were passed " + "through the connector's configuration");
            credentials = new BasicAWSCredentials(accessKeyId, secretKey);
        }
        return new AWSStaticCredentialsProvider(credentials);
    }
    LOG.info("Creating new credentials provider using the provider class that was passed " + "through the connector's configuration");
    return config.getAwsCredentialsProvider();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) VisibleForTesting(io.streamthoughts.kafka.connect.filepulse.annotation.VisibleForTesting)

Example 67 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project syndesis by syndesisio.

the class AWSSQSVerifierExtension method verifyConnectivity.

// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
    ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
    try {
        SqsConfiguration configuration = setProperties(new SqsConfiguration(), parameters);
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
        AmazonSQS client = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build();
        client.listQueues();
    } catch (SdkClientException e) {
        ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()).detail("aws_sqs_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()).detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
        builder.error(errorBuilder.build());
    } catch (Exception e) {
        builder.error(ResultErrorBuilder.withException(e).build());
    }
    return builder.build();
}
Also used : ResultBuilder(org.apache.camel.component.extension.verifier.ResultBuilder) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) SdkClientException(com.amazonaws.SdkClientException) SqsConfiguration(org.apache.camel.component.aws.sqs.SqsConfiguration) ResultErrorBuilder(org.apache.camel.component.extension.verifier.ResultErrorBuilder) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) SdkClientException(com.amazonaws.SdkClientException)

Example 68 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project syndesis by syndesisio.

the class AWSSNSMetaDataExtension method meta.

@Override
public Optional<MetaData> meta(Map<String, Object> parameters) {
    final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey");
    final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey");
    final String region = ConnectorOptions.extractOption(parameters, "region");
    AmazonSNSClientBuilder clientBuilder;
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
    clientBuilder = AmazonSNSClientBuilder.standard().withCredentials(credentialsProvider);
    clientBuilder = clientBuilder.withRegion(Regions.valueOf(region));
    AmazonSNS sqsClient = clientBuilder.build();
    try {
        ListTopicsResult result = sqsClient.listTopics();
        Set<String> setTopic = new HashSet<String>();
        if (result.getTopics() != null) {
            for (Topic entry : result.getTopics()) {
                setTopic.add(entry.getTopicArn());
            }
        }
        return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setTopic).build());
    } catch (Exception e) {
        throw new IllegalStateException("Get information about existing topics with has failed.", e);
    }
}
Also used : AmazonSNSClientBuilder(com.amazonaws.services.sns.AmazonSNSClientBuilder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AmazonSNS(com.amazonaws.services.sns.AmazonSNS) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) ListTopicsResult(com.amazonaws.services.sns.model.ListTopicsResult) Topic(com.amazonaws.services.sns.model.Topic) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) HashSet(java.util.HashSet)

Example 69 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project syndesis by syndesisio.

the class AWSSQSMetaDataExtension method meta.

@Override
public Optional<MetaData> meta(Map<String, Object> parameters) {
    final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey");
    final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey");
    final String region = ConnectorOptions.extractOption(parameters, "region");
    AmazonSQSClientBuilder clientBuilder;
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
    clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider);
    clientBuilder = clientBuilder.withRegion(Regions.valueOf(region));
    AmazonSQS sqsClient = clientBuilder.build();
    List<String> attributeNames = new ArrayList<String>();
    attributeNames.add("All");
    try {
        ListQueuesResult result = sqsClient.listQueues();
        Set<String> setQueue = new HashSet<String>();
        if (result.getQueueUrls() != null) {
            for (String entry : result.getQueueUrls()) {
                GetQueueAttributesRequest req = new GetQueueAttributesRequest();
                req.setQueueUrl(entry);
                req.setAttributeNames(attributeNames);
                GetQueueAttributesResult c = sqsClient.getQueueAttributes(req);
                setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name()));
            }
        }
        return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setQueue).build());
    } catch (Exception e) {
        throw new IllegalStateException("Get information about existing queues with has failed.", e);
    }
}
Also used : GetQueueAttributesRequest(com.amazonaws.services.sqs.model.GetQueueAttributesRequest) ListQueuesResult(com.amazonaws.services.sqs.model.ListQueuesResult) ArrayList(java.util.ArrayList) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) GetQueueAttributesResult(com.amazonaws.services.sqs.model.GetQueueAttributesResult) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonSQSClientBuilder(com.amazonaws.services.sqs.AmazonSQSClientBuilder) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) HashSet(java.util.HashSet)

Example 70 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project flink-mirror by flink-ci.

the class AWSUtilTest method testGetCredentialsProviderBasic.

@Test
public void testGetCredentialsProviderBasic() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "BASIC");
    testConfig.setProperty(AWSConfigConstants.accessKeyId(AWS_CREDENTIALS_PROVIDER), "ak");
    testConfig.setProperty(AWSConfigConstants.secretKey(AWS_CREDENTIALS_PROVIDER), "sk");
    AWSCredentials credentials = AWSUtil.getCredentialsProvider(testConfig).getCredentials();
    assertEquals("ak", credentials.getAWSAccessKeyId());
    assertEquals("sk", credentials.getAWSSecretKey());
}
Also used : Properties(java.util.Properties) AWSCredentials(com.amazonaws.auth.AWSCredentials) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)277 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)181 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)80 Test (org.junit.Test)57 ClientConfiguration (com.amazonaws.ClientConfiguration)53 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)49 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)33 AmazonS3 (com.amazonaws.services.s3.AmazonS3)30 AmazonClientException (com.amazonaws.AmazonClientException)29 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)26 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)15 HashMap (java.util.HashMap)15 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)14 IOException (java.io.IOException)14 AmazonServiceException (com.amazonaws.AmazonServiceException)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)13 Date (java.util.Date)13 SdkClientException (com.amazonaws.SdkClientException)11 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)11 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)11