steamcannon-s3 0.3.2.1 → 0.3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +5 -5
- data/Rakefile +1 -0
- data/lib/s3.rb +1 -0
- data/lib/s3/bucket.rb +1 -1
- data/lib/s3/connection.rb +12 -17
- data/lib/s3/object.rb +3 -4
- data/lib/s3/request.rb +11 -0
- data/lib/s3/service.rb +2 -2
- data/lib/s3/version.rb +1 -1
- data/s3.gemspec +2 -2
- data/test/test_helper.rb +1 -4
- metadata +10 -10
- data/bin/s3 +0 -187
data/Gemfile.lock
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
s3 (0.3.
|
4
|
+
s3 (0.3.5)
|
5
|
+
http_connection
|
5
6
|
proxies
|
6
|
-
trollop
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
+
http_connection (1.3.1)
|
11
12
|
mocha (0.9.8)
|
12
13
|
rake
|
13
|
-
proxies (0.
|
14
|
+
proxies (0.2.1)
|
14
15
|
rake (0.8.7)
|
15
16
|
test-unit (2.1.1)
|
16
|
-
trollop (1.16.2)
|
17
17
|
|
18
18
|
PLATFORMS
|
19
19
|
ruby
|
20
20
|
|
21
21
|
DEPENDENCIES
|
22
22
|
bundler (>= 1.0.0)
|
23
|
+
http_connection
|
23
24
|
mocha
|
24
25
|
proxies
|
25
26
|
s3!
|
26
27
|
test-unit (>= 2.0)
|
27
|
-
trollop
|
data/Rakefile
CHANGED
data/lib/s3.rb
CHANGED
data/lib/s3/bucket.rb
CHANGED
@@ -93,7 +93,7 @@ module S3
|
|
93
93
|
# Returns the objects in the bucket and caches the result (see
|
94
94
|
# #reload method).
|
95
95
|
def objects
|
96
|
-
|
96
|
+
Proxy.new(lambda { list_bucket }, :owner => self, :extend => ObjectsExtension)
|
97
97
|
end
|
98
98
|
|
99
99
|
def inspect #:nodoc:
|
data/lib/s3/connection.rb
CHANGED
@@ -19,7 +19,8 @@ module S3
|
|
19
19
|
# * <tt>:timeout</tt> - Timeout to use by the Net::HTTP object
|
20
20
|
# (60 by default)
|
21
21
|
# * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
|
22
|
-
#
|
22
|
+
# { :host => "proxy.mydomain.com", :port => "80, :user => "user_a", :password => "secret" }
|
23
|
+
# * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
|
23
24
|
def initialize(options = {})
|
24
25
|
@access_key_id = options.fetch(:access_key_id)
|
25
26
|
@secret_access_key = options.fetch(:secret_access_key)
|
@@ -53,7 +54,7 @@ module S3
|
|
53
54
|
def request(method, options)
|
54
55
|
host = options.fetch(:host, HOST)
|
55
56
|
path = options.fetch(:path)
|
56
|
-
body = options.fetch(:body,
|
57
|
+
body = options.fetch(:body, nil)
|
57
58
|
params = options.fetch(:params, {})
|
58
59
|
headers = options.fetch(:headers, {})
|
59
60
|
|
@@ -63,14 +64,21 @@ module S3
|
|
63
64
|
end
|
64
65
|
|
65
66
|
path = URI.escape(path)
|
66
|
-
request =
|
67
|
+
request = Net::HTTPGenericRequest.new(method.to_s.upcase, !!body, true, path)
|
67
68
|
|
68
69
|
headers = self.class.parse_headers(headers)
|
69
70
|
headers.each do |key, value|
|
70
71
|
request[key] = value
|
71
72
|
end
|
72
73
|
|
73
|
-
|
74
|
+
if body
|
75
|
+
if body.respond_to?(:read)
|
76
|
+
request.body_stream = body
|
77
|
+
else
|
78
|
+
request.body = body
|
79
|
+
end
|
80
|
+
request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
|
81
|
+
end
|
74
82
|
|
75
83
|
send_request(host, request)
|
76
84
|
end
|
@@ -143,19 +151,6 @@ module S3
|
|
143
151
|
|
144
152
|
private
|
145
153
|
|
146
|
-
def request_class(method)
|
147
|
-
case method
|
148
|
-
when :get
|
149
|
-
request_class = Net::HTTP::Get
|
150
|
-
when :head
|
151
|
-
request_class = Net::HTTP::Head
|
152
|
-
when :put
|
153
|
-
request_class = Net::HTTP::Put
|
154
|
-
when :delete
|
155
|
-
request_class = Net::HTTP::Delete
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
154
|
def port
|
160
155
|
use_ssl ? 443 : 80
|
161
156
|
end
|
data/lib/s3/object.rb
CHANGED
@@ -40,8 +40,8 @@ module S3
|
|
40
40
|
def acl=(acl)
|
41
41
|
@acl = acl.to_s.gsub("_", "-") if acl
|
42
42
|
end
|
43
|
-
|
44
|
-
# Assigns a new storage class (RRS) to the object. Please note
|
43
|
+
|
44
|
+
# Assigns a new storage class (RRS) to the object. Please note
|
45
45
|
# that the storage class is not retrieved from the server and set
|
46
46
|
# to "STANDARD" by default.
|
47
47
|
#
|
@@ -185,8 +185,7 @@ module S3
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def put_object
|
188
|
-
|
189
|
-
response = object_request(:put, :body => body, :headers => dump_headers)
|
188
|
+
response = object_request(:put, :body => content, :headers => dump_headers)
|
190
189
|
parse_headers(response)
|
191
190
|
end
|
192
191
|
|
data/lib/s3/request.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module S3
|
2
|
+
# Class responsible for sending chunked requests
|
3
|
+
# properly. Net::HTTPGenericRequest has hardcoded chunk_size, so we
|
4
|
+
# inherit the class and override chunk_size.
|
5
|
+
class Request < Net::HTTPGenericRequest
|
6
|
+
def initialize(chunk_size, m, reqbody, resbody, path, initheader = nil)
|
7
|
+
@chunk_size = chunk_size
|
8
|
+
super(m, reqbody, resbody, path, initheader)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/s3/service.rb
CHANGED
@@ -28,7 +28,7 @@ module S3
|
|
28
28
|
@use_ssl = options.fetch(:use_ssl, false)
|
29
29
|
@timeout = options.fetch(:timeout, 60)
|
30
30
|
@debug = options.fetch(:debug, false)
|
31
|
-
|
31
|
+
|
32
32
|
raise ArgumentError, "Missing proxy settings. Must specify at least :host." if options[:proxy] && !options[:proxy][:host]
|
33
33
|
@proxy = options.fetch(:proxy, nil)
|
34
34
|
end
|
@@ -36,7 +36,7 @@ module S3
|
|
36
36
|
# Returns all buckets in the service and caches the result (see
|
37
37
|
# +reload+)
|
38
38
|
def buckets
|
39
|
-
|
39
|
+
Proxy.new(lambda { list_all_my_buckets}, :owner => self, :extend => BucketsExtension)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Returns "http://" or "https://", depends on <tt>:use_ssl</tt>
|
data/lib/s3/version.rb
CHANGED
data/s3.gemspec
CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Jakub Kuźma"]
|
10
10
|
s.email = ["qoobaa@gmail.com"]
|
11
11
|
s.homepage = "http://jah.pl/projects/s3.html"
|
12
|
-
s.summary = "Library for accessing S3 objects and buckets
|
12
|
+
s.summary = "Library for accessing S3 objects and buckets"
|
13
13
|
s.description = "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
|
14
14
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
16
16
|
s.rubyforge_project = "s3"
|
17
17
|
|
18
|
-
s.add_dependency "trollop"
|
19
18
|
s.add_dependency "proxies"
|
19
|
+
s.add_dependency "http_connection"
|
20
20
|
s.add_development_dependency "test-unit", ">= 2.0"
|
21
21
|
s.add_development_dependency "mocha"
|
22
22
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steamcannon-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 65
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
9
|
+
- 5
|
10
10
|
- 1
|
11
|
-
version: 0.3.
|
11
|
+
version: 0.3.5.1
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- "Jakub Ku\xC5\xBAma"
|
@@ -16,11 +16,11 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-28 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name:
|
23
|
+
name: proxies
|
24
24
|
prerelease: false
|
25
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: http_connection
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
@@ -95,8 +95,8 @@ dependencies:
|
|
95
95
|
description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
|
96
96
|
email:
|
97
97
|
- qoobaa@gmail.com
|
98
|
-
executables:
|
99
|
-
|
98
|
+
executables: []
|
99
|
+
|
100
100
|
extensions: []
|
101
101
|
|
102
102
|
extra_rdoc_files: []
|
@@ -108,7 +108,6 @@ files:
|
|
108
108
|
- LICENSE
|
109
109
|
- README.rdoc
|
110
110
|
- Rakefile
|
111
|
-
- bin/s3
|
112
111
|
- extra/s3_attachment_fu.rb
|
113
112
|
- extra/s3_paperclip.rb
|
114
113
|
- lib/s3.rb
|
@@ -119,6 +118,7 @@ files:
|
|
119
118
|
- lib/s3/object.rb
|
120
119
|
- lib/s3/objects_extension.rb
|
121
120
|
- lib/s3/parser.rb
|
121
|
+
- lib/s3/request.rb
|
122
122
|
- lib/s3/service.rb
|
123
123
|
- lib/s3/signature.rb
|
124
124
|
- lib/s3/version.rb
|
@@ -164,6 +164,6 @@ rubyforge_project: s3
|
|
164
164
|
rubygems_version: 1.3.7
|
165
165
|
signing_key:
|
166
166
|
specification_version: 3
|
167
|
-
summary: Library for accessing S3 objects and buckets
|
167
|
+
summary: Library for accessing S3 objects and buckets
|
168
168
|
test_files: []
|
169
169
|
|
data/bin/s3
DELETED
@@ -1,187 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
|
4
|
-
|
5
|
-
require "trollop"
|
6
|
-
require "s3"
|
7
|
-
|
8
|
-
# HELPER METHODS
|
9
|
-
|
10
|
-
include S3
|
11
|
-
|
12
|
-
def list_buckets(service)
|
13
|
-
service.buckets.each do |bucket|
|
14
|
-
puts bucket.name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_bucket(service, name, location)
|
19
|
-
service.buckets.build(name).save(location)
|
20
|
-
end
|
21
|
-
|
22
|
-
def destroy_bucket(service, name)
|
23
|
-
service.buckets.find(name).destroy
|
24
|
-
end
|
25
|
-
|
26
|
-
def show_bucket(service, name, options = {})
|
27
|
-
service.buckets.find(name).objects.find_all.each do |object|
|
28
|
-
puts "#{name}/#{object.key}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def list_objects(service)
|
33
|
-
service.buckets.each do |bucket|
|
34
|
-
bucket.objects.each do |object|
|
35
|
-
puts "#{bucket.name}/#{object.key}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def create_object(service, name, file_name, options = {})
|
41
|
-
bucket_name, object_name = name.split("/", 2)
|
42
|
-
object = service.buckets.find(bucket_name).objects.build(object_name)
|
43
|
-
object.content_type = options[:type]
|
44
|
-
object.content_encoding = options[:encoding]
|
45
|
-
object.content_disposition = options[:disposition]
|
46
|
-
object.acl = options[:acl]
|
47
|
-
object.content = File.new(file_name)
|
48
|
-
object.save
|
49
|
-
end
|
50
|
-
|
51
|
-
def destroy_object(service, name)
|
52
|
-
bucket_name, object_name = name.split("/", 2)
|
53
|
-
object = service.buckets.find(bucket_name).objects.find(object_name)
|
54
|
-
object.destroy
|
55
|
-
end
|
56
|
-
|
57
|
-
def show_object(service, name, file_name = nil)
|
58
|
-
bucket_name, object_name = name.split("/", 2)
|
59
|
-
object = service.buckets.find(bucket_name).objects.find_first(object_name)
|
60
|
-
puts " object: #{object.name}/#{object.key}"
|
61
|
-
puts " content type: #{object.content_type}"
|
62
|
-
puts " size: #{object.size}"
|
63
|
-
puts " etag: #{object.etag}"
|
64
|
-
puts " last modified: #{object.last_modified}"
|
65
|
-
if file_name
|
66
|
-
if file_name == "-"
|
67
|
-
puts object.content
|
68
|
-
else
|
69
|
-
File.open(file_name, "wb") do |file|
|
70
|
-
file.write(object.content)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# COMMAND LINE PARSER
|
77
|
-
|
78
|
-
ACCESS_KEY_ID = ENV["ACCESS_KEY_ID"]
|
79
|
-
SECRET_ACCESS_KEY = ENV["SECRET_ACCESS_KEY"]
|
80
|
-
COMMANDS = %w(bucket object)
|
81
|
-
BUCKET_SUBCOMMANDS = %w(add remove show)
|
82
|
-
OBJECT_SUBCOMMANDS = %w(add remove show)
|
83
|
-
|
84
|
-
global_options = Trollop::options do
|
85
|
-
banner "s3 command line tool"
|
86
|
-
opt :access_key_id, "Your access key id to AWS", :type => :string, :default => ACCESS_KEY_ID
|
87
|
-
opt :secret_access_key, "Your secret access key to AWS", :type => :string, :default => SECRET_ACCESS_KEY
|
88
|
-
opt :debug, "Debug mode", :type => :flag, :default => false
|
89
|
-
stop_on COMMANDS
|
90
|
-
end
|
91
|
-
|
92
|
-
Trollop::die "No access key id given" unless global_options[:access_key_id]
|
93
|
-
Trollop::die "No secret access key given" unless global_options[:secret_access_key]
|
94
|
-
|
95
|
-
service = Service.new(:access_key_id => global_options[:access_key_id],
|
96
|
-
:secret_access_key => global_options[:secret_access_key],
|
97
|
-
:debug => global_options[:debug])
|
98
|
-
|
99
|
-
command = ARGV.shift
|
100
|
-
|
101
|
-
begin
|
102
|
-
case command
|
103
|
-
when "bucket"
|
104
|
-
command_options = Trollop::options do
|
105
|
-
banner "manage buckets"
|
106
|
-
stop_on BUCKET_SUBCOMMANDS
|
107
|
-
end
|
108
|
-
subcommand = ARGV.shift
|
109
|
-
case subcommand
|
110
|
-
when "add"
|
111
|
-
subcommand_options = Trollop::options do
|
112
|
-
banner "add bucket"
|
113
|
-
opt :location, "Location of the bucket - EU or US", :default => "US", :type => :string
|
114
|
-
end
|
115
|
-
name = ARGV.shift
|
116
|
-
Trollop::die "Bucket has not been added because of unknown error" unless create_bucket(service, name, subcommand_options[:location])
|
117
|
-
when "remove"
|
118
|
-
subcommand_options = Trollop::options do
|
119
|
-
banner "remove bucket"
|
120
|
-
end
|
121
|
-
name = ARGV.shift
|
122
|
-
Trollop::die "Bucket name must be given" if name.nil? or name.empty?
|
123
|
-
Trollop::die "Bucket has not been removed because of unknown error" unless destroy_bucket(service, name)
|
124
|
-
when "show"
|
125
|
-
subcommand_options = Trollop::options do
|
126
|
-
banner "show bucket"
|
127
|
-
opt :prefix, "Limits the response to keys which begin with the indicated prefix", :type => :string
|
128
|
-
opt :marker, "Indicates where in the bucket to begin listing", :type => :string
|
129
|
-
opt :max_keys, "The maximum number of keys you'd like to see", :type => :integer
|
130
|
-
opt :delimiter, "Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element", :type => :string
|
131
|
-
end
|
132
|
-
name = ARGV.shift
|
133
|
-
Trollop::die "Bucket name must be given" if name.nil? or name.empty?
|
134
|
-
show_bucket(service, name, subcommand_options)
|
135
|
-
when nil
|
136
|
-
list_buckets(service)
|
137
|
-
else
|
138
|
-
Trollop::die "Unknown subcommand: #{subcommand.inspect}"
|
139
|
-
end
|
140
|
-
when "object"
|
141
|
-
command_options = Trollop::options do
|
142
|
-
banner "manage objects"
|
143
|
-
stop_on OBJECT_SUBCOMMANDS
|
144
|
-
end
|
145
|
-
subcommand = ARGV.shift
|
146
|
-
case subcommand
|
147
|
-
when "add"
|
148
|
-
subcommand_options = Trollop::options do
|
149
|
-
banner "object add s3_object_name local_file_name"
|
150
|
-
opt :type, "A standard MIME type describing the format of the contents", :default => "binary/octet-stream"
|
151
|
-
opt :disposition, "Specifies presentational information for the object", :type => :string
|
152
|
-
opt :encoding, "Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header field", :type => :string
|
153
|
-
opt :acl, "The canned ACL to apply to the object. Options include private, public-read, public-read-write, and authenticated-read", :type => :string
|
154
|
-
end
|
155
|
-
name = ARGV.shift
|
156
|
-
Trollop::die "No object name given" if name.nil? or name.empty?
|
157
|
-
file_name = ARGV.shift
|
158
|
-
Trollop::die "No file name given" if file_name.nil? or file_name.empty?
|
159
|
-
Trollop::die "Object has not been added because of unknown error" unless create_object(service, name, file_name, subcommand_options)
|
160
|
-
when "remove"
|
161
|
-
subcommand_options = Trollop::options do
|
162
|
-
banner "object remove s3_object_name"
|
163
|
-
end
|
164
|
-
name = ARGV.shift
|
165
|
-
Trollop::die "No object name given" if name.nil? or name.empty?
|
166
|
-
Trollop::die "Object has not been removed because of unknown error" unless destroy_object(service, name)
|
167
|
-
when "show"
|
168
|
-
subcommand_options = Trollop::options do
|
169
|
-
banner "object show s3_object_name optional_file_name"
|
170
|
-
end
|
171
|
-
name = ARGV.shift
|
172
|
-
Trollop::die "No object name given" if name.nil? or name.empty?
|
173
|
-
file_name = ARGV.shift
|
174
|
-
show_object(service, name, file_name)
|
175
|
-
when nil
|
176
|
-
list_objects(service)
|
177
|
-
else
|
178
|
-
Trollop::die "Unknown subcommand: #{subcommand.inspect}"
|
179
|
-
end
|
180
|
-
when nil
|
181
|
-
Trollop::die "No command given"
|
182
|
-
else
|
183
|
-
Trollop::die "Unknown command #{command.inspect}"
|
184
|
-
end
|
185
|
-
rescue Error::ResponseError => e
|
186
|
-
Trollop::die e.message.sub(/\.+\Z/, "")
|
187
|
-
end
|