Search in sources :

Example 1 with S3Service

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;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) AWSCredentials(org.jets3t.service.security.AWSCredentials) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Service(org.jets3t.service.S3Service)

Example 2 with 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;
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Service(org.jets3t.service.S3Service)

Example 3 with S3Service

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;
    }
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) S3ServiceException(org.jets3t.service.S3ServiceException) IOException(java.io.IOException) AWSCredentials(org.jets3t.service.security.AWSCredentials) ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) FileOutputStream(java.io.FileOutputStream) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Object(org.jets3t.service.model.S3Object) File(java.io.File) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Service(org.jets3t.service.S3Service)

Example 4 with S3Service

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());
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) S3ServiceException(org.jets3t.service.S3ServiceException) S3Service(org.jets3t.service.S3Service) Test(org.junit.Test)

Example 5 with S3Service

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());
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) S3ServiceException(org.jets3t.service.S3ServiceException) S3Service(org.jets3t.service.S3Service) Test(org.junit.Test)

Aggregations

S3Service (org.jets3t.service.S3Service)6 S3ServiceException (org.jets3t.service.S3ServiceException)4 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)3 AWSCredentials (org.jets3t.service.security.AWSCredentials)3 Test (org.junit.Test)2 Variables (org.pentaho.di.core.variables.Variables)2 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 XBayaDialog (org.apache.airavata.xbaya.ui.dialogs.XBayaDialog)1 BucketsLoader (org.apache.airavata.xbaya.ui.dialogs.amazon.BucketsLoader)1 ChangeCredentialWindow (org.apache.airavata.xbaya.ui.dialogs.amazon.ChangeCredentialWindow)1 S3Tree (org.apache.airavata.xbaya.ui.widgets.amazon.S3Tree)1