1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

Merge pull request #589 from stanhu/sh-filter-upload-part-copy-options

Filter unknown UploadPartCopy paramaters
This commit is contained in:
Wesley Beary 2021-01-10 08:00:10 -06:00 committed by GitHub
commit 9a30e67051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 2 deletions

View file

@ -148,7 +148,8 @@ module Fog
self.multipart_chunk_size = MIN_MULTIPART_CHUNK_SIZE * 2 if !multipart_chunk_size && self.content_length.to_i > MAX_SINGLE_PUT_SIZE self.multipart_chunk_size = MIN_MULTIPART_CHUNK_SIZE * 2 if !multipart_chunk_size && self.content_length.to_i > MAX_SINGLE_PUT_SIZE
if multipart_chunk_size && self.content_length.to_i >= multipart_chunk_size if multipart_chunk_size && self.content_length.to_i >= multipart_chunk_size
upload_part_options = options.merge({ 'x-amz-copy-source' => "#{directory.key}/#{key}" }) upload_part_options = options.select { |key, _| ALLOWED_UPLOAD_PART_OPTIONS.include?(key.to_sym) }
upload_part_options = upload_part_options.merge({ 'x-amz-copy-source' => "#{directory.key}/#{key}" })
multipart_copy(options, upload_part_options, target_directory_key, target_file_key) multipart_copy(options, upload_part_options, target_directory_key, target_file_key)
else else
service.copy_object(directory.key, key, target_directory_key, target_file_key, options) service.copy_object(directory.key, key, target_directory_key, target_file_key, options)

View file

@ -1,6 +1,25 @@
module Fog module Fog
module AWS module AWS
class Storage class Storage
# From https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html
ALLOWED_UPLOAD_PART_OPTIONS = %i(
x-amz-copy-source
x-amz-copy-source-if-match
x-amz-copy-source-if-modified-since
x-amz-copy-source-if-none-match
x-amz-copy-source-if-unmodified-since
x-amz-copy-source-range
x-amz-copy-source-server-side-encryption-customer-algorithm
x-amz-copy-source-server-side-encryption-customer-key
x-amz-copy-source-server-side-encryption-customer-key-MD5
x-amz-expected-bucket-owner
x-amz-request-payer
x-amz-server-side-encryption-customer-algorithm
x-amz-server-side-encryption-customer-key
x-amz-server-side-encryption-customer-key-MD5
x-amz-source-expected-bucket-owner
).freeze
class Real class Real
require 'fog/aws/parsers/storage/upload_part_copy_object' require 'fog/aws/parsers/storage/upload_part_copy_object'
@ -45,6 +64,8 @@ module Fog
include Fog::AWS::Storage::SharedMockMethods include Fog::AWS::Storage::SharedMockMethods
def upload_part_copy(target_bucket_name, target_object_name, upload_id, part_number, options = {}) def upload_part_copy(target_bucket_name, target_object_name, upload_id, part_number, options = {})
validate_options!(options)
copy_source = options['x-amz-copy-source'] copy_source = options['x-amz-copy-source']
copy_range = options['x-amz-copy-source-range'] copy_range = options['x-amz-copy-source-range']
@ -86,6 +107,12 @@ module Fog
[matches[1].to_i, end_pos] [matches[1].to_i, end_pos]
end end
def validate_options!(options)
options.keys.each do |key|
raise "Invalid UploadPart option: #{key}" unless ::Fog::AWS::Storage::ALLOWED_UPLOAD_PART_OPTIONS.include?(key.to_sym)
end
end
end # Mock end # Mock
end # Storage end # Storage
end # AWS end # AWS

View file

@ -3,7 +3,7 @@ require 'securerandom'
Shindo.tests('Fog::Storage[:aws] | copy requests', ["aws"]) do Shindo.tests('Fog::Storage[:aws] | copy requests', ["aws"]) do
@directory = Fog::Storage[:aws].directories.create(:key => uniq_id('fogmultipartcopytests')) @directory = Fog::Storage[:aws].directories.create(:key => uniq_id('fogmultipartcopytests'))
@large_data = SecureRandom.hex * 19 * 1024 * 1024 @large_data = SecureRandom.hex * 600000
@large_blob = Fog::Storage[:aws].put_object(@directory.identity, 'large_object', @large_data) @large_blob = Fog::Storage[:aws].put_object(@directory.identity, 'large_object', @large_data)
tests('copies an empty object') do tests('copies an empty object') do
@ -77,4 +77,17 @@ Shindo.tests('Fog::Storage[:aws] | copy requests', ["aws"]) do
test("copied is the same") { copied.body == file.body } test("copied is the same") { copied.body == file.body }
end end
tests('copies an object with unknown headers') do
file = Fog::Storage[:aws].directories.new(key: @directory.identity).files.get('large_object')
file.multipart_chunk_size = Fog::AWS::Storage::File::MIN_MULTIPART_CHUNK_SIZE
file.concurrency = 10
tests("#copy_object('#{@directory.identity}', 'copied_object'").succeeds do
file.copy(@directory.identity, 'copied_object', { unknown: 1 } )
end
copied = Fog::Storage[:aws].directories.new(key: @directory.identity).files.get('copied_object')
test("copied is the same") { copied.body == file.body }
end
end end