Method: Fog::Storage::AWS::Mock#copy_object

Defined in:
lib/fog/aws/requests/storage/copy_object.rb

#copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {}) ⇒ Object

[View source]

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/aws/requests/storage/copy_object.rb', line 48

def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
  response = Excon::Response.new
  source_bucket = self.data[:buckets][source_bucket_name]
  source_object = source_bucket && source_bucket[:objects][source_object_name] && source_bucket[:objects][source_object_name].first
  target_bucket = self.data[:buckets][target_bucket_name]

  acl = options['x-amz-acl'] || 'private'
  if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
    raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
  else
    self.data[:acls][:object][target_bucket_name] ||= {}
    self.data[:acls][:object][target_bucket_name][target_object_name] = self.class.acls(acl)
  end

  if source_object && target_bucket
    response.status = 200
    target_object = source_object.dup
    target_object.merge!({'Key' => target_object_name})
    target_bucket[:objects][target_object_name] = [target_object]
    response.body = {
      'ETag'          => target_object['ETag'],
      'LastModified'  => Time.parse(target_object['Last-Modified'])
    }
  else
    response.status = 404
    raise(Excon::Errors.status_error({:expects => 200}, response))
  end

  response
end