Example usage for com.amazonaws.services.s3.model CopyObjectRequest setSourceSSECustomerKey

List of usage examples for com.amazonaws.services.s3.model CopyObjectRequest setSourceSSECustomerKey

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CopyObjectRequest setSourceSSECustomerKey.

Prototype

public void setSourceSSECustomerKey(SSECustomerKey sseKey) 

Source Link

Document

Sets the optional customer-provided server-side encryption key to use to decrypt the source object being copied.

Usage

From source file:org.alanwilliamson.amazon.s3.Copy.java

License:Open Source License

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {

    AmazonKey amazonKey = getAmazonKey(_session, argStruct);
    AmazonS3 s3Client = getAmazonS3(amazonKey);

    String srcbucket = getNamedStringParam(argStruct, "srcbucket", null);
    String srckey = getNamedStringParam(argStruct, "srckey", null);
    String srcaes256key = getNamedStringParam(argStruct, "srcaes256key", null);

    String destbucket = getNamedStringParam(argStruct, "destbucket", null);
    String deskey = getNamedStringParam(argStruct, "destkey", null);
    String destaes256key = getNamedStringParam(argStruct, "destaes256key", null);
    String deststorageclass = getNamedStringParam(argStruct, "deststorageclass", null);
    String destacl = getNamedStringParam(argStruct, "destacl", null);

    if (srckey != null && srckey.charAt(0) == '/')
        srckey = srckey.substring(1);//from   www  .ja v  a  2s  .  co  m

    if (deskey != null && deskey.charAt(0) == '/')
        deskey = deskey.substring(1);

    CopyObjectRequest cor = new CopyObjectRequest(srcbucket, srckey, destbucket, deskey);

    if (srcaes256key != null && !srcaes256key.isEmpty())
        cor.setSourceSSECustomerKey(new SSECustomerKey(srcaes256key));

    if (destaes256key != null && !destaes256key.isEmpty())
        cor.setDestinationSSECustomerKey(new SSECustomerKey(destaes256key));

    if (deststorageclass != null && !deststorageclass.isEmpty())
        cor.setStorageClass(amazonKey.getAmazonStorageClass(deststorageclass));

    if (destacl != null && !destacl.isEmpty())
        cor.setCannedAccessControlList(amazonKey.getAmazonCannedAcl(destacl));

    try {
        s3Client.copyObject(cor);
        return cfBooleanData.TRUE;
    } catch (Exception e) {
        throwException(_session, "AmazonS3: " + e.getMessage());
        return cfBooleanData.FALSE;
    }
}

From source file:org.alanwilliamson.amazon.s3.Rename.java

License:Open Source License

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
    AmazonKey amazonKey = getAmazonKey(_session, argStruct);
    AmazonS3 s3Client = getAmazonS3(amazonKey);

    String bucket = getNamedStringParam(argStruct, "bucket", null);
    String srckey = getNamedStringParam(argStruct, "srckey", null);
    String deskey = getNamedStringParam(argStruct, "destkey", null);
    String aes256key = getNamedStringParam(argStruct, "aes256key", null);

    if (srckey != null && srckey.charAt(0) == '/')
        srckey = srckey.substring(1);/*from w ww. j a  v  a  2 s .  c om*/

    if (deskey != null && deskey.charAt(0) == '/')
        deskey = deskey.substring(1);

    CopyObjectRequest cor = new CopyObjectRequest(bucket, srckey, bucket, deskey);

    if (aes256key != null && !aes256key.isEmpty()) {
        cor.setSourceSSECustomerKey(new SSECustomerKey(aes256key));
        cor.setDestinationSSECustomerKey(new SSECustomerKey(aes256key));
    }

    try {
        s3Client.copyObject(cor);
        s3Client.deleteObject(new DeleteObjectRequest(bucket, srckey));
        return cfBooleanData.TRUE;
    } catch (Exception e) {
        throwException(_session, "AmazonS3: " + e.getMessage());
        return cfBooleanData.FALSE;
    }
}

From source file:org.apache.beam.sdk.io.aws.s3.S3FileSystem.java

License:Apache License

@VisibleForTesting
CopyObjectResult atomicCopy(S3ResourceId sourcePath, S3ResourceId destinationPath,
        ObjectMetadata sourceObjectMetadata) throws AmazonClientException {
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourcePath.getBucket(), sourcePath.getKey(),
            destinationPath.getBucket(), destinationPath.getKey());
    copyObjectRequest.setNewObjectMetadata(sourceObjectMetadata);
    copyObjectRequest.setStorageClass(options.getS3StorageClass());
    copyObjectRequest.setSourceSSECustomerKey(options.getSSECustomerKey());
    copyObjectRequest.setDestinationSSECustomerKey(options.getSSECustomerKey());
    return amazonS3.get().copyObject(copyObjectRequest);
}