mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws&google|storage] add canned acl related mocks
This commit is contained in:
parent
3f5b48e812
commit
e8b740c84e
11 changed files with 158 additions and 7 deletions
|
@ -49,7 +49,15 @@ module Fog
|
|||
class Mock # :nodoc:all
|
||||
|
||||
def get_bucket_acl(bucket_name)
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
if acl = @data[:acls][:bucket][bucket_name]
|
||||
response.status = 200
|
||||
response.body = acl
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -60,7 +60,15 @@ module Fog
|
|||
class Mock # :nodoc:all
|
||||
|
||||
def get_object_acl(bucket_name, object_name)
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
if acl = @data[:acls][:object][bucket_name] && @data[:acls][:object][bucket_name][object_name]
|
||||
response.status = 200
|
||||
response.body = acl
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -44,6 +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
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
bucket = {
|
||||
|
|
|
@ -47,6 +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
|
||||
end
|
||||
data = parse_data(data)
|
||||
unless data[:body].is_a?(String)
|
||||
data[:body] = data[:body].read
|
||||
|
|
|
@ -87,10 +87,56 @@ module Fog
|
|||
class Mock
|
||||
include Utils
|
||||
|
||||
def self.acls(type)
|
||||
case type
|
||||
when 'private'
|
||||
@private ||= {
|
||||
"AccessControlList" => [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Grantee" => {"DisplayName" => "me", "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"}
|
||||
}
|
||||
],
|
||||
"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
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, region|
|
||||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:acls => {
|
||||
:bucket => {},
|
||||
:object => {}
|
||||
},
|
||||
:buckets => {}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -46,7 +46,15 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def get_bucket_acl(bucket_name)
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
if acl = @data[:acls][:bucket][bucket_name]
|
||||
response.status = 200
|
||||
response.body = acl
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -57,7 +57,15 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def get_object_acl(bucket_name, object_name)
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
if acl = @data[:acls][:object][bucket_name] && @data[:acls][:object][bucket_name][object_name]
|
||||
response.status = 200
|
||||
response.body = acl
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -40,6 +40,13 @@ 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
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
bucket = {
|
||||
|
|
|
@ -12,13 +12,14 @@ module Fog
|
|||
# * ID<~String>: id of owner
|
||||
# * DisplayName<~String>: display name of owner
|
||||
# * AccessControlList<~Array>:
|
||||
# * Grantee<~Hash>:
|
||||
# * 'DisplayName'<~String> - Display name of grantee
|
||||
# * scope<~Hash>:
|
||||
# * 'type'<~String> - 'UserById'
|
||||
# * 'ID'<~String> - Id of grantee
|
||||
# or
|
||||
# * 'type'<~String> - 'UserByEmail'
|
||||
# * 'EmailAddress'<~String> - Email address of grantee
|
||||
# or
|
||||
# * 'URI'<~String> - URI of group to grant access for
|
||||
# * 'type'<~String> - type of user to grant permission to
|
||||
# * Permission<~String> - Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
||||
def put_bucket_acl(bucket_name, acl)
|
||||
data =
|
||||
|
|
|
@ -42,6 +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
|
||||
end
|
||||
data = parse_data(data)
|
||||
unless data[:body].is_a?(String)
|
||||
data[:body] = data[:body].read
|
||||
|
|
|
@ -64,6 +64,48 @@ module Fog
|
|||
class Mock
|
||||
include Utils
|
||||
|
||||
def self.acls(type)
|
||||
case type
|
||||
when 'private'
|
||||
@private ||= {
|
||||
"AccessControlList"=> [
|
||||
{
|
||||
"Permission" => "FULL_CONTROL",
|
||||
"Scope" => {"ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById"}
|
||||
}
|
||||
],
|
||||
"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
|
||||
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
|
||||
when 'authenticated-read'
|
||||
@authenticated_read ||= begin
|
||||
authenticated_read = self.acls('private').dup
|
||||
authenticated_read['AccessControlList'] << {
|
||||
"Permission" => "READ",
|
||||
"Scope" => {"type" => "AllAuthenticatedUsers"}
|
||||
}
|
||||
authenticated_read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
|
|
Loading…
Reference in a new issue