use of com.amazonaws.auth.BasicSessionCredentials in project Gatekeeper by FINRAOS.
the class AwsSessionService method getRDSSession.
public AmazonRDSClient getRDSSession(AWSEnvironment environment) {
BasicSessionCredentials creds = credentialCache.getUnchecked(environment);
AmazonRDSClient rds = awsSessionFactory.createRdsSession(creds);
rds.setRegion(Region.getRegion(Regions.fromName(environment.getRegion())));
return rds;
}
use of com.amazonaws.auth.BasicSessionCredentials in project Gatekeeper by FINRAOS.
the class AwsSessionService method getEC2Session.
public AmazonEC2Client getEC2Session(AWSEnvironment environment) {
BasicSessionCredentials creds = credentialCache.getUnchecked(environment);
AmazonEC2Client ec2 = awsSessionFactory.createEC2Session(creds);
ec2.setRegion(Region.getRegion(Regions.fromName(environment.getRegion())));
return ec2;
}
use of com.amazonaws.auth.BasicSessionCredentials in project ice by Netflix.
the class AwsUtils method downloadFileIfChangedSince.
public static boolean downloadFileIfChangedSince(String bucketName, String bucketFileRegion, String bucketFilePrefix, File file, long milles, String accountId, String assumeRole, String externalId) {
AmazonS3Client s3Client = AwsUtils.s3Client;
try {
if (!StringUtils.isEmpty(accountId) && !StringUtils.isEmpty(assumeRole)) {
Credentials assumedCredentials = getAssumedCredentials(accountId, assumeRole, externalId);
s3Client = new AmazonS3Client(new BasicSessionCredentials(assumedCredentials.getAccessKeyId(), assumedCredentials.getSecretAccessKey(), assumedCredentials.getSessionToken()), clientConfig);
}
if (bucketFileRegion != null && !bucketFileRegion.isEmpty()) {
s3Client.setEndpoint("s3-" + bucketFileRegion + ".amazonaws.com");
}
ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, bucketFilePrefix + file.getName());
boolean download = !file.exists() || metadata.getLastModified().getTime() > milles;
if (download) {
return download(s3Client, bucketName, bucketFilePrefix + file.getName(), file);
} else
return download;
} finally {
if (s3Client != AwsUtils.s3Client)
s3Client.shutdown();
}
}
use of com.amazonaws.auth.BasicSessionCredentials in project ice by Netflix.
the class AwsUtils method listAllObjects.
/**
* List all object summary with given prefix in the s3 bucket.
* @param bucket
* @param prefix
* @return
*/
public static List<S3ObjectSummary> listAllObjects(String bucket, String prefix, String accountId, String assumeRole, String externalId) {
AmazonS3Client s3Client = AwsUtils.s3Client;
try {
ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix);
List<S3ObjectSummary> result = Lists.newLinkedList();
if (!StringUtils.isEmpty(accountId) && !StringUtils.isEmpty(assumeRole)) {
Credentials assumedCredentials = getAssumedCredentials(accountId, assumeRole, externalId);
s3Client = new AmazonS3Client(new BasicSessionCredentials(assumedCredentials.getAccessKeyId(), assumedCredentials.getSecretAccessKey(), assumedCredentials.getSessionToken()), clientConfig);
}
ObjectListing page = null;
do {
if (page != null)
request.setMarker(page.getNextMarker());
page = s3Client.listObjects(request);
result.addAll(page.getObjectSummaries());
} while (page.isTruncated());
return result;
} finally {
if (s3Client != AwsUtils.s3Client)
s3Client.shutdown();
}
}
use of com.amazonaws.auth.BasicSessionCredentials in project crate by crate.
the class Ec2ClientSettings method loadCredentials.
static AWSCredentials loadCredentials(Settings settings) {
try (SecureString key = ACCESS_KEY_SETTING.get(settings);
SecureString secret = SECRET_KEY_SETTING.get(settings);
SecureString sessionToken = SESSION_TOKEN_SETTING.get(settings)) {
if (key.length() == 0 && secret.length() == 0) {
if (sessionToken.length() > 0) {
throw new SettingsException("Setting [{}] is set but [{}] and [{}] are not", SESSION_TOKEN_SETTING.getKey(), ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
}
LOGGER.debug("Using either environment variables, system properties or instance profile credentials");
return null;
} else {
if (key.length() == 0) {
DEPRECATION_LOGGER.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", SECRET_KEY_SETTING.getKey(), ACCESS_KEY_SETTING.getKey());
}
if (secret.length() == 0) {
DEPRECATION_LOGGER.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
}
final AWSCredentials credentials;
if (sessionToken.length() == 0) {
LOGGER.debug("Using basic key/secret credentials");
credentials = new BasicAWSCredentials(key.toString(), secret.toString());
} else {
LOGGER.debug("Using basic session credentials");
credentials = new BasicSessionCredentials(key.toString(), secret.toString(), sessionToken.toString());
}
return credentials;
}
}
}
Aggregations