Java 类com.amazonaws.services.s3.model.SSEAlgorithm 实例源码

项目:esthree    文件:Put.java   
@Override
public Integer call() throws Exception {
    TransferManager t = new TransferManager(amazonS3Client);

    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setUserMetadata(metadata);
    if(sse) {
        objectMetadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
    }

    Upload u = t.upload(new PutObjectRequest(bucket, key, inputFile).withMetadata(objectMetadata));

    // TODO this listener spews out garbage >100% on a retry, add a test to verify
    if (progressListener != null) {
        progressListener.withTransferProgress(new TransferProgressWrapper(u.getProgress()));
        u.addProgressListener(progressListener);
    }
    try {
        u.waitForCompletion();
    } finally {
        t.shutdownNow();
    }
    return 0;
}
项目:herd    文件:S3DaoImpl.java   
/**
 * Prepares the object metadata for server side encryption and reduced redundancy storage.
 *
 * @param params the parameters.
 * @param metadata the metadata to prepare.
 */
private void prepareMetadata(final S3FileTransferRequestParamsDto params, ObjectMetadata metadata)
{
    // Set the server side encryption
    if (params.getKmsKeyId() != null)
    {
        /*
         * TODO Use proper way to set KMS once AWS provides a way.
         * We are modifying the raw headers directly since TransferManager's uploadFileList operation does not provide a way to set a KMS key ID.
         * This would normally cause some issues when uploading where an MD5 checksum validation exception will be thrown, even though the object is
         * correctly uploaded.
         * To get around this, a system property defined at
         * com.amazonaws.services.s3.internal.SkipMd5CheckStrategy.DISABLE_PUT_OBJECT_MD5_VALIDATION_PROPERTY must be set.
         */
        metadata.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
        metadata.setHeader(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, params.getKmsKeyId().trim());
    }
    else
    {
        metadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
    }

    // If specified, set the metadata to use RRS.
    if (Boolean.TRUE.equals(params.isUseRrs()))
    {
        // TODO: For upload File, we can set RRS on the putObjectRequest. For uploadDirectory, this is the only
        // way to do it. However, setHeader() is flagged as For Internal Use Only
        metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.ReducedRedundancy.toString());
    }
}
项目:datacollector    文件:FileHelper.java   
protected ObjectMetadata getObjectMetadata() throws StageException {
  ObjectMetadata metadata = null;
  if (s3TargetConfigBean.sseConfig.useSSE) {
    metadata = new ObjectMetadata();
    switch (s3TargetConfigBean.sseConfig.encryption) {
      case S3:
        metadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
        break;
      case KMS:
        metadata.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
        metadata.setHeader(
            Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID,
            s3TargetConfigBean.sseConfig.kmsKeyId.get()
        );
        if (!s3TargetConfigBean.sseConfig.encryptionContext.isEmpty()) {
          metadata.setHeader(
              "x-amz-server-side-encryption-context",
              s3TargetConfigBean.sseConfig.resolveEncryptionContext()
          );
        }
        break;
      case CUSTOMER:
        metadata.setSSECustomerAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
        metadata.setHeader(
            Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY,
            s3TargetConfigBean.sseConfig.customerKey.get()
        );
        metadata.setHeader(
            Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
            s3TargetConfigBean.sseConfig.customerKeyMd5.get()
        );
        break;
      default:
        throw new IllegalStateException(
            Utils.format(
                "Unknown encryption option: ",
                s3TargetConfigBean.sseConfig.encryption
            )
        );
    }
  }
  return metadata;
}