List of usage examples for com.amazonaws.services.s3.model InitiateMultipartUploadRequest setSSEAwsKeyManagementParams
public void setSSEAwsKeyManagementParams(SSEAwsKeyManagementParams params)
From source file:io.confluent.connect.s3.storage.S3OutputStream.java
License:Open Source License
private MultipartUpload newMultipartUpload() throws IOException { InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucket, key, newObjectMetadata()).withCannedACL(cannedAcl); if (SSEAlgorithm.KMS.toString().equalsIgnoreCase(ssea) && StringUtils.isNotBlank(sseKmsKeyId)) { initRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(sseKmsKeyId)); } else if (sseCustomerKey != null) { initRequest.setSSECustomerKey(sseCustomerKey); }/*from w w w . j av a2s .co m*/ try { return new MultipartUpload(s3.initiateMultipartUpload(initRequest).getUploadId()); } catch (AmazonClientException e) { // TODO: elaborate on the exception interpretation. If this is an AmazonServiceException, // there's more info to be extracted. throw new IOException("Unable to initiate MultipartUpload: " + e, e); } }
From source file:io.konig.camel.aws.s3.DeleteObjectProducer.java
License:Apache License
public void processMultiPart(final Exchange exchange) throws Exception { File filePayload = null;// w w w. ja v a 2s.c o m Object obj = exchange.getIn().getMandatoryBody(); // Need to check if the message body is WrappedFile if (obj instanceof WrappedFile) { obj = ((WrappedFile<?>) obj).getFile(); } if (obj instanceof File) { filePayload = (File) obj; } else { throw new InvalidArgumentException("aws-s3: MultiPart upload requires a File input."); } ObjectMetadata objectMetadata = determineMetadata(exchange); if (objectMetadata.getContentLength() == 0) { objectMetadata.setContentLength(filePayload.length()); } final String keyName = determineKey(exchange); final InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest( getConfiguration().getBucketName(), keyName, objectMetadata); String storageClass = determineStorageClass(exchange); if (storageClass != null) { initRequest.setStorageClass(StorageClass.fromValue(storageClass)); } String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class); if (cannedAcl != null) { CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl); initRequest.setCannedACL(objectAcl); } AccessControlList acl = exchange.getIn().getHeader(S3Constants.ACL, AccessControlList.class); if (acl != null) { // note: if cannedacl and acl are both specified the last one will // be used. refer to // PutObjectRequest#setAccessControlList for more details initRequest.setAccessControlList(acl); } if (getConfiguration().isUseAwsKMS()) { SSEAwsKeyManagementParams keyManagementParams; if (ObjectHelper.isNotEmpty(getConfiguration().getAwsKMSKeyId())) { keyManagementParams = new SSEAwsKeyManagementParams(getConfiguration().getAwsKMSKeyId()); } else { keyManagementParams = new SSEAwsKeyManagementParams(); } initRequest.setSSEAwsKeyManagementParams(keyManagementParams); } LOG.trace("Initiating multipart upload [{}] from exchange [{}]...", initRequest, exchange); final InitiateMultipartUploadResult initResponse = getEndpoint().getS3Client() .initiateMultipartUpload(initRequest); final long contentLength = objectMetadata.getContentLength(); final List<PartETag> partETags = new ArrayList<PartETag>(); long partSize = getConfiguration().getPartSize(); CompleteMultipartUploadResult uploadResult = null; long filePosition = 0; try { for (int part = 1; filePosition < contentLength; part++) { partSize = Math.min(partSize, contentLength - filePosition); UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(getConfiguration().getBucketName()).withKey(keyName) .withUploadId(initResponse.getUploadId()).withPartNumber(part).withFileOffset(filePosition) .withFile(filePayload).withPartSize(partSize); LOG.trace("Uploading part [{}] for {}", part, keyName); partETags.add(getEndpoint().getS3Client().uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest( getConfiguration().getBucketName(), keyName, initResponse.getUploadId(), partETags); uploadResult = getEndpoint().getS3Client().completeMultipartUpload(compRequest); } catch (Exception e) { getEndpoint().getS3Client().abortMultipartUpload(new AbortMultipartUploadRequest( getConfiguration().getBucketName(), keyName, initResponse.getUploadId())); throw e; } Message message = getMessageForResponse(exchange); message.setHeader(S3Constants.E_TAG, uploadResult.getETag()); if (uploadResult.getVersionId() != null) { message.setHeader(S3Constants.VERSION_ID, uploadResult.getVersionId()); } if (getConfiguration().isDeleteAfterWrite() && filePayload != null) { FileUtil.deleteFile(filePayload); } }
From source file:org.apache.beam.sdk.io.aws.s3.S3WritableByteChannel.java
License:Apache License
S3WritableByteChannel(AmazonS3 amazonS3, S3ResourceId path, String contentType, S3Options options) throws IOException { this.amazonS3 = checkNotNull(amazonS3, "amazonS3"); this.options = checkNotNull(options); this.path = checkNotNull(path, "path"); checkArgument(/*from ww w.ja v a 2s . c o m*/ atMostOne(options.getSSECustomerKey() != null, options.getSSEAlgorithm() != null, options.getSSEAwsKeyManagementParams() != null), "Either SSECustomerKey (SSE-C) or SSEAlgorithm (SSE-S3)" + " or SSEAwsKeyManagementParams (SSE-KMS) must not be set at the same time."); // Amazon S3 API docs: Each part must be at least 5 MB in size, except the last part. checkArgument(options .getS3UploadBufferSizeBytes() >= S3UploadBufferSizeBytesFactory.MINIMUM_UPLOAD_BUFFER_SIZE_BYTES, "S3UploadBufferSizeBytes must be at least %s bytes", S3UploadBufferSizeBytesFactory.MINIMUM_UPLOAD_BUFFER_SIZE_BYTES); this.uploadBuffer = ByteBuffer.allocate(options.getS3UploadBufferSizeBytes()); eTags = new ArrayList<>(); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(contentType); if (options.getSSEAlgorithm() != null) { objectMetadata.setSSEAlgorithm(options.getSSEAlgorithm()); } InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(path.getBucket(), path.getKey()) .withStorageClass(options.getS3StorageClass()).withObjectMetadata(objectMetadata); request.setSSECustomerKey(options.getSSECustomerKey()); request.setSSEAwsKeyManagementParams(options.getSSEAwsKeyManagementParams()); InitiateMultipartUploadResult result; try { result = amazonS3.initiateMultipartUpload(request); } catch (AmazonClientException e) { throw new IOException(e); } uploadId = result.getUploadId(); }
From source file:org.apache.nifi.processors.aws.s3.encryption.ServerSideKMSEncryptionStrategy.java
License:Apache License
@Override public void configureInitiateMultipartUploadRequest(InitiateMultipartUploadRequest request, ObjectMetadata objectMetadata, String keyValue) { SSEAwsKeyManagementParams keyParams = new SSEAwsKeyManagementParams(keyValue); request.setSSEAwsKeyManagementParams(keyParams); }
From source file:org.apache.nifi.processors.aws.s3.encryption.service.StandardS3ServerSideEncryptionService.java
License:Apache License
public void encrypt(InitiateMultipartUploadRequest initiateMultipartUploadRequest) { if (encryptionMethod == null) return;/*w ww . j a va 2 s .c om*/ if (encryptionMethod.equals(METHOD_SSE_S3)) { getLogger().info("Encrypting multipart object using SSE-S3"); initiateMultipartUploadRequest.getObjectMetadata() .setSSEAlgorithm(algorithm == null ? ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION : algorithm); } if (encryptionMethod.equals(METHOD_SSE_KMS)) { getLogger().info("Encrypting multipart object using SSE-KMS"); initiateMultipartUploadRequest.setSSEAwsKeyManagementParams( kmsKeyId == null ? new SSEAwsKeyManagementParams() : new SSEAwsKeyManagementParams(kmsKeyId)); } if (encryptionMethod.equals(METHOD_SSE_C)) { getLogger().info("Encrypting multipart object using SSE-C"); if (StringUtils.isNotBlank(customerKey)) { initiateMultipartUploadRequest.setSSECustomerKey(new SSECustomerKey(customerKey)); } String sseCustomerAlgorithm = customerAlgorithm == null ? ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION : customerAlgorithm; initiateMultipartUploadRequest.getObjectMetadata().setSSECustomerAlgorithm(sseCustomerAlgorithm); if (StringUtils.isNotBlank(customerKeyMD5)) { initiateMultipartUploadRequest.getObjectMetadata().setSSECustomerKeyMd5(customerKeyMD5); } } }