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

[aws|storage] Add get/put bucket policy support

This commit is contained in:
Michael Linderman 2011-02-22 10:13:00 -08:00
parent 34f8c03cec
commit 051e8c0c5e
3 changed files with 69 additions and 0 deletions

View file

@ -24,6 +24,7 @@ module Fog
request :get_bucket_location
request :get_bucket_logging
request :get_bucket_object_versions
request :get_bucket_policy
request :get_bucket_versioning
request :get_bucket_website
request :get_object
@ -40,6 +41,7 @@ module Fog
request :put_bucket
request :put_bucket_acl
request :put_bucket_logging
request :put_bucket_policy
request :put_bucket_versioning
request :put_bucket_website
request :put_object

View file

@ -0,0 +1,37 @@
module Fog
module AWS
class Storage
class Real
# Get bucket policy for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get policy for
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash> - policy document
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETpolicy.html
def get_bucket_policy(bucket_name)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
response = request({
:expects => 200,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:idempotent => true,
:method => 'GET',
:query => {'policy' => nil}
})
response.body = JSON.parse(response.body) unless response.body.nil?
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module AWS
class Storage
class Real
# Change bucket policy for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to modify
# * policy<~Hash> - policy document
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTpolicy.html
def put_bucket_policy(bucket_name, policy)
request({
:body => policy.to_json,
:expects => 204,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => {'policy' => nil}
})
end
end
end
end
end