Search in sources :

Example 1 with S3DatastoreProperties

use of org.talend.components.simplefileio.s3.S3DatastoreProperties in project components by Talend.

the class S3TestResource method createS3DatastoreProperties.

/**
 * @return An S3DatastoreProperties with all of the defaults, but filled with security credentials from the system
 * environment.
 */
public S3DatastoreProperties createS3DatastoreProperties() {
    S3DatastoreProperties properties = new S3DatastoreProperties(null);
    properties.init();
    String s3AccessKey = System.getProperty("s3.accesskey");
    String s3SecretKey = System.getProperty("s3.secretkey");
    // If we are running in an environment without specified keys, then don't use them.
    if (StringUtils.isEmpty(s3AccessKey) || StringUtils.isEmpty(s3SecretKey)) {
        properties.specifyCredentials.setValue(false);
    } else {
        properties.accessKey.setValue(System.getProperty("s3.accesskey"));
        properties.secretKey.setValue(System.getProperty("s3.secretkey"));
    }
    return properties;
}
Also used : S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties)

Example 2 with S3DatastoreProperties

use of org.talend.components.simplefileio.s3.S3DatastoreProperties in project components by Talend.

the class S3Connection method createClient.

public static AmazonS3 createClient(S3OutputProperties properties) {
    S3DatasetProperties data_set = properties.getDatasetProperties();
    S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties();
    com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials(data_store.accessKey.getValue(), data_store.secretKey.getValue());
    Region region = RegionUtils.getRegion(data_set.region.getValue().getValue());
    Boolean clientSideEnc = data_set.encryptDataInMotion.getValue();
    AmazonS3 conn = null;
    if (clientSideEnc != null && clientSideEnc) {
        String kms_cmk = data_set.kmsForDataInMotion.getValue();
        KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kms_cmk);
        conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region));
    } else {
        AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials);
        conn = new AmazonS3Client(basicCredentialsProvider);
    }
    conn.setRegion(region);
    return conn;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3EncryptionClient(com.amazonaws.services.s3.AmazonS3EncryptionClient) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) CryptoConfiguration(com.amazonaws.services.s3.model.CryptoConfiguration) S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Region(com.amazonaws.regions.Region) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 3 with S3DatastoreProperties

use of org.talend.components.simplefileio.s3.S3DatastoreProperties in project components by Talend.

the class PropertiesPreparer method createS3OtuputProperties.

public static S3OutputProperties createS3OtuputProperties() {
    S3OutputProperties properties = new S3OutputProperties("s3output");
    S3DatasetProperties dataset = new S3DatasetProperties("dataset");
    S3DatastoreProperties datastore = new S3DatastoreProperties("datastore");
    properties.setDatasetProperties(dataset);
    dataset.setDatastoreProperties(datastore);
    datastore.accessKey.setValue(accessKey);
    datastore.secretKey.setValue(secretkey);
    dataset.region.setValue(S3Region.valueOf(region));
    dataset.bucket.setValue(bucket);
    dataset.kmsForDataInMotion.setValue(ssekmskey);
    dataset.kmsForDataAtRest.setValue(csekmskey);
    dataset.object.setValue(objectkey);
    return properties;
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) S3OutputProperties(org.talend.components.simplefileio.s3.output.S3OutputProperties) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties)

Example 4 with S3DatastoreProperties

use of org.talend.components.simplefileio.s3.S3DatastoreProperties in project components by Talend.

the class S3SourceOrSinkTestIT method validate_fail.

@Test
public void validate_fail() {
    S3OutputProperties properties = PropertiesPreparer.createS3OtuputProperties();
    S3DatastoreProperties datastore = properties.getDatasetProperties().getDatastoreProperties();
    datastore.secretKey.setValue("wrongone");
    runtime.initialize(null, properties);
    ValidationResult result = runtime.validate(null);
    org.junit.Assert.assertEquals(result.getMessage(), ValidationResult.Result.ERROR, result.getStatus());
}
Also used : S3OutputProperties(org.talend.components.simplefileio.s3.output.S3OutputProperties) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 5 with S3DatastoreProperties

use of org.talend.components.simplefileio.s3.S3DatastoreProperties in project components by Talend.

the class S3OutputPropertiesTest method setup.

@Before
public void setup() {
    properties = new S3OutputProperties("test");
    S3DatastoreProperties datastoreProperties = new S3DatastoreProperties("test");
    datastoreProperties.init();
    S3DatasetProperties datasetProperties = new S3DatasetProperties("test");
    datasetProperties.init();
    datasetProperties.setDatastoreProperties(datastoreProperties);
    properties.setDatasetProperties(datasetProperties);
    properties.init();
}
Also used : S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties) Before(org.junit.Before)

Aggregations

S3DatastoreProperties (org.talend.components.simplefileio.s3.S3DatastoreProperties)5 S3DatasetProperties (org.talend.components.simplefileio.s3.S3DatasetProperties)3 S3OutputProperties (org.talend.components.simplefileio.s3.output.S3OutputProperties)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 StaticCredentialsProvider (com.amazonaws.internal.StaticCredentialsProvider)1 Region (com.amazonaws.regions.Region)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AmazonS3EncryptionClient (com.amazonaws.services.s3.AmazonS3EncryptionClient)1 CryptoConfiguration (com.amazonaws.services.s3.model.CryptoConfiguration)1 KMSEncryptionMaterialsProvider (com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1