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!");
}
}
use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.
the class S3FileSystemProvider method createS3Client.
/**
* Creates an S3 client with the standard credential providers.
*/
@VisibleForTesting
protected AmazonS3 createS3Client(@Nonnull final URI uri, @Nonnull final Configuration conf) {
// Create list of credential providers
final List<AWSCredentialsProvider> credentials = new ArrayList<>();
getCustomCredentialsProvider(uri, conf).ifPresent(credentials::add);
getBasicCredentialsProvider(uri, conf).ifPresent(credentials::add);
credentials.add(InstanceProfileCredentialsProvider.getInstance());
// Create client
final AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(credentials);
chain.setReuseLastProvider(true);
return AmazonS3ClientBuilder.standard().withCredentials(chain).build();
}
use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.
the class S3FileSystemProviderTest method getCustomCredentialsProvider.
/**
* Verify creating a custom credentials provider.
*/
@Test
@SuppressWarnings("squid:S3655")
public void getCustomCredentialsProvider() {
// Test empty configuration
final S3FileSystemProvider provider = new S3FileSystemProvider();
Assert.assertFalse("Expected empty credentials", provider.getCustomCredentialsProvider(S3N, new Configuration(false)).isPresent());
// Test with custom credentials provider
final Configuration conf = new Configuration(false);
conf.setClass("fs.s3.customAWSCredentialsProvider", EnvironmentVariableCredentialsProvider.class, AWSCredentialsProvider.class);
final Optional<AWSCredentialsProvider> credentials = provider.getCustomCredentialsProvider(S3N, conf);
Assert.assertTrue("Expected custom credentials", credentials.isPresent());
Assert.assertTrue("Expected EnvironmentVariableCredentialsProvider", credentials.get() instanceof EnvironmentVariableCredentialsProvider);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project kylo by Teradata.
the class S3FileSystemProviderTest method getBasicCredentialsProvider.
/**
* Verify reading basic credentials.
*/
@Test
@SuppressWarnings("squid:S3655")
public void getBasicCredentialsProvider() {
// Test empty configuration
final S3FileSystemProvider provider = new S3FileSystemProvider();
Assert.assertFalse("Expected empty credentials", provider.getBasicCredentialsProvider(S3N, new Configuration(false)).isPresent());
// Test configuration credentials
final Configuration conf = new Configuration(false);
conf.set("fs.s3n.awsAccessKeyId", "S3N_ACCESS_KEY");
conf.set("fs.s3n.awsSecretAccessKey", "S3N_SECRET_KEY");
final Optional<AWSCredentialsProvider> credentialsProvider = provider.getBasicCredentialsProvider(S3N, conf);
Assert.assertTrue("Expected URI credentials", credentialsProvider.isPresent());
final AWSCredentials credentials = credentialsProvider.get().getCredentials();
Assert.assertEquals("S3N_ACCESS_KEY", credentials.getAWSAccessKeyId());
Assert.assertEquals("S3N_SECRET_KEY", credentials.getAWSSecretKey());
}
use of com.amazonaws.auth.AWSCredentialsProvider in project ignite by apache.
the class DiscoveryInTheCloud method awsExample2.
public static void awsExample2() {
// tag::aws2[]
TcpDiscoverySpi spi = new TcpDiscoverySpi();
AWSCredentialsProvider instanceProfileCreds = new InstanceProfileCredentialsProvider(false);
TcpDiscoveryS3IpFinder ipFinder = new TcpDiscoveryS3IpFinder();
ipFinder.setAwsCredentialsProvider(instanceProfileCreds);
ipFinder.setBucketName("yourBucketName");
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
// Start a node.
Ignition.start(cfg);
// end::aws2[]
}
Aggregations