use of org.jets3t.service.S3Service in project pentaho-kettle by pentaho.
the class S3CsvInputMeta method getS3Service.
public S3Service getS3Service(VariableSpace space) throws S3ServiceException {
// Try to connect to S3 first
//
String accessKey = Encr.decryptPasswordOptionallyEncrypted(space.environmentSubstitute(awsAccessKey));
String secretKey = Encr.decryptPasswordOptionallyEncrypted(space.environmentSubstitute(awsSecretKey));
AWSCredentials awsCredentials = new AWSCredentials(accessKey, secretKey);
S3Service s3service = new RestS3Service(awsCredentials);
return s3service;
}
use of org.jets3t.service.S3Service in project pentaho-kettle by pentaho.
the class S3ObjectsProviderTest method getS3ServiceMock.
private S3Service getS3ServiceMock(AWSCredentials credentials) throws Exception {
S3Service service = mock(S3Service.class);
when(service.listAllBuckets()).thenReturn(generateTestBuckets(TEST_USER_BUCKETS_NAMES));
// BUCKET2 - not empty bucket
when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET2)))).thenReturn(bucket2Objects);
// BUCKET3 - empty bucket
when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET3)))).thenReturn(bucket3Objects);
when(service.getObject(any(S3Bucket.class), any(String.class), any(), any(), any(), any(), any(), any())).thenReturn(testObject);
when(service.getObjectDetails(any(S3Bucket.class), any(String.class), any(), any(), any(), any())).thenReturn(testObject);
return service;
}
use of org.jets3t.service.S3Service in project OpenTripPlanner by opentripplanner.
the class DegreeGridNEDTileSource method getPathToTile.
private File getPathToTile(int x, int y) {
File path = new File(cacheDirectory, formatLatLon(x, y) + ".tiff");
if (path.exists()) {
return path;
} else {
path.getParentFile().mkdirs();
if (awsAccessKey == null || awsSecretKey == null) {
throw new RuntimeException("Cannot download NED tiles from S3: awsAccessKey or awsSecretKey properties are not set");
}
log.info("Downloading NED degree tile " + path);
// download the file from S3.
AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
try {
S3Service s3Service = new RestS3Service(awsCredentials);
String key = formatLatLon(x, y) + ".tiff";
S3Object object = s3Service.getObject(awsBucketName, key);
InputStream istream = object.getDataInputStream();
FileOutputStream ostream = new FileOutputStream(path);
byte[] buffer = new byte[4096];
while (true) {
int read = istream.read(buffer);
if (read == -1) {
break;
}
ostream.write(buffer, 0, read);
}
ostream.close();
istream.close();
} catch (S3ServiceException e) {
path.deleteOnExit();
throw new RuntimeException(e);
} catch (ServiceException e) {
path.deleteOnExit();
throw new RuntimeException(e);
} catch (FileNotFoundException e) {
path.deleteOnExit();
throw new RuntimeException(e);
} catch (IOException e) {
path.deleteOnExit();
throw new RuntimeException(e);
}
return path;
}
}
use of org.jets3t.service.S3Service in project pentaho-kettle by pentaho.
the class S3CsvInputMetaTest method testGetS3Service_notEncryptedKeys.
@Test
public void testGetS3Service_notEncryptedKeys() {
S3CsvInputMeta s3CvsInput = new S3CsvInputMeta();
s3CvsInput.setAwsAccessKey(TEST_ACCESS_KEY);
s3CvsInput.setAwsSecretKey(TEST_AWS_SECRET_KEY);
try {
S3Service s3Service = s3CvsInput.getS3Service(new Variables());
assertNotNull(s3Service);
assertEquals(TEST_ACCESS_KEY, s3Service.getProviderCredentials().getAccessKey());
assertEquals(TEST_AWS_SECRET_KEY, s3Service.getProviderCredentials().getSecretKey());
} catch (S3ServiceException e) {
fail("No exception should be thrown. But it was:" + e.getLocalizedMessage());
}
}
use of org.jets3t.service.S3Service in project pentaho-kettle by pentaho.
the class S3CsvInputMetaTest method testGetS3Service_WithEncryptedKeys.
@Test
public void testGetS3Service_WithEncryptedKeys() {
S3CsvInputMeta s3CvsInput = new S3CsvInputMeta();
s3CvsInput.setAwsAccessKey(TEST_ACCESS_KEY_ENCRYPTED);
s3CvsInput.setAwsSecretKey(TEST_AWS_SECRET_KEY_ENCRYPTED);
try {
S3Service s3Service = s3CvsInput.getS3Service(new Variables());
assertNotNull(s3Service);
assertEquals(TEST_ACCESS_KEY, s3Service.getProviderCredentials().getAccessKey());
assertEquals(TEST_AWS_SECRET_KEY, s3Service.getProviderCredentials().getSecretKey());
} catch (S3ServiceException e) {
fail("No exception should be thrown. But it was:" + e.getLocalizedMessage());
}
}
Aggregations