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:
parent
13d0495e77
commit
85c0c2fbf1
6 changed files with 53 additions and 9 deletions
|
@ -14,6 +14,14 @@ module Fog
|
||||||
|
|
||||||
attribute :creation_date, :aliases => 'CreationDate'
|
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
|
def destroy
|
||||||
requires :key
|
requires :key
|
||||||
connection.delete_bucket(key)
|
connection.delete_bucket(key)
|
||||||
|
@ -56,6 +64,9 @@ module Fog
|
||||||
def save
|
def save
|
||||||
requires :key
|
requires :key
|
||||||
options = {}
|
options = {}
|
||||||
|
if @acl
|
||||||
|
options['x-amz-acl'] = @acl
|
||||||
|
end
|
||||||
if @location
|
if @location
|
||||||
options['LocationConstraint'] = @location
|
options['LocationConstraint'] = @location
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,8 +70,11 @@ module Fog
|
||||||
|
|
||||||
def save(options = {})
|
def save(options = {})
|
||||||
requires :body, :directory, :key
|
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
|
if @acl
|
||||||
options['x-amz-acl'] = @acl
|
options['x-amz-acl'] ||= @acl
|
||||||
end
|
end
|
||||||
data = connection.put_object(directory.key, @key, @body, options)
|
data = connection.put_object(directory.key, @key, @body, options)
|
||||||
@etag = data.headers['ETag']
|
@etag = data.headers['ETag']
|
||||||
|
|
|
@ -8,17 +8,21 @@ module Fog
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * bucket_name<~String> - name of bucket to create
|
# * bucket_name<~String> - name of bucket to create
|
||||||
# * options<~Hash> - config arguments for bucket. Defaults to {}.
|
# * 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
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * status<~Integer> - 200
|
# * status<~Integer> - 200
|
||||||
|
#
|
||||||
|
# ==== API Reference
|
||||||
|
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
|
||||||
def put_bucket(bucket_name, options = {})
|
def put_bucket(bucket_name, options = {})
|
||||||
if options['LocationConstraint']
|
if location_constraint = options.delete('LocationConstraint')
|
||||||
data =
|
data =
|
||||||
<<-DATA
|
<<-DATA
|
||||||
<CreateBucketConfiguration>
|
<CreateBucketConfiguration>
|
||||||
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
|
<LocationConstraint>#{location_constraint}</LocationConstraint>
|
||||||
</CreateBucketConfiguration>
|
</CreateBucketConfiguration>
|
||||||
DATA
|
DATA
|
||||||
else
|
else
|
||||||
|
@ -27,7 +31,7 @@ DATA
|
||||||
request({
|
request({
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:body => data,
|
:body => data,
|
||||||
:headers => {},
|
:headers => options,
|
||||||
:idempotent => true,
|
:idempotent => true,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'PUT'
|
:method => 'PUT'
|
||||||
|
|
|
@ -14,6 +14,14 @@ module Fog
|
||||||
|
|
||||||
attribute :creation_date, :aliases => 'CreationDate'
|
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
|
def destroy
|
||||||
requires :key
|
requires :key
|
||||||
connection.delete_bucket(key)
|
connection.delete_bucket(key)
|
||||||
|
@ -34,6 +42,9 @@ module Fog
|
||||||
def save
|
def save
|
||||||
requires :key
|
requires :key
|
||||||
options = {}
|
options = {}
|
||||||
|
if @acl
|
||||||
|
options['x-amz-acl'] = @acl
|
||||||
|
end
|
||||||
if @location
|
if @location
|
||||||
options['LocationConstraint'] = @location
|
options['LocationConstraint'] = @location
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,14 @@ module Fog
|
||||||
attribute :size, :aliases => 'Size'
|
attribute :size, :aliases => 'Size'
|
||||||
attribute :storage_class, :aliases => 'StorageClass'
|
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
|
def body
|
||||||
@body ||= if last_modified && (file = collection.get(identity))
|
@body ||= if last_modified && (file = collection.get(identity))
|
||||||
file.body
|
file.body
|
||||||
|
@ -65,6 +73,12 @@ module Fog
|
||||||
|
|
||||||
def save(options = {})
|
def save(options = {})
|
||||||
requires :body, :directory, :key
|
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)
|
data = connection.put_object(directory.key, @key, @body, options)
|
||||||
@etag = data.headers['ETag']
|
@etag = data.headers['ETag']
|
||||||
true
|
true
|
||||||
|
|
|
@ -8,17 +8,18 @@ module Fog
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * bucket_name<~String> - name of bucket to create
|
# * bucket_name<~String> - name of bucket to create
|
||||||
# * options<~Hash> - config arguments for bucket. Defaults to {}.
|
# * 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
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * status<~Integer> - 200
|
# * status<~Integer> - 200
|
||||||
def put_bucket(bucket_name, options = {})
|
def put_bucket(bucket_name, options = {})
|
||||||
if options['LocationConstraint']
|
if location_constraint = options.delete('LocationConstraint')
|
||||||
data =
|
data =
|
||||||
<<-DATA
|
<<-DATA
|
||||||
<CreateBucketConfiguration>
|
<CreateBucketConfiguration>
|
||||||
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
|
<LocationConstraint>#{location_constraint}</LocationConstraint>
|
||||||
</CreateBucketConfiguration>
|
</CreateBucketConfiguration>
|
||||||
DATA
|
DATA
|
||||||
else
|
else
|
||||||
|
@ -27,7 +28,7 @@ DATA
|
||||||
request({
|
request({
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:body => data,
|
:body => data,
|
||||||
:headers => {},
|
:headers => options,
|
||||||
:idempotent => true,
|
:idempotent => true,
|
||||||
:host => "#{bucket_name}.#{@host}",
|
:host => "#{bucket_name}.#{@host}",
|
||||||
:method => 'PUT'
|
:method => 'PUT'
|
||||||
|
|
Loading…
Add table
Reference in a new issue