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:
parent
34f8c03cec
commit
051e8c0c5e
3 changed files with 69 additions and 0 deletions
|
@ -24,6 +24,7 @@ module Fog
|
||||||
request :get_bucket_location
|
request :get_bucket_location
|
||||||
request :get_bucket_logging
|
request :get_bucket_logging
|
||||||
request :get_bucket_object_versions
|
request :get_bucket_object_versions
|
||||||
|
request :get_bucket_policy
|
||||||
request :get_bucket_versioning
|
request :get_bucket_versioning
|
||||||
request :get_bucket_website
|
request :get_bucket_website
|
||||||
request :get_object
|
request :get_object
|
||||||
|
@ -40,6 +41,7 @@ module Fog
|
||||||
request :put_bucket
|
request :put_bucket
|
||||||
request :put_bucket_acl
|
request :put_bucket_acl
|
||||||
request :put_bucket_logging
|
request :put_bucket_logging
|
||||||
|
request :put_bucket_policy
|
||||||
request :put_bucket_versioning
|
request :put_bucket_versioning
|
||||||
request :put_bucket_website
|
request :put_bucket_website
|
||||||
request :put_object
|
request :put_object
|
||||||
|
|
37
lib/fog/storage/requests/aws/get_bucket_policy.rb
Normal file
37
lib/fog/storage/requests/aws/get_bucket_policy.rb
Normal 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
|
30
lib/fog/storage/requests/aws/put_bucket_policy.rb
Normal file
30
lib/fog/storage/requests/aws/put_bucket_policy.rb
Normal 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
|
||||||
|
|
Loading…
Reference in a new issue