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

[aws&google|storage] cleanup/fixes for bucket acl

This commit is contained in:
geemus 2010-10-29 16:38:17 -07:00
parent 13d0495e77
commit 85c0c2fbf1
6 changed files with 53 additions and 9 deletions

View file

@ -14,6 +14,14 @@ module Fog
attribute :creation_date, :aliases => 'CreationDate'
def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
unless valid_acls.include?(new_acl)
raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
end
@acl = new_acl
end
def destroy
requires :key
connection.delete_bucket(key)
@ -56,6 +64,9 @@ module Fog
def save
requires :key
options = {}
if @acl
options['x-amz-acl'] = @acl
end
if @location
options['LocationConstraint'] = @location
end

View file

@ -70,8 +70,11 @@ module Fog
def save(options = {})
requires :body, :directory, :key
if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end
if @acl
options['x-amz-acl'] = @acl
options['x-amz-acl'] ||= @acl
end
data = connection.put_object(directory.key, @key, @body, options)
@etag = data.headers['ETag']

View file

@ -8,17 +8,21 @@ module Fog
# ==== Parameters
# * bucket_name<~String> - name of bucket to create
# * options<~Hash> - config arguments for bucket. Defaults to {}.
# * :location_constraint<~Symbol> - sets the location for the bucket
# * 'LocationConstraint'<~Symbol> - sets the location for the bucket
# * 'x-amz-acl'<~String> - Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
#
# ==== Returns
# * response<~Excon::Response>:
# * status<~Integer> - 200
#
# ==== API Reference
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
def put_bucket(bucket_name, options = {})
if options['LocationConstraint']
if location_constraint = options.delete('LocationConstraint')
data =
<<-DATA
<CreateBucketConfiguration>
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
<LocationConstraint>#{location_constraint}</LocationConstraint>
</CreateBucketConfiguration>
DATA
else
@ -27,7 +31,7 @@ DATA
request({
:expects => 200,
:body => data,
:headers => {},
:headers => options,
:idempotent => true,
:host => "#{bucket_name}.#{@host}",
:method => 'PUT'

View file

@ -14,6 +14,14 @@ module Fog
attribute :creation_date, :aliases => 'CreationDate'
def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
unless valid_acls.include?(new_acl)
raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
end
@acl = new_acl
end
def destroy
requires :key
connection.delete_bucket(key)
@ -34,6 +42,9 @@ module Fog
def save
requires :key
options = {}
if @acl
options['x-amz-acl'] = @acl
end
if @location
options['LocationConstraint'] = @location
end

View file

@ -17,6 +17,14 @@ module Fog
attribute :size, :aliases => 'Size'
attribute :storage_class, :aliases => 'StorageClass'
def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
unless valid_acls.include?(new_acl)
raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
end
@acl = new_acl
end
def body
@body ||= if last_modified && (file = collection.get(identity))
file.body
@ -65,6 +73,12 @@ module Fog
def save(options = {})
requires :body, :directory, :key
if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end
if @acl
options['x-amz-acl'] ||= @acl
end
data = connection.put_object(directory.key, @key, @body, options)
@etag = data.headers['ETag']
true

View file

@ -8,17 +8,18 @@ module Fog
# ==== Parameters
# * bucket_name<~String> - name of bucket to create
# * options<~Hash> - config arguments for bucket. Defaults to {}.
# * :location_constraint<~Symbol> - sets the location for the bucket
# * 'LocationConstraint'<~Symbol> - sets the location for the bucket
# * 'x-amz-acl'<~String> - Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
#
# ==== Returns
# * response<~Excon::Response>:
# * status<~Integer> - 200
def put_bucket(bucket_name, options = {})
if options['LocationConstraint']
if location_constraint = options.delete('LocationConstraint')
data =
<<-DATA
<CreateBucketConfiguration>
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
<LocationConstraint>#{location_constraint}</LocationConstraint>
</CreateBucketConfiguration>
DATA
else
@ -27,7 +28,7 @@ DATA
request({
:expects => 200,
:body => data,
:headers => {},
:headers => options,
:idempotent => true,
:host => "#{bucket_name}.#{@host}",
:method => 'PUT'