use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project opentest by mcdcorp.
the class PutS3Object method run.
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
String sourceFilePath = this.readStringArgument("sourceFile");
File sourceFile = new File(sourceFilePath);
if (sourceFile.exists()) {
try {
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
s3Client.putObject(new PutObjectRequest(bucket, objectKey, sourceFile));
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to upload file \"%s\" to S3 bucket \"%s\"", sourceFilePath, bucket), ex);
}
} else {
throw new RuntimeException(String.format("Source file \"%s\" doesn't exist", sourceFilePath));
}
}
use of com.talend.shaded.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;
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project components by Talend.
the class S3Connection method createClient.
public static AmazonS3 createClient(S3OutputProperties properties) {
S3DatasetProperties data_set = properties.getDatasetProperties();
S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties();
com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials(data_store.accessKey.getValue(), data_store.secretKey.getValue());
Region region = RegionUtils.getRegion(data_set.region.getValue().getValue());
Boolean clientSideEnc = data_set.encryptDataInMotion.getValue();
AmazonS3 conn = null;
if (clientSideEnc != null && clientSideEnc) {
String kms_cmk = data_set.kmsForDataInMotion.getValue();
KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kms_cmk);
conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region));
} else {
AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials);
conn = new AmazonS3Client(basicCredentialsProvider);
}
conn.setRegion(region);
return conn;
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project herd by FINRAOS.
the class S3DaoTest method testGetAWSCredentialsProviderAssertStaticCredentialsSet.
@Test
public void testGetAWSCredentialsProviderAssertStaticCredentialsSet() {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
String s3AccessKey = "s3AccessKey";
String s3SecretKey = "s3SecretKey";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
s3FileTransferRequestParamsDto.setAwsAccessKeyId(s3AccessKey);
s3FileTransferRequestParamsDto.setAwsSecretKey(s3SecretKey);
when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {
@SuppressWarnings("unchecked")
@Override
public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
// Expect 2 providers: the static provider, and the default provider
assertEquals(2, credentialsProviders.size());
// Only verify the static value
assertEquals(StaticCredentialsProvider.class, credentialsProviders.get(0).getClass());
StaticCredentialsProvider staticCredentialsProvider = (StaticCredentialsProvider) credentialsProviders.get(0);
assertEquals(s3AccessKey, staticCredentialsProvider.getCredentials().getAWSAccessKeyId());
assertEquals(s3SecretKey, staticCredentialsProvider.getCredentials().getAWSSecretKey());
return new PutObjectResult();
}
});
s3Dao.createDirectory(s3FileTransferRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project herd by FINRAOS.
the class S3DaoTest method testGetAmazonS3AssertV4SigningAlwaysPresent.
@Test
public void testGetAmazonS3AssertV4SigningAlwaysPresent() {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
when(mockS3Operations.putObject(any(), any())).then(invocation -> {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration");
assertEquals(S3Dao.SIGNER_OVERRIDE_V4, clientConfiguration.getSignerOverride());
return new PutObjectResult();
});
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
Aggregations