use of com.amazonaws.services.s3.AmazonS3Client in project nifi by apache.
the class MockAWSProcessor method createClient.
/**
* Create client using AWSCredentials
*
* @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
*/
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
getLogger().info("Creating client with awd credentials");
final AmazonS3Client s3 = new AmazonS3Client(credentials, config);
return s3;
}
use of com.amazonaws.services.s3.AmazonS3Client in project nifi by apache.
the class MockAWSProcessor method createClient.
/**
* Create client using credentials provider. This is the preferred way for creating clients
*/
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
getLogger().info("Creating client with credentials provider");
final AmazonS3Client s3 = new AmazonS3Client(credentialsProvider, config);
return s3;
}
use of com.amazonaws.services.s3.AmazonS3Client in project ORCID-Source by ORCID.
the class S3Utils method createBuckets.
// Create S3 buckets for a given prefix
public static void createBuckets(String bucketPrefix, String accessKey, String secretKey) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3 = new AmazonS3Client(credentials);
String api12JsonPrefix = bucketPrefix + "-api-1-2-json-";
String api12XMLPrefix = bucketPrefix + "-api-1-2-xml-";
String api20JsonPrefix = bucketPrefix + "-api-2-0-json-";
String api20XMLPrefix = bucketPrefix + "-api-2-0-xml-";
for (int i = 0; i <= 10; i++) {
char lastCharacter = (i == 10 ? 'x' : Character.forDigit(i, 10));
if (!s3.doesBucketExist(api12JsonPrefix + lastCharacter)) {
s3.createBucket((api12JsonPrefix + lastCharacter), Region.EU_Ireland);
}
if (!s3.doesBucketExist(api12XMLPrefix + lastCharacter)) {
s3.createBucket((api12XMLPrefix + lastCharacter), Region.EU_Ireland);
}
if (!s3.doesBucketExist(api20JsonPrefix + lastCharacter)) {
s3.createBucket((api20JsonPrefix + lastCharacter), Region.EU_Ireland);
}
if (!s3.doesBucketExist(api20XMLPrefix + lastCharacter)) {
s3.createBucket((api20XMLPrefix + lastCharacter), Region.EU_Ireland);
}
}
}
use of com.amazonaws.services.s3.AmazonS3Client in project Synapse-Stack-Builder by Sage-Bionetworks.
the class BuildStackMainTest method before.
@Before
public void before() throws IOException {
inputProps = TestHelper.createInputProperties("dev");
InputConfiguration config = TestHelper.createTestConfig("dev");
defaultProps = TestHelper.createDefaultProperties();
clientFactory = new MockAmazonClientFactory();
AmazonS3Client mockS3Client = clientFactory.createS3Client();
AmazonEC2Client mockEC2Client = clientFactory.createEC2Client();
AmazonSNSClient mockSNSnsClient = clientFactory.createSNSClient();
AmazonRDSClient mockRdsClient = clientFactory.createRDSClient();
// Write the default properties.
when(mockS3Client.getObject(any(GetObjectRequest.class), any(File.class))).thenAnswer(new Answer<ObjectMetadata>() {
public ObjectMetadata answer(InvocationOnMock invocation) throws Throwable {
// Write the property file
File file = (File) invocation.getArguments()[1];
FileWriter writer = new FileWriter(file);
try {
defaultProps.store(writer, "test generated");
} finally {
writer.close();
}
return new ObjectMetadata();
}
});
// Return a valid EC2 security group.
DescribeSecurityGroupsRequest dsgr = new DescribeSecurityGroupsRequest().withGroupNames(config.getElasticSecurityGroupName());
when(mockEC2Client.describeSecurityGroups(dsgr)).thenReturn(new DescribeSecurityGroupsResult().withSecurityGroups(new SecurityGroup().withGroupName(config.getElasticSecurityGroupName())));
// Return a valid topic
String topicArn = "some:arn";
when(mockSNSnsClient.createTopic(new CreateTopicRequest(config.getRDSAlertTopicName()))).thenReturn(new CreateTopicResult().withTopicArn(topicArn));
when(mockSNSnsClient.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicArn))).thenReturn(new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription()));
// return a valid group
when(mockRdsClient.describeDBParameterGroups(new DescribeDBParameterGroupsRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParameterGroupsResult().withDBParameterGroups(new DBParameterGroup().withDBParameterGroupName(config.getDatabaseParameterGroupName())));
when(mockRdsClient.describeDBParameters(new DescribeDBParametersRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParametersResult().withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_SLOW_QUERY_LOG)).withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_LONG_QUERY_TIME)));
}
use of com.amazonaws.services.s3.AmazonS3Client in project components by Talend.
the class S3Connection method createClient.
public static AmazonS3 createClient(S3DatastoreProperties properties) {
AWSCredentialsProviderChain credentials;
if (properties.specifyCredentials.getValue()) {
credentials = new AWSCredentialsProviderChain(new BasicAWSCredentialsProvider(properties.accessKey.getValue(), properties.secretKey.getValue()), new DefaultAWSCredentialsProviderChain(), new AnonymousAWSCredentialsProvider());
} else {
// do not be polluted by hidden accessKey/secretKey
credentials = new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain(), new AnonymousAWSCredentialsProvider());
}
AmazonS3 conn = new AmazonS3Client(credentials);
return conn;
}
Aggregations