use of com.amazonaws.auth.AWSCredentialsProvider in project hippo by NHS-digital-website.
the class S3ConnectorServiceRegistrationModule method getAmazonS3.
private AmazonS3 getAmazonS3() {
AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider();
AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard().withCredentials(provider).withRegion(Regions.fromName(s3Region));
if (!s3Endpoint.isEmpty()) {
s3Builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Endpoint, s3Region));
}
return s3Builder.build();
}
use of com.amazonaws.auth.AWSCredentialsProvider in project kafka-connect-storage-cloud by confluentinc.
the class TestWithMockedS3 method newS3Client.
@Override
public AmazonS3 newS3Client(S3SinkConnectorConfig config) {
final AWSCredentialsProvider provider = new AWSCredentialsProvider() {
private final AnonymousAWSCredentials credentials = new AnonymousAWSCredentials();
@Override
public AWSCredentials getCredentials() {
return credentials;
}
@Override
public void refresh() {
}
};
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withAccelerateModeEnabled(config.getBoolean(S3SinkConnectorConfig.WAN_MODE_CONFIG)).withPathStyleAccessEnabled(true).withCredentials(provider);
builder = url == null ? builder.withRegion(config.getString(S3SinkConnectorConfig.REGION_CONFIG)) : builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, ""));
return builder.build();
}
use of com.amazonaws.auth.AWSCredentialsProvider in project herd by FINRAOS.
the class S3DaoTest method testGetAWSCredentialsProviderAssertStaticCredentialsIsNotSetWhenAccessKeyIsNull.
@Test
public void testGetAWSCredentialsProviderAssertStaticCredentialsIsNotSetWhenAccessKeyIsNull() {
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 = null;
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");
assertEquals(1, credentialsProviders.size());
assertEquals(DefaultAWSCredentialsProviderChain.class, credentialsProviders.get(0).getClass());
return new PutObjectResult();
}
});
s3Dao.createDirectory(s3FileTransferRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of com.amazonaws.auth.AWSCredentialsProvider in project halyard by spinnaker.
the class S3Validator method validate.
@Override
public void validate(ConfigProblemSetBuilder ps, S3PersistentStore n) {
if (!StringUtils.isEmpty(n.getEndpoint())) {
return;
}
try {
AWSCredentialsProvider credentialsProvider = AwsAccountValidator.getAwsCredentialsProvider(n.getAccessKeyId(), n.getSecretAccessKey());
S3Config s3Config = new S3Config();
S3Properties s3Properties = new S3Properties();
s3Properties.setBucket(n.getBucket());
s3Properties.setRootFolder(n.getRootFolder());
s3Properties.setRegion(n.getRegion());
AmazonS3 s3Client = s3Config.awsS3Client(credentialsProvider, s3Properties);
new S3Config().s3StorageService(s3Client, s3Properties);
} catch (Exception e) {
ps.addProblem(Problem.Severity.ERROR, "Failed to ensure the required bucket \"" + n.getBucket() + "\" exists: " + e.getMessage());
}
}
use of com.amazonaws.auth.AWSCredentialsProvider in project opencast by opencast.
the class AwsS3DistributionServiceImpl method activate.
@Override
public void activate(ComponentContext cc) {
// Get the configuration
if (cc != null) {
if (!Boolean.valueOf(getAWSConfigKey(cc, AWS_S3_DISTRIBUTION_ENABLE))) {
logger.info("AWS S3 distribution disabled");
return;
}
// AWS S3 bucket name
bucketName = getAWSConfigKey(cc, AWS_S3_BUCKET_CONFIG);
logger.info("AWS S3 bucket name is {}", bucketName);
// AWS region
String regionStr = getAWSConfigKey(cc, AWS_S3_REGION_CONFIG);
logger.info("AWS region is {}", regionStr);
opencastDistributionUrl = getAWSConfigKey(cc, AWS_S3_DISTRIBUTION_BASE_CONFIG);
if (!opencastDistributionUrl.endsWith("/")) {
opencastDistributionUrl = opencastDistributionUrl + "/";
}
logger.info("AWS distribution url is {}", opencastDistributionUrl);
// Explicit credentials are optional.
AWSCredentialsProvider provider = null;
Option<String> accessKeyIdOpt = OsgiUtil.getOptCfg(cc.getProperties(), AWS_S3_ACCESS_KEY_ID_CONFIG);
Option<String> accessKeySecretOpt = OsgiUtil.getOptCfg(cc.getProperties(), AWS_S3_SECRET_ACCESS_KEY_CONFIG);
// profile credentials
if (accessKeyIdOpt.isNone() && accessKeySecretOpt.isNone())
provider = new DefaultAWSCredentialsProviderChain();
else
provider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyIdOpt.get(), accessKeySecretOpt.get()));
// Create AWS client.
s3 = AmazonS3ClientBuilder.standard().withRegion(regionStr).withCredentials(provider).build();
s3TransferManager = new TransferManager(s3);
// Create AWS S3 bucket if not there yet
createAWSBucket();
distributionChannel = OsgiUtil.getComponentContextProperty(cc, CONFIG_KEY_STORE_TYPE);
logger.info("AwsS3DistributionService activated!");
}
}
Aggregations