use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.
the class ChainingAWSCredentialsProvider method getInstance.
/**
* Gets instance.
*
* @param credentialAccessKey the credential access key
* @param credentialSecretKey the credential secret key
* @param credentialPropertiesFile the credential properties file
* @param profilePath the profile path
* @param profileName the profile name
* @return the instance
*/
public static AWSCredentialsProvider getInstance(final String credentialAccessKey, final String credentialSecretKey, final Resource credentialPropertiesFile, final String profilePath, final String profileName) {
LOGGER.debug("Attempting to locate AWS credentials...");
final List<AWSCredentialsProvider> chain = new ArrayList<>();
chain.add(new InstanceProfileCredentialsProvider(false));
if (credentialPropertiesFile != null) {
try {
final File f = credentialPropertiesFile.getFile();
chain.add(new PropertiesFileCredentialsProvider(f.getCanonicalPath()));
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
if (StringUtils.isNotBlank(profilePath) && StringUtils.isNotBlank(profileName)) {
chain.add(new ProfileCredentialsProvider(profilePath, profileName));
}
chain.add(new SystemPropertiesCredentialsProvider());
chain.add(new EnvironmentVariableCredentialsProvider());
chain.add(new ClasspathPropertiesFileCredentialsProvider("awscredentials.properties"));
if (StringUtils.isNotBlank(credentialAccessKey) && StringUtils.isNotBlank(credentialSecretKey)) {
final BasicAWSCredentials credentials = new BasicAWSCredentials(credentialAccessKey, credentialSecretKey);
chain.add(new AWSStaticCredentialsProvider(credentials));
}
LOGGER.debug("AWS chained credential providers are configured as [{}]", chain);
return new ChainingAWSCredentialsProvider(chain);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.
the class AmazonDynamoDbClientFactory method createAmazonDynamoDb.
/**
* Create amazon dynamo db instance.
*
* @param dynamoDbProperties the dynamo db properties
* @return the amazon dynamo db
*/
@SneakyThrows
public AmazonDynamoDB createAmazonDynamoDb(final AbstractDynamoDbProperties dynamoDbProperties) {
if (dynamoDbProperties.isLocalInstance()) {
LOGGER.debug("Creating DynamoDb standard client with endpoint [{}] and region [{}]", dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
return AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).build();
}
final AWSCredentialsProvider provider = ChainingAWSCredentialsProvider.getInstance(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey(), dynamoDbProperties.getCredentialsPropertiesFile());
LOGGER.debug("Creating DynamoDb client configuration...");
final ClientConfiguration cfg = new ClientConfiguration();
cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
cfg.setUseGzip(dynamoDbProperties.isUseGzip());
cfg.setUseReaper(dynamoDbProperties.isUseReaper());
cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
LOGGER.debug("Creating DynamoDb client local address [{}]", dynamoDbProperties.getLocalAddress());
cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
}
LOGGER.debug("Creating DynamoDb client instance...");
final AmazonDynamoDBClient client = new AmazonDynamoDBClient(provider, cfg);
if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
LOGGER.debug("Setting DynamoDb client endpoint [{}]", dynamoDbProperties.getEndpoint());
client.setEndpoint(dynamoDbProperties.getEndpoint());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
LOGGER.debug("Setting DynamoDb client region [{}]", dynamoDbProperties.getRegion());
client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
LOGGER.debug("Setting DynamoDb client region override [{}]", dynamoDbProperties.getRegionOverride());
client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
}
if (dynamoDbProperties.getTimeOffset() != 0) {
client.setTimeOffset(dynamoDbProperties.getTimeOffset());
}
return client;
}
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 apex-malhar by apache.
the class KinesisTestProducer method createClient.
private void createClient() {
AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
client = new AmazonKinesisClient(credentials);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project apex-malhar by apache.
the class KinesisTestConsumer method createClient.
private void createClient() {
AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
client = new AmazonKinesisClient(credentials);
}
Aggregations