mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws&google|storage] mock fixes
This commit is contained in:
parent
12cffca4e4
commit
e53fffeb28
6 changed files with 118 additions and 81 deletions
|
@ -21,7 +21,7 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent
|
||||
recognizes :provider # remove post deprecation
|
||||
|
||||
|
||||
model_path 'fog/storage/models/aws'
|
||||
collection :directories
|
||||
model :directory
|
||||
|
@ -79,14 +79,14 @@ module Fog
|
|||
|
||||
if data.is_a?(String)
|
||||
metadata[:body] = data
|
||||
metadata[:headers]['Content-Length'] = metadata[:body].size.to_s
|
||||
metadata[:headers]['Content-Length'] = metadata[:body].size
|
||||
else
|
||||
filename = ::File.basename(data.path)
|
||||
unless (mime_types = MIME::Types.of(filename)).empty?
|
||||
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
||||
end
|
||||
metadata[:body] = data
|
||||
metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s
|
||||
metadata[:headers]['Content-Length'] = ::File.size(data.path)
|
||||
end
|
||||
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
||||
metadata
|
||||
|
@ -111,7 +111,7 @@ module Fog
|
|||
def self.acls(type)
|
||||
case type
|
||||
when 'private'
|
||||
@private ||= {
|
||||
{
|
||||
"AccessControlList" => [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
|
@ -121,32 +121,51 @@ module Fog
|
|||
"Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'public-read'
|
||||
@public_read ||= begin
|
||||
public_read = self.acls('private').dup
|
||||
public_read['AccessControlList'] << {
|
||||
"Permission" => "READ",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"}
|
||||
}
|
||||
public_read
|
||||
end
|
||||
{
|
||||
"AccessControlList" => [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'public-read-write'
|
||||
@public_read_write ||= begin
|
||||
public_read_write = self.acls('public-read').dup
|
||||
public_read_write['AccessControlList'] << {
|
||||
"Permission" => "WRITE",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"}
|
||||
}
|
||||
public_read_write
|
||||
end
|
||||
{
|
||||
"AccessControlList" => [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"}
|
||||
},
|
||||
{
|
||||
"Permission" => "WRITE",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AllUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'authenticated-read'
|
||||
@authenticated_read ||= begin
|
||||
authenticated_read = self.acls('private').dup
|
||||
authenticated_read['AccessControlList'] << {
|
||||
"Permission" => "READ",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"}
|
||||
}
|
||||
authenticated_read
|
||||
end
|
||||
{
|
||||
"AccessControlList" => [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Grantee" => {"URI" => "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,14 +39,14 @@ module Fog
|
|||
|
||||
if data.is_a?(String)
|
||||
metadata[:body] = data
|
||||
metadata[:headers]['Content-Length'] = metadata[:body].size.to_s
|
||||
metadata[:headers]['Content-Length'] = metadata[:body].size
|
||||
else
|
||||
filename = ::File.basename(data.path)
|
||||
unless (mime_types = MIME::Types.of(filename)).empty?
|
||||
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
||||
end
|
||||
metadata[:body] = data
|
||||
metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s
|
||||
metadata[:headers]['Content-Length'] = ::File.size(data.path)
|
||||
end
|
||||
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
||||
metadata
|
||||
|
@ -70,7 +70,7 @@ module Fog
|
|||
def self.acls(type)
|
||||
case type
|
||||
when 'private'
|
||||
@private ||= {
|
||||
{
|
||||
"AccessControlList"=> [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
|
@ -80,32 +80,51 @@ module Fog
|
|||
"Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'public-read'
|
||||
@public_read ||= begin
|
||||
public_read = self.acls('private').dup
|
||||
public_read['AccessControlList'] << {
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllUsers"}
|
||||
}
|
||||
public_read
|
||||
end
|
||||
{
|
||||
"AccessControlList"=> [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'public-read-write'
|
||||
@public_read_write ||= begin
|
||||
public_read_write = self.acls('private').dup
|
||||
public_read_write['AccessControlList'] << {
|
||||
"Permission" => "WRITE",
|
||||
"Scope" => {"type" => "AllUsers"}
|
||||
}
|
||||
public_read_write
|
||||
end
|
||||
{
|
||||
"AccessControlList"=> [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllUsers"}
|
||||
},
|
||||
{
|
||||
"Permission" => "WRITE",
|
||||
"Scope" => {"type" => "AllUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
when 'authenticated-read'
|
||||
@authenticated_read ||= begin
|
||||
authenticated_read = self.acls('private').dup
|
||||
authenticated_read['AccessControlList'] << {
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllAuthenticatedUsers"}
|
||||
}
|
||||
authenticated_read
|
||||
end
|
||||
{
|
||||
"AccessControlList"=> [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"}
|
||||
},
|
||||
{
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllAuthenticatedUsers"}
|
||||
}
|
||||
],
|
||||
"Owner" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@ DATA
|
|||
class Mock # :nodoc:all
|
||||
|
||||
def put_bucket(bucket_name, options = {})
|
||||
if options['x-amz-acl']
|
||||
unless ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
||||
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
||||
else
|
||||
@data[:acls][:bucket][bucket_name] = self.class.acls(options['x-amz-acl'])
|
||||
end
|
||||
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
|
||||
@data[:acls][:bucket][bucket_name] = self.class.acls(acl)
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
bucket = {
|
||||
|
|
|
@ -47,14 +47,14 @@ module Fog
|
|||
class Mock # :nodoc:all
|
||||
|
||||
def put_object(bucket_name, object_name, data, options = {})
|
||||
if options['x-amz-acl']
|
||||
unless ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
||||
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
||||
else
|
||||
@data[:acls][:object][bucket_name] ||= {}
|
||||
@data[:acls][:object][bucket_name][object_name] = self.class.acls(options['x-amz-acl'])
|
||||
end
|
||||
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
|
||||
@data[:acls][:object][bucket_name] ||= {}
|
||||
@data[:acls][:object][bucket_name][object_name] = self.class.acls(acl)
|
||||
end
|
||||
|
||||
data = parse_data(data)
|
||||
unless data[:body].is_a?(String)
|
||||
data[:body] = data[:body].read
|
||||
|
|
|
@ -40,12 +40,11 @@ DATA
|
|||
class Mock
|
||||
|
||||
def put_bucket(bucket_name, options = {})
|
||||
if options['x-goog-acl']
|
||||
unless ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
||||
raise Excon::Errors::BadRequest.new('invalid x-goog-acl')
|
||||
else
|
||||
@data[:acls][:bucket][bucket_name] = self.class.acls(options['x-goog-acl'])
|
||||
end
|
||||
acl = options['x-goog-acl'] || 'private'
|
||||
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
||||
raise Excon::Errors::BadRequest.new('invalid x-goog-acl')
|
||||
else
|
||||
@data[:acls][:bucket][bucket_name] = self.class.acls(options[acl])
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
|
|
@ -42,14 +42,14 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def put_object(bucket_name, object_name, data, options = {})
|
||||
if options['x-goog-acl']
|
||||
unless ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
||||
raise Excon::Errors::BadRequest.new('invalid x-goog-acl')
|
||||
else
|
||||
@data[:acls][:object][bucket_name] ||= {}
|
||||
@data[:acls][:object][bucket_name][object_name] = self.class.acls(options['x-goog-acl'])
|
||||
end
|
||||
acl = options['x-goog-acl'] || 'private'
|
||||
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
||||
raise Excon::Errors::BadRequest.new('invalid x-goog-acl')
|
||||
else
|
||||
@data[:acls][:object][bucket_name] ||= {}
|
||||
@data[:acls][:object][bucket_name][object_name] = self.class.acls(acl)
|
||||
end
|
||||
|
||||
data = parse_data(data)
|
||||
unless data[:body].is_a?(String)
|
||||
data[:body] = data[:body].read
|
||||
|
|
Loading…
Reference in a new issue