fog-internet-archive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.travis.yml +16 -0
- data/Gemfile +3 -0
- data/README.md +6 -0
- data/Rakefile +19 -0
- data/fog-internet-archive.gemspec +32 -0
- data/lib/fog/bin/internet_archive.rb +32 -0
- data/lib/fog/internet_archive.rb +1 -0
- data/lib/fog/internet_archive/core.rb +291 -0
- data/lib/fog/internet_archive/models/storage/directories.rb +39 -0
- data/lib/fog/internet_archive/models/storage/directory.rb +105 -0
- data/lib/fog/internet_archive/models/storage/file.rb +254 -0
- data/lib/fog/internet_archive/models/storage/files.rb +119 -0
- data/lib/fog/internet_archive/models/storage/ia_attributes.rb +36 -0
- data/lib/fog/internet_archive/parsers/storage/access_control_list.rb +42 -0
- data/lib/fog/internet_archive/parsers/storage/complete_multipart_upload.rb +20 -0
- data/lib/fog/internet_archive/parsers/storage/copy_object.rb +18 -0
- data/lib/fog/internet_archive/parsers/storage/cors_configuration.rb +38 -0
- data/lib/fog/internet_archive/parsers/storage/delete_multiple_objects.rb +45 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket.rb +58 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_lifecycle.rb +64 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_location.rb +16 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_logging.rb +36 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_website.rb +22 -0
- data/lib/fog/internet_archive/parsers/storage/get_request_payment.rb +16 -0
- data/lib/fog/internet_archive/parsers/storage/get_service.rb +28 -0
- data/lib/fog/internet_archive/parsers/storage/initiate_multipart_upload.rb +20 -0
- data/lib/fog/internet_archive/parsers/storage/list_multipart_uploads.rb +52 -0
- data/lib/fog/internet_archive/parsers/storage/list_parts.rb +36 -0
- data/lib/fog/internet_archive/requests/storage/abort_multipart_upload.rb +27 -0
- data/lib/fog/internet_archive/requests/storage/acl_utils.rb +60 -0
- data/lib/fog/internet_archive/requests/storage/complete_multipart_upload.rb +46 -0
- data/lib/fog/internet_archive/requests/storage/copy_object.rb +77 -0
- data/lib/fog/internet_archive/requests/storage/cors_utils.rb +39 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket.rb +42 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_cors.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_lifecycle.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_policy.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_website.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb +88 -0
- data/lib/fog/internet_archive/requests/storage/delete_object.rb +46 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket.rb +108 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_acl.rb +65 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_cors.rb +61 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_lifecycle.rb +35 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_location.rb +54 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_logging.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_policy.rb +31 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_website.rb +38 -0
- data/lib/fog/internet_archive/requests/storage/get_object.rb +163 -0
- data/lib/fog/internet_archive/requests/storage/get_object_acl.rb +72 -0
- data/lib/fog/internet_archive/requests/storage/get_object_http_url.rb +48 -0
- data/lib/fog/internet_archive/requests/storage/get_object_https_url.rb +30 -0
- data/lib/fog/internet_archive/requests/storage/get_object_torrent.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_object_url.rb +49 -0
- data/lib/fog/internet_archive/requests/storage/get_request_payment.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_service.rb +50 -0
- data/lib/fog/internet_archive/requests/storage/head_object.rb +57 -0
- data/lib/fog/internet_archive/requests/storage/initiate_multipart_upload.rb +42 -0
- data/lib/fog/internet_archive/requests/storage/list_multipart_uploads.rb +52 -0
- data/lib/fog/internet_archive/requests/storage/list_parts.rb +53 -0
- data/lib/fog/internet_archive/requests/storage/post_object_hidden_fields.rb +36 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket.rb +70 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_acl.rb +69 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb +47 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_lifecycle.rb +76 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_logging.rb +79 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_policy.rb +25 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_website.rb +59 -0
- data/lib/fog/internet_archive/requests/storage/put_object.rb +94 -0
- data/lib/fog/internet_archive/requests/storage/put_object_acl.rb +73 -0
- data/lib/fog/internet_archive/requests/storage/put_object_url.rb +43 -0
- data/lib/fog/internet_archive/requests/storage/put_request_payment.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/sync_clock.rb +24 -0
- data/lib/fog/internet_archive/requests/storage/upload_part.rb +39 -0
- data/lib/fog/internet_archive/signaturev4.rb +71 -0
- data/lib/fog/internet_archive/storage.rb +381 -0
- data/lib/fog/internet_archive/version.rb +5 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/console.rake +17 -0
- data/tasks/lint.rake +3 -0
- data/tasks/test.rake +7 -0
- data/tests/helper.rb +36 -0
- data/tests/helpers/collection_helper.rb +88 -0
- data/tests/helpers/formats_helper.rb +98 -0
- data/tests/helpers/formats_helper_tests.rb +106 -0
- data/tests/helpers/mock_helper.rb +13 -0
- data/tests/helpers/model_helper.rb +29 -0
- data/tests/helpers/responds_to_helper.rb +11 -0
- data/tests/helpers/schema_validator_tests.rb +101 -0
- data/tests/helpers/succeeds_helper.rb +9 -0
- data/tests/internet_archive/models/storage/directory_tests.rb +42 -0
- data/tests/internet_archive/models/storage/file_tests.rb +61 -0
- data/tests/internet_archive/models/storage/files_tests.rb +60 -0
- data/tests/internet_archive/models/storage/url_tests.rb +28 -0
- data/tests/internet_archive/requests/storage/acl_utils_tests.rb +209 -0
- data/tests/internet_archive/requests/storage/bucket_tests.rb +324 -0
- data/tests/internet_archive/requests/storage/cors_utils_tests.rb +108 -0
- data/tests/internet_archive/requests/storage/multipart_upload_tests.rb +132 -0
- data/tests/internet_archive/requests/storage/object_tests.rb +166 -0
- data/tests/internet_archive/signaturev4_tests.rb +41 -0
- data/tests/internet_archive/signed_params_tests.rb +5 -0
- data/tests/lorem.txt +1 -0
- metadata +322 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Create an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] name of bucket to create
|
8
|
+
# @option options [Hash] config arguments for bucket. Defaults to {}.
|
9
|
+
# @option options LocationConstraint [Symbol] sets the location for the bucket
|
10
|
+
# @option options x-amz-acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
11
|
+
#
|
12
|
+
# @return [Excon::Response] response:
|
13
|
+
# * status [Integer] 200
|
14
|
+
#
|
15
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
|
16
|
+
#
|
17
|
+
def put_bucket(bucket_name, options = {})
|
18
|
+
if location_constraint = options.delete('LocationConstraint')
|
19
|
+
data =
|
20
|
+
<<-DATA
|
21
|
+
<CreateBucketConfiguration>
|
22
|
+
<LocationConstraint>#{location_constraint}</LocationConstraint>
|
23
|
+
</CreateBucketConfiguration>
|
24
|
+
DATA
|
25
|
+
else
|
26
|
+
data = nil
|
27
|
+
end
|
28
|
+
request({
|
29
|
+
:expects => 200,
|
30
|
+
:body => data,
|
31
|
+
:headers => options,
|
32
|
+
:idempotent => true,
|
33
|
+
:host => "#{bucket_name}.#{@host}",
|
34
|
+
:method => 'PUT'
|
35
|
+
})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Mock # :nodoc:all
|
40
|
+
def put_bucket(bucket_name, options = {})
|
41
|
+
acl = options['x-amz-acl'] || 'private'
|
42
|
+
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
43
|
+
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
44
|
+
else
|
45
|
+
self.data[:acls][:bucket][bucket_name] = self.class.acls(acl)
|
46
|
+
end
|
47
|
+
|
48
|
+
response = Excon::Response.new
|
49
|
+
response.status = 200
|
50
|
+
bucket = {
|
51
|
+
:objects => {},
|
52
|
+
'Name' => bucket_name,
|
53
|
+
'CreationDate' => Time.now,
|
54
|
+
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
|
55
|
+
'Payer' => 'BucketOwner'
|
56
|
+
}
|
57
|
+
if options['LocationConstraint']
|
58
|
+
bucket['LocationConstraint'] = options['LocationConstraint']
|
59
|
+
else
|
60
|
+
bucket['LocationConstraint'] = nil
|
61
|
+
end
|
62
|
+
unless self.data[:buckets][bucket_name]
|
63
|
+
self.data[:buckets][bucket_name] = bucket
|
64
|
+
end
|
65
|
+
response
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
require 'fog/internet_archive/requests/storage/acl_utils'
|
6
|
+
|
7
|
+
# Change access control list for an S3 bucket
|
8
|
+
#
|
9
|
+
# @param bucket_name [String] name of bucket to modify
|
10
|
+
# @param acl [Hash]
|
11
|
+
# * Owner [Hash]:
|
12
|
+
# * ID [String]: id of owner
|
13
|
+
# * DisplayName [String]: display name of owner
|
14
|
+
# * AccessControlList [Array]:
|
15
|
+
# * Grantee [Hash]:
|
16
|
+
# * DisplayName [String] Display name of grantee
|
17
|
+
# * ID [String] Id of grantee
|
18
|
+
# or
|
19
|
+
# * EmailAddress [String] Email address of grantee
|
20
|
+
# or
|
21
|
+
# * URI [String] URI of group to grant access for
|
22
|
+
# * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
23
|
+
# * acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
24
|
+
#
|
25
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTacl.html
|
26
|
+
|
27
|
+
def put_bucket_acl(bucket_name, acl)
|
28
|
+
data = ""
|
29
|
+
headers = {}
|
30
|
+
|
31
|
+
if acl.is_a?(Hash)
|
32
|
+
data = Fog::Storage::InternetArchive.hash_to_acl(acl)
|
33
|
+
else
|
34
|
+
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
35
|
+
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
36
|
+
end
|
37
|
+
headers['x-amz-acl'] = acl
|
38
|
+
end
|
39
|
+
|
40
|
+
headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).strip
|
41
|
+
headers['Content-Type'] = 'application/json'
|
42
|
+
headers['Date'] = Fog::Time.now.to_date_header
|
43
|
+
|
44
|
+
request({
|
45
|
+
:body => data,
|
46
|
+
:expects => 200,
|
47
|
+
:headers => headers,
|
48
|
+
:host => "#{bucket_name}.#{@host}",
|
49
|
+
:method => 'PUT',
|
50
|
+
:query => {'acl' => nil}
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Mock
|
56
|
+
def put_bucket_acl(bucket_name, acl)
|
57
|
+
if acl.is_a?(Hash)
|
58
|
+
self.data[:acls][:bucket][bucket_name] = Fog::Storage::InternetArchive.hash_to_acl(acl)
|
59
|
+
else
|
60
|
+
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
61
|
+
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
62
|
+
end
|
63
|
+
self.data[:acls][:bucket][bucket_name] = acl
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
require 'fog/internet_archive/requests/storage/cors_utils'
|
6
|
+
|
7
|
+
# Sets the cors configuration for your bucket. If the configuration exists, Amazon S3 replaces it.
|
8
|
+
#
|
9
|
+
# @param bucket_name [String] name of bucket to modify
|
10
|
+
# @param cors [Hash]
|
11
|
+
# * CORSConfiguration [Array]:
|
12
|
+
# * ID [String]: A unique identifier for the rule.
|
13
|
+
# * AllowedMethod [String]: An HTTP method that you want to allow the origin to execute.
|
14
|
+
# * AllowedOrigin [String]: An origin that you want to allow cross-domain requests from.
|
15
|
+
# * AllowedHeader [String]: Specifies which headers are allowed in a pre-flight OPTIONS request via the Access-Control-Request-Headers header.
|
16
|
+
# * MaxAgeSeconds [String]: The time in seconds that your browser is to cache the preflight response for the specified resource.
|
17
|
+
# * ExposeHeader [String]: One or more headers in the response that you want customers to be able to access from their applications.
|
18
|
+
#
|
19
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTcors.html
|
20
|
+
|
21
|
+
def put_bucket_cors(bucket_name, cors)
|
22
|
+
data = Fog::Storage::InternetArchive.hash_to_cors(cors)
|
23
|
+
|
24
|
+
headers = {}
|
25
|
+
headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).strip
|
26
|
+
headers['Content-Type'] = 'application/json'
|
27
|
+
headers['Date'] = Fog::Time.now.to_date_header
|
28
|
+
|
29
|
+
request({
|
30
|
+
:body => data,
|
31
|
+
:expects => 200,
|
32
|
+
:headers => headers,
|
33
|
+
:host => "#{bucket_name}.#{@host}",
|
34
|
+
:method => 'PUT',
|
35
|
+
:query => {'cors' => nil}
|
36
|
+
})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Mock
|
41
|
+
def put_bucket_cors(bucket_name, cors)
|
42
|
+
self.data[:cors][:bucket][bucket_name] = Fog::Storage::InternetArchive.hash_to_cors(cors)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Change lifecycle configuration for an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] name of bucket to set lifecycle configuration for
|
8
|
+
# * lifecycle [Hash]:
|
9
|
+
# * Rules [Array] object expire rules
|
10
|
+
# * ID [String] Unique identifier for the rule
|
11
|
+
# * Prefix [String] Prefix identifying one or more objects to which the rule applies
|
12
|
+
# * Enabled [Boolean] if rule is currently being applied
|
13
|
+
# * Expiration [Hash] Container for the object expiration rule.
|
14
|
+
# * Days [Integer] lifetime, in days, of the objects that are subject to the rule
|
15
|
+
# * Date [Date] Indicates when the specific rule take effect.
|
16
|
+
# The date value must conform to the ISO 8601 format. The time is always midnight UTC.
|
17
|
+
# * Transition [Hash] Container for the transition rule that describes when objects transition
|
18
|
+
# to the Glacier storage class
|
19
|
+
# * Days [Integer] lifetime, in days, of the objects that are subject to the rule
|
20
|
+
# * Date [Date] Indicates when the specific rule take effect.
|
21
|
+
# The date value must conform to the ISO 8601 format. The time is always midnight UTC.
|
22
|
+
# * StorageClass [String] Indicates the Amazon S3 storage class to which you want the object
|
23
|
+
# to transition to.
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTlifecycle.html
|
27
|
+
#
|
28
|
+
def put_bucket_lifecycle(bucket_name, lifecycle)
|
29
|
+
builder = Nokogiri::XML::Builder.new do
|
30
|
+
LifecycleConfiguration {
|
31
|
+
lifecycle['Rules'].each do |rule|
|
32
|
+
Rule {
|
33
|
+
ID rule['ID']
|
34
|
+
Prefix rule['Prefix']
|
35
|
+
Status rule['Enabled'] ? 'Enabled' : 'Disabled'
|
36
|
+
unless (rule['Expiration'] or rule['Transition'])
|
37
|
+
Expiration { Days rule['Days'] }
|
38
|
+
else
|
39
|
+
if rule['Expiration']
|
40
|
+
if rule['Expiration']['Days']
|
41
|
+
Expiration { Days rule['Expiration']['Days'] }
|
42
|
+
elsif rule['Expiration']['Date']
|
43
|
+
Expiration { Date rule['Expiration']['Date'].is_a?(Time) ? rule['Expiration']['Date'].utc.iso8601 : Time.parse(rule['Expiration']['Date']).utc.iso8601 }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
if rule['Transition']
|
47
|
+
Transition {
|
48
|
+
if rule['Transition']['Days']
|
49
|
+
Days rule['Transition']['Days']
|
50
|
+
elsif rule['Transition']['Date']
|
51
|
+
Date rule['Transition']['Date'].is_a?(Time) ? time.utc.iso8601 : Time.parse(time).utc.iso8601
|
52
|
+
end
|
53
|
+
StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass']
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
}
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
body = builder.to_xml
|
62
|
+
body.gsub! /<([^<>]+)\/>/, '<\1></\1>'
|
63
|
+
request({
|
64
|
+
:body => body,
|
65
|
+
:expects => 200,
|
66
|
+
:headers => {'Content-MD5' => Base64.encode64(Digest::MD5.digest(body)).chomp!,
|
67
|
+
'Content-Type' => 'application/xml'},
|
68
|
+
:host => "#{bucket_name}.#{@host}",
|
69
|
+
:method => 'PUT',
|
70
|
+
:query => {'lifecycle' => nil}
|
71
|
+
})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Change logging status for an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] name of bucket to modify
|
8
|
+
# @param logging_status [Hash]:
|
9
|
+
# * Owner [Hash]:
|
10
|
+
# * ID [String]: id of owner
|
11
|
+
# * DisplayName [String]: display name of owner
|
12
|
+
# * AccessControlList [Array]:
|
13
|
+
# * Grantee [Hash]:
|
14
|
+
# * DisplayName [String] Display name of grantee
|
15
|
+
# * ID [String] Id of grantee
|
16
|
+
# or
|
17
|
+
# * EmailAddress [String] Email address of grantee
|
18
|
+
# or
|
19
|
+
# * URI [String] URI of group to grant access for
|
20
|
+
# * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
21
|
+
#
|
22
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTlogging.html
|
23
|
+
|
24
|
+
def put_bucket_logging(bucket_name, logging_status)
|
25
|
+
if logging_status['LoggingEnabled'].empty?
|
26
|
+
data =
|
27
|
+
<<-DATA
|
28
|
+
<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />
|
29
|
+
DATA
|
30
|
+
else
|
31
|
+
data =
|
32
|
+
<<-DATA
|
33
|
+
<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01">
|
34
|
+
<LoggingEnabled>
|
35
|
+
<TargetBucket>#{logging_status['LoggingEnabled']['TargetBucket']}</TargetBucket>
|
36
|
+
<TargetPrefix>#{logging_status['LoggingEnabled']['TargetBucket']}</TargetPrefix>
|
37
|
+
<TargetGrants>
|
38
|
+
DATA
|
39
|
+
|
40
|
+
acl['AccessControlList'].each do |grant|
|
41
|
+
data << " <Grant>"
|
42
|
+
type = case grant['Grantee'].keys.sort
|
43
|
+
when ['DisplayName', 'ID']
|
44
|
+
'CanonicalUser'
|
45
|
+
when ['EmailAddress']
|
46
|
+
'AmazonCustomerByEmail'
|
47
|
+
when ['URI']
|
48
|
+
'Group'
|
49
|
+
end
|
50
|
+
data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">"
|
51
|
+
for key, value in grant['Grantee']
|
52
|
+
data << " <#{key}>#{value}</#{key}>"
|
53
|
+
end
|
54
|
+
data << " </Grantee>"
|
55
|
+
data << " <Permission>#{grant['Permission']}</Permission>"
|
56
|
+
data << " </Grant>"
|
57
|
+
end
|
58
|
+
|
59
|
+
data <<
|
60
|
+
<<-DATA
|
61
|
+
</TargetGrants>
|
62
|
+
</LoggingEnabled>
|
63
|
+
</BucketLoggingStatus>
|
64
|
+
DATA
|
65
|
+
end
|
66
|
+
|
67
|
+
request({
|
68
|
+
:body => data,
|
69
|
+
:expects => 200,
|
70
|
+
:headers => {},
|
71
|
+
:host => "#{bucket_name}.#{@host}",
|
72
|
+
:method => 'PUT',
|
73
|
+
:query => {'logging' => nil}
|
74
|
+
})
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Change bucket policy for an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] name of bucket to modify
|
8
|
+
# @param policy [Hash] policy document
|
9
|
+
#
|
10
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTpolicy.html
|
11
|
+
|
12
|
+
def put_bucket_policy(bucket_name, policy)
|
13
|
+
request({
|
14
|
+
:body => Fog::JSON.encode(policy),
|
15
|
+
:expects => 204,
|
16
|
+
:headers => {},
|
17
|
+
:host => "#{bucket_name}.#{@host}",
|
18
|
+
:method => 'PUT',
|
19
|
+
:query => {'policy' => nil}
|
20
|
+
})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Change website configuration for an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] name of bucket to modify
|
8
|
+
# @param suffix [String] suffix to append to requests for the bucket
|
9
|
+
# @param options [Hash]
|
10
|
+
# @option options key [String] key to use for 4XX class errors
|
11
|
+
#
|
12
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTwebsite.html
|
13
|
+
|
14
|
+
def put_bucket_website(bucket_name, suffix, options = {})
|
15
|
+
data =
|
16
|
+
<<-DATA
|
17
|
+
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
18
|
+
<IndexDocument>
|
19
|
+
<Suffix>#{suffix}</Suffix>
|
20
|
+
</IndexDocument>
|
21
|
+
DATA
|
22
|
+
|
23
|
+
if options[:key]
|
24
|
+
data <<
|
25
|
+
<<-DATA
|
26
|
+
<ErrorDocument>
|
27
|
+
<Key>#{options[:key]}</Key>
|
28
|
+
</ErrorDocument>
|
29
|
+
DATA
|
30
|
+
end
|
31
|
+
|
32
|
+
data << '</WebsiteConfiguration>'
|
33
|
+
request({
|
34
|
+
:body => data,
|
35
|
+
:expects => 200,
|
36
|
+
:headers => {},
|
37
|
+
:host => "#{bucket_name}.#{@host}",
|
38
|
+
:method => 'PUT',
|
39
|
+
:query => {'website' => nil}
|
40
|
+
})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Mock # :nodoc:all
|
45
|
+
def put_bucket_website(bucket_name, suffix, options = {})
|
46
|
+
response = Excon::Response.new
|
47
|
+
if self.data[:buckets][bucket_name]
|
48
|
+
response.status = 200
|
49
|
+
else
|
50
|
+
response.status = 404
|
51
|
+
raise(Excon::Errors.status_error({:expects => 200}, response))
|
52
|
+
end
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class InternetArchive
|
4
|
+
class Real
|
5
|
+
# Create an object in an S3 bucket
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] Name of bucket to create object in
|
8
|
+
# @param object_name [String] Name of object to create
|
9
|
+
# @param data [File||String] File or String to create object from
|
10
|
+
# @param options [Hash]
|
11
|
+
# @option options Cache-Control [String] Caching behaviour
|
12
|
+
# @option options Content-Disposition [String] Presentational information for the object
|
13
|
+
# @option options Content-Encoding [String] Encoding of object data
|
14
|
+
# @option options Content-Length [String] Size of object in bytes (defaults to object.read.length)
|
15
|
+
# @option options Content-MD5 [String] Base64 encoded 128-bit MD5 digest of message
|
16
|
+
# @option options Content-Type [String] Standard MIME type describing contents (defaults to MIME::Types.of.first)
|
17
|
+
# @option options Expires [String] Cache expiry
|
18
|
+
# @option options x-amz-acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
19
|
+
# @option options x-amz-storage-class [String] Default is 'STANDARD', set to 'REDUCED_REDUNDANCY' for non-critical, reproducable data
|
20
|
+
# @option options x-amz-meta-#{name} Headers to be returned with object, note total size of request without body must be less than 8 KB.
|
21
|
+
#
|
22
|
+
# @return [Excon::Response] response:
|
23
|
+
# * headers [Hash]:
|
24
|
+
# * ETag [String] etag of new object
|
25
|
+
#
|
26
|
+
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html
|
27
|
+
|
28
|
+
def put_object(bucket_name, object_name, data, options = {})
|
29
|
+
data = Fog::Storage.parse_data(data)
|
30
|
+
headers = data[:headers].merge!(options)
|
31
|
+
request({
|
32
|
+
:body => data[:body],
|
33
|
+
:expects => 200,
|
34
|
+
:headers => headers,
|
35
|
+
:host => "#{bucket_name}.#{@host}",
|
36
|
+
:idempotent => true,
|
37
|
+
:method => 'PUT',
|
38
|
+
:path => CGI.escape(object_name)
|
39
|
+
})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Mock # :nodoc:all
|
44
|
+
def put_object(bucket_name, object_name, data, options = {})
|
45
|
+
acl = options['x-amz-acl'] || 'private'
|
46
|
+
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
47
|
+
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
48
|
+
else
|
49
|
+
self.data[:acls][:object][bucket_name] ||= {}
|
50
|
+
self.data[:acls][:object][bucket_name][object_name] = self.class.acls(acl)
|
51
|
+
end
|
52
|
+
|
53
|
+
data = Fog::Storage.parse_data(data)
|
54
|
+
unless data[:body].is_a?(String)
|
55
|
+
data[:body] = data[:body].read
|
56
|
+
end
|
57
|
+
response = Excon::Response.new
|
58
|
+
if (bucket = self.data[:buckets][bucket_name])
|
59
|
+
response.status = 200
|
60
|
+
object = {
|
61
|
+
:body => data[:body],
|
62
|
+
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
|
63
|
+
'ETag' => Digest::MD5.hexdigest(data[:body]),
|
64
|
+
'Key' => object_name,
|
65
|
+
'Last-Modified' => Fog::Time.now.to_date_header,
|
66
|
+
'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'],
|
67
|
+
}
|
68
|
+
|
69
|
+
for key, value in options
|
70
|
+
case key
|
71
|
+
when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-MD5', 'Expires', /^x-amz-meta-/, /^x-archive-/
|
72
|
+
object[key] = value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
bucket[:objects][object_name] = [object]
|
77
|
+
|
78
|
+
response.headers = {
|
79
|
+
'Content-Length' => object['Content-Length'],
|
80
|
+
'Content-Type' => object['Content-Type'],
|
81
|
+
'ETag' => object['ETag'],
|
82
|
+
'Last-Modified' => object['Last-Modified'],
|
83
|
+
}
|
84
|
+
|
85
|
+
else
|
86
|
+
response.status = 404
|
87
|
+
raise(Excon::Errors.status_error({:expects => 200}, response))
|
88
|
+
end
|
89
|
+
response
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|