use of com.amazonaws.services.s3.AmazonS3 in project bayou by capergroup.
the class S3LoggerBase method putToS3.
/**
* Performs an S3 Put Object operation storing the UTF-8 bytes of logMsg under the given key
* using construction provided AWS credentials.
*
* @param objectKey the S3 object key. may not be null or whitespace only.
* @param logMsg the message to store
* @throws IllegalArgumentException if objectKey is whitespace only.
*/
void putToS3(String objectKey, String logMsg) {
if (objectKey == null)
throw new NullPointerException("objectKey");
if (objectKey.trim().length() == 0)
throw new IllegalArgumentException("objectKey may not be only whitespace.");
/*
* Make the client used to send the log msg to S3.
*/
AmazonS3 client;
{
Regions regions = Regions.US_EAST_1;
if (_credentials == null) {
client = // get creds from environment
AmazonS3ClientBuilder.standard().withRegion(regions).build();
} else {
client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(_credentials)).withRegion(regions).build();
}
}
/*
* Store the log msg in S3.
*/
byte[] logMsgBytes = logMsg.getBytes(StandardCharsets.UTF_8);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(logMsgBytes.length);
client.putObject(_bucketName, objectKey, new ByteArrayInputStream(logMsgBytes), metadata);
_logger.debug("exiting");
}
use of com.amazonaws.services.s3.AmazonS3 in project athenz by yahoo.
the class S3ChangeLogStore method getUpdatedSignedDomains.
@Override
public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("getUpdatedSignedDomains: Retrieving updating signed domains from S3...");
}
// We need save the timestamp at the beginning just in case we end up getting
// paged results and while processing the last page, S3 gets pushed
// updated domains from the earlier pages
lastModTimeBuffer.append(System.currentTimeMillis());
// AWS S3 API does not provide support for listing objects filtered
// based on its last modification timestamp so we need to get
// the full list and filter ourselves
// instead of using our fetched s3 client, we're going to
// obtain a new one to get the changes
AmazonS3 s3 = getS3Client();
ArrayList<String> domains = new ArrayList<>();
listObjects(s3, domains, lastModTime);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("getUpdatedSignedDomains: {} updated domains", domains.size());
}
ArrayList<SignedDomain> signedDomainList = new ArrayList<>();
SignedDomain signedDomain = null;
for (String domain : domains) {
signedDomain = getSignedDomain(s3, domain);
if (signedDomain != null) {
signedDomainList.add(signedDomain);
}
}
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(signedDomainList);
return signedDomains;
}
use of com.amazonaws.services.s3.AmazonS3 in project athenz by yahoo.
the class AwsPrivateKeyStoreTest method testAwsPrivateKeyStore.
@Test
public void testAwsPrivateKeyStore() throws Exception {
String bucketName = "my_bucket";
String keyName = "my_key";
String expected = "my_value";
AmazonS3 s3 = Mockito.mock(AmazonS3.class);
AWSKMS kms = Mockito.mock(AWSKMS.class);
S3Object s3Object = Mockito.mock(S3Object.class);
Mockito.when(s3.getObject(bucketName, keyName)).thenReturn(s3Object);
InputStream is = new ByteArrayInputStream(expected.getBytes());
S3ObjectInputStream s3ObjectInputStream = new S3ObjectInputStream(is, null);
Mockito.when(s3Object.getObjectContent()).thenReturn(s3ObjectInputStream);
String result = expected;
ByteBuffer buffer = ByteBuffer.wrap(result.getBytes());
DecryptResult decryptResult = Mockito.mock(DecryptResult.class);
Mockito.when(kms.decrypt(Mockito.any(DecryptRequest.class))).thenReturn(decryptResult);
Mockito.when(decryptResult.getPlaintext()).thenReturn(buffer);
AwsPrivateKeyStore awsPrivateKeyStore = new AwsPrivateKeyStore(s3, kms);
String actual = awsPrivateKeyStore.getApplicationSecret(bucketName, keyName);
Assert.assertEquals(actual, expected);
}
Aggregations