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();
}
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();
}
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);
}
}
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);
}
}
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());
}
Aggregations