s3batch 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/s3batch/batch_upload.rb +6 -4
- data/lib/s3batch/happening_patch.rb +1 -0
- data/lib/s3batch/multi_delete.rb +3 -3
- data/lib/s3batch/website_enabler.rb +35 -0
- data/lib/s3batch.rb +5 -1
- metadata +17 -5
data/lib/s3batch/batch_upload.rb
CHANGED
@@ -39,7 +39,7 @@ module S3Batch
|
|
39
39
|
|
40
40
|
def self.run s3id, s3key, bucket, dir, pattern
|
41
41
|
EM.run {
|
42
|
-
items = Upload.new bucket, dir, pattern, :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http', :permissions => 'public-read'
|
42
|
+
items = S3Batch::Upload.new bucket, dir, pattern, :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http', :permissions => 'public-read'
|
43
43
|
items.upload
|
44
44
|
}
|
45
45
|
end
|
@@ -58,7 +58,7 @@ module S3Batch
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def check_md5_and_upload keys
|
61
|
-
manager = TaskManager.new
|
61
|
+
manager = S3Batch::TaskManager.new
|
62
62
|
on_error = Proc.new {|response| puts "An error occured: #{response.response_header.status}"; manager.remove; }
|
63
63
|
on_success = Proc.new {|response| manager.remove; }
|
64
64
|
|
@@ -72,7 +72,10 @@ module S3Batch
|
|
72
72
|
if keys[key] != md5
|
73
73
|
puts "uploading #{key} to #{@bucket}"
|
74
74
|
item = Happening::S3::Item.new(@bucket, key, @options)
|
75
|
-
|
75
|
+
headers = {}
|
76
|
+
type = MIME::Types.type_for(key).first
|
77
|
+
headers['Content-Type'] = type if type
|
78
|
+
item.put(content, :on_error => on_error, :on_success => on_success, :headers => headers)
|
76
79
|
manager.add
|
77
80
|
else
|
78
81
|
puts "ignore #{key}, no change"
|
@@ -81,6 +84,5 @@ module S3Batch
|
|
81
84
|
|
82
85
|
manager.end_adding
|
83
86
|
end
|
84
|
-
|
85
87
|
end
|
86
88
|
end
|
@@ -7,6 +7,7 @@ module Happening
|
|
7
7
|
def canonical_request_description(method, path, headers = {}, expires = nil)
|
8
8
|
description = old_canonical_request_description(method, path, headers, expires)
|
9
9
|
description << '?delete' if path[/[&?]delete($|&|=)/]
|
10
|
+
description << '?website' if path[/[&?]website($|&|=)/]
|
10
11
|
description
|
11
12
|
end
|
12
13
|
end
|
data/lib/s3batch/multi_delete.rb
CHANGED
@@ -26,12 +26,12 @@ module S3Batch
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def run s3id, s3key, bucket, keys
|
29
|
+
def self.run s3id, s3key, bucket, keys
|
30
30
|
EM.run {
|
31
31
|
on_error = Proc.new {|response| puts "An error occured: #{response.response}"; EM.stop }
|
32
32
|
on_success = Proc.new {|response| puts "Deleted!"; EM.stop }
|
33
|
-
items = Delete.new bucket, keys, :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http'
|
34
|
-
items.delete(:on_error => on_error, :on_success => on_success)
|
33
|
+
items = S3Batch::Delete.new bucket, keys, :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http'
|
34
|
+
items.delete(:on_error => on_error, :on_success => on_success)
|
35
35
|
}
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module S3Batch
|
2
|
+
class WebsiteEnabler < Happening::S3::Item
|
3
|
+
def path(with_bucket=true)
|
4
|
+
with_bucket ? "/#{bucket}/?website" : "/?website"
|
5
|
+
end
|
6
|
+
|
7
|
+
def enable index_doc, error_doc, request_options = {}, &blk
|
8
|
+
data =<<EOF
|
9
|
+
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
10
|
+
<IndexDocument>
|
11
|
+
<Suffix>#{index_doc}</Suffix>
|
12
|
+
</IndexDocument>
|
13
|
+
<ErrorDocument>
|
14
|
+
<Key>#{error_doc}</Key>
|
15
|
+
</ErrorDocument>
|
16
|
+
</WebsiteConfiguration>
|
17
|
+
EOF
|
18
|
+
|
19
|
+
md5 = Base64.encode64(Digest::MD5.digest(data)).strip
|
20
|
+
headers = aws.sign("PUT", path, {"Content-MD5" => md5})
|
21
|
+
request_options[:on_success] = blk if blk
|
22
|
+
request_options.update(:headers => headers, :data => data)
|
23
|
+
Happening::S3::Request.new(:put, url, {:ssl => options[:ssl]}.update(request_options)).execute
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.run s3id, s3key, bucket, index_doc = "index.html", error_doc = "404.html"
|
27
|
+
EM.run {
|
28
|
+
on_error = Proc.new {|response| puts "An error occured: #{response.response}"; EM.stop; }
|
29
|
+
on_success = Proc.new {|response| puts "Enabled #{response.response}"; EM.stop; }
|
30
|
+
item = S3Batch::WebsiteEnabler.new(bucket, "NO_USE", :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http')
|
31
|
+
item.enable(index_doc, error_doc, :on_error => on_error, :on_success => on_success)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/s3batch.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'happening'
|
2
2
|
require 'nokogiri'
|
3
|
+
require 'mime/types'
|
3
4
|
|
4
5
|
require File.expand_path(File.dirname(__FILE__) + '/s3batch/happening_patch')
|
5
6
|
require File.expand_path(File.dirname(__FILE__) + '/s3batch/multi_delete')
|
6
7
|
require File.expand_path(File.dirname(__FILE__) + '/s3batch/batch_upload')
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/s3batch/website_enabler')
|
7
9
|
|
8
10
|
#ruby s3batch.rb S3ID S3KEY BUCKET DIR
|
9
11
|
if $0 == __FILE__
|
@@ -13,6 +15,8 @@ if $0 == __FILE__
|
|
13
15
|
dir = ARGV[3]
|
14
16
|
pattern = ARGV[4] || "**/*"
|
15
17
|
|
16
|
-
S3Batch::
|
18
|
+
S3Batch::WebsiteEnabler.run s3id, s3key, bucket
|
19
|
+
#S3Batch::Upload.run s3id, s3key, bucket, dir, pattern
|
20
|
+
#S3Batch::Delete.run s3id, s3key, bucket, [dir]
|
17
21
|
end
|
18
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: happening
|
16
|
-
requirement: &
|
16
|
+
requirement: &72777590 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *72777590
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &72777260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *72777260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mime-types
|
38
|
+
requirement: &72701030 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *72701030
|
36
47
|
description:
|
37
48
|
email:
|
38
49
|
- yong@intridea.com
|
@@ -42,6 +53,7 @@ extra_rdoc_files: []
|
|
42
53
|
files:
|
43
54
|
- lib/s3batch/multi_delete.rb
|
44
55
|
- lib/s3batch/batch_upload.rb
|
56
|
+
- lib/s3batch/website_enabler.rb
|
45
57
|
- lib/s3batch/happening_patch.rb
|
46
58
|
- lib/s3batch.rb
|
47
59
|
homepage: http://github.com/yong/s3batch
|