mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|storage] add website configuration methods
This commit is contained in:
parent
e72831d99b
commit
34f8c03cec
7 changed files with 156 additions and 4 deletions
|
@ -3,7 +3,7 @@ PATH
|
|||
specs:
|
||||
fog (0.5.3)
|
||||
builder
|
||||
excon (>= 0.5.2)
|
||||
excon (>= 0.5.5)
|
||||
formatador (>= 0.0.16)
|
||||
json
|
||||
mime-types
|
||||
|
@ -15,7 +15,7 @@ GEM
|
|||
remote: http://rubygems.org/
|
||||
specs:
|
||||
builder (3.0.0)
|
||||
excon (0.5.2)
|
||||
excon (0.5.5)
|
||||
formatador (0.0.16)
|
||||
json (1.5.1)
|
||||
mime-types (1.16)
|
||||
|
|
|
@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|||
## List your runtime dependencies here. Runtime dependencies are those
|
||||
## that are needed for an end user to actually USE your code.
|
||||
s.add_dependency('builder')
|
||||
s.add_dependency('excon', '>=0.5.2')
|
||||
s.add_dependency('excon', '>=0.5.5')
|
||||
s.add_dependency('formatador', '>=0.0.16')
|
||||
s.add_dependency('json')
|
||||
s.add_dependency('mime-types')
|
||||
|
|
|
@ -17,6 +17,7 @@ module Fog
|
|||
request :complete_multipart_upload
|
||||
request :copy_object
|
||||
request :delete_bucket
|
||||
request :delete_bucket_website
|
||||
request :delete_object
|
||||
request :get_bucket
|
||||
request :get_bucket_acl
|
||||
|
@ -24,6 +25,7 @@ module Fog
|
|||
request :get_bucket_logging
|
||||
request :get_bucket_object_versions
|
||||
request :get_bucket_versioning
|
||||
request :get_bucket_website
|
||||
request :get_object
|
||||
request :get_object_acl
|
||||
request :get_object_torrent
|
||||
|
@ -39,6 +41,7 @@ module Fog
|
|||
request :put_bucket_acl
|
||||
request :put_bucket_logging
|
||||
request :put_bucket_versioning
|
||||
request :put_bucket_website
|
||||
request :put_object
|
||||
request :put_object_acl
|
||||
request :put_object_url
|
||||
|
@ -312,7 +315,7 @@ DATA
|
|||
canonical_resource << params[:path].to_s
|
||||
canonical_resource << '?'
|
||||
for key in (params[:query] || {}).keys.sort
|
||||
if %w{acl location logging notification partNumber policy requestPayment torrent uploadId uploads versionId versioning versions}.include?(key)
|
||||
if %w{acl location logging notification partNumber policy requestPayment torrent uploadId uploads versionId versioning versions website}.include?(key)
|
||||
canonical_resource << "#{key}#{"=#{params[:query][key]}" unless params[:query][key].nil?}&"
|
||||
end
|
||||
end
|
||||
|
|
26
lib/fog/storage/parsers/aws/get_bucket_website.rb
Normal file
26
lib/fog/storage/parsers/aws/get_bucket_website.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module Storage
|
||||
|
||||
class GetBucketWebsite < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'ErrorDocument' => {}, 'IndexDocument' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Key'
|
||||
@response['ErrorDocument'][name] = @value
|
||||
when 'Suffix'
|
||||
@response['IndexDocument'][name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/storage/requests/aws/delete_bucket_website.rb
Normal file
32
lib/fog/storage/requests/aws/delete_bucket_website.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Storage
|
||||
class Real
|
||||
|
||||
# Delete website configuration for a bucket
|
||||
#
|
||||
# ==== Parameters
|
||||
# * bucket_name<~String> - name of bucket to delete website configuration from
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * status<~Integer> - 204
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketDELETEwebsite.html
|
||||
|
||||
def delete_bucket_website(bucket_name)
|
||||
request({
|
||||
:expects => 204,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'DELETE',
|
||||
:query => {'website' => nil}
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/storage/requests/aws/get_bucket_website.rb
Normal file
42
lib/fog/storage/requests/aws/get_bucket_website.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Storage
|
||||
class Real
|
||||
|
||||
require 'fog/storage/parsers/aws/get_bucket_website'
|
||||
|
||||
# Get website configuration for an S3 bucket
|
||||
#
|
||||
# ==== Parameters
|
||||
# * bucket_name<~String> - name of bucket to get website configuration for
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * IndexDocument<~Hash>
|
||||
# * Suffix<~String> - Suffix appended when directory is requested
|
||||
# * ErrorDocument<~Hash>
|
||||
# * Key<~String> - Object key to return for 4XX class errors
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETwebsite.html
|
||||
|
||||
def get_bucket_website(bucket_name)
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::AWS::Storage::GetBucketWebsite.new,
|
||||
:query => {'website' => nil}
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
49
lib/fog/storage/requests/aws/put_bucket_website.rb
Normal file
49
lib/fog/storage/requests/aws/put_bucket_website.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Storage
|
||||
class Real
|
||||
|
||||
# Change website configuration for an S3 bucket
|
||||
#
|
||||
# ==== Parameters
|
||||
# * bucket_name<~String> - name of bucket to modify
|
||||
# * suffix<~String> - suffix to append to requests for the bucket
|
||||
# * options<~Hash>
|
||||
# * key<~String> - key to use for 4XX class errors
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTwebsite.html
|
||||
|
||||
def put_bucket_website(bucket_name, suffix, options = {})
|
||||
data =
|
||||
<<-DATA
|
||||
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<IndexDocument>
|
||||
<Suffix>#{suffix}</Suffix>
|
||||
</IndexDocument>
|
||||
DATA
|
||||
|
||||
if options[:key]
|
||||
data <<
|
||||
<<-DATA
|
||||
<ErrorDocument>
|
||||
<Key>#{options[:key]}</Key>
|
||||
</ErrorDocument>
|
||||
DATA
|
||||
end
|
||||
|
||||
data << '</WebsiteConfiguration>'
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
:query => {'website' => nil}
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue