radosgw-s3 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de2e6c6190b45b9b75aae4043eb248ebe80752aa
4
- data.tar.gz: 5eaf652702ee6343ba519b099db3a6436442f9a9
3
+ metadata.gz: b670b4ebdb3d82028d8123baabdb8b73009c758c
4
+ data.tar.gz: e55274728dd5ba6e66174ddd31349e1268210768
5
5
  SHA512:
6
- metadata.gz: 20d3f333a2a7091f2246fbb4fbf9fe98d8252493d790040c898e02c6c9b1026b7ee12d9ad58ae4fb52d13497a7fb641183a68ba02c4af14f7a002bdbd59bff7a
7
- data.tar.gz: 828fed5272e3946575c92c86958ad317c243a57468df73600b023edf1f9d365d7f270a7ead77287d8043390400d5dba405dfd7725611430e57fffd263cac0e60
6
+ metadata.gz: 40dde8be0059906467dfad9efeaa69aa5db302c3718c6fc3108f9a282b0d1d12b8d2cbc683da135ff1cdf6103771c747727e8f88dd74d0eb8d0dd2ceeebc5e79
7
+ data.tar.gz: 0534107067e63a729561ad184caf01c9be301c0c29aacf60de928433993869aa58994384380aa774bae8abfb1d104b7ad1a40900ffb58a68382b22a7b4f597ae
data/lib/s3/connection.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  module S3
2
-
3
2
  # Class responsible for handling connections to amazon hosts
4
3
  class Connection
5
4
  include Parser
6
5
 
7
6
  attr_accessor :access_key_id, :secret_access_key, :use_ssl, :timeout, :debug, :proxy, :host
8
- alias :use_ssl? :use_ssl
7
+ alias_method :use_ssl?, :use_ssl
9
8
 
10
9
  # Creates new connection object.
11
10
  #
@@ -30,7 +29,7 @@ module S3
30
29
  @debug = options.fetch(:debug, false)
31
30
  @timeout = options.fetch(:timeout, 60)
32
31
  @proxy = options.fetch(:proxy, nil)
33
- @chunk_size = options.fetch(:chunk_size, 1048576)
32
+ @chunk_size = options.fetch(:chunk_size, 1_048_576)
34
33
  end
35
34
 
36
35
  # Makes request with given HTTP method, sets missing parameters,
@@ -60,6 +59,7 @@ module S3
60
59
  body = options.fetch(:body, nil)
61
60
  params = options.fetch(:params, {})
62
61
  headers = options.fetch(:headers, {})
62
+ use_authsign = options.fetch(:use_authsign)
63
63
 
64
64
  # Must be done before adding params
65
65
  # Encodes all characters except forward-slash (/) and explicitly legal URL characters
@@ -70,7 +70,7 @@ module S3
70
70
  path << "?#{params}"
71
71
  end
72
72
 
73
- request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != "HEAD", path)
73
+ request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != 'HEAD', path)
74
74
 
75
75
  headers = self.class.parse_headers(headers)
76
76
  headers.each do |key, value|
@@ -86,7 +86,11 @@ module S3
86
86
  request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
87
87
  end
88
88
 
89
- send_request(host, request)
89
+ if use_authsign
90
+ send_authsign(host, request)
91
+ else
92
+ send_request(host, request)
93
+ end
90
94
  end
91
95
 
92
96
  # Helper function to parser parameters and create single string of
@@ -104,7 +108,7 @@ module S3
104
108
  result = []
105
109
  params.each do |key, value|
106
110
  if interesting_keys.include?(key)
107
- parsed_key = key.to_s.gsub("_", "-")
111
+ parsed_key = key.to_s.tr('_', '-')
108
112
  case value
109
113
  when nil
110
114
  result << parsed_key
@@ -113,7 +117,7 @@ module S3
113
117
  end
114
118
  end
115
119
  end
116
- result.join("&")
120
+ result.join('&')
117
121
  end
118
122
 
119
123
  # Helper function to change headers from symbols, to in correct
@@ -142,7 +146,7 @@ module S3
142
146
  if headers
143
147
  headers.each do |key, value|
144
148
  if interesting_keys.include?(key)
145
- parsed_key = key.to_s.gsub("_", "-")
149
+ parsed_key = key.to_s.tr('_', '-')
146
150
  parsed_value = value
147
151
  case value
148
152
  when Range
@@ -178,19 +182,7 @@ module S3
178
182
  response = http(host).start do |http|
179
183
  host = http.address
180
184
 
181
- request["Date"] ||= Time.now.httpdate
182
-
183
- if request.body
184
- request["Content-Type"] ||= "application/octet-stream"
185
- request["Content-MD5"] = Base64.encode64(Digest::MD5.digest(request.body)).chomp unless request.body.empty?
186
- end
187
-
188
- unless skip_authorization
189
- request["Authorization"] = Signature.generate(:host => host,
190
- :request => request,
191
- :access_key_id => access_key_id,
192
- :secret_access_key => secret_access_key)
193
- end
185
+ request = send_authsign(request)
194
186
 
195
187
  http.request(request)
196
188
  end
@@ -198,26 +190,40 @@ module S3
198
190
  if response.code.to_i == 307
199
191
  if response.body
200
192
  doc = Document.new response.body
201
- send_request(doc.elements["Error"].elements["Endpoint"].text, request, true)
193
+ send_request(doc.elements['Error'].elements['Endpoint'].text, request, true)
202
194
  end
203
195
  else
204
196
  handle_response(response)
205
197
  end
206
198
  end
207
199
 
200
+ def send_authsign(host, request, skip_authorization = false)
201
+ request['Date'] ||= Time.now.httpdate
202
+ if request.body
203
+ request['Content-Type'] ||= 'application/octet-stream'
204
+ request['Content-MD5'] = Base64.encode64(Digest::MD5.digest(request.body)).chomp unless request.body.empty?
205
+ end
206
+ unless skip_authorization
207
+ request['Authorization'] = Signature.generate(host: host, request: request,
208
+ access_key_id: access_key_id,
209
+ secret_access_key: secret_access_key)
210
+ end
211
+ request
212
+ end
213
+
208
214
  def handle_response(response)
209
215
  case response.code.to_i
210
216
  when 200...300
211
217
  response
212
218
  when 300...600
213
219
  if response.body.nil? || response.body.empty?
214
- raise Error::ResponseError.new(nil, response)
220
+ fail Error::ResponseError.new(nil, response)
215
221
  else
216
222
  code, message = parse_error(response.body)
217
- raise Error::ResponseError.exception(code).new(message, response)
223
+ fail Error::ResponseError.exception(code).new(message, response)
218
224
  end
219
225
  else
220
- raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
226
+ fail(ConnectionError.new(response, "Unknown response code: #{response.code}"))
221
227
  end
222
228
  response
223
229
  end
data/lib/s3/service.rb CHANGED
@@ -8,7 +8,7 @@ module S3
8
8
  # Compares service to other, by <tt>access_key_id</tt> and
9
9
  # <tt>secret_access_key</tt>
10
10
  def ==(other)
11
- self.access_key_id == other.access_key_id and self.secret_access_key == other.secret_access_key
11
+ access_key_id == other.access_key_id && secret_access_key == other.secret_access_key
12
12
  end
13
13
 
14
14
  # Creates new service.
@@ -28,8 +28,8 @@ module S3
28
28
  # The keys for these required options might exist in the options hash, but
29
29
  # they might be set to something like `nil`. If this is the case, we want
30
30
  # to fail early.
31
- raise ArgumentError, "Missing :access_key_id." if !options[:access_key_id]
32
- raise ArgumentError, "Missing :secret_access_key." if !options[:secret_access_key]
31
+ fail ArgumentError, 'Missing :access_key_id.' unless options[:access_key_id]
32
+ fail ArgumentError, 'Missing :secret_access_key.' unless options[:secret_access_key]
33
33
 
34
34
  @access_key_id = options.fetch(:access_key_id)
35
35
  @secret_access_key = options.fetch(:secret_access_key)
@@ -39,14 +39,14 @@ module S3
39
39
  @timeout = options.fetch(:timeout, 60)
40
40
  @debug = options.fetch(:debug, false)
41
41
 
42
- raise ArgumentError, "Missing proxy settings. Must specify at least :host." if options[:proxy] && !options[:proxy][:host]
42
+ fail ArgumentError, 'Missing proxy settings. Must specify at least :host.' if options[:proxy] && !options[:proxy][:host]
43
43
  @proxy = options.fetch(:proxy, nil)
44
44
  end
45
45
 
46
46
  # Returns all buckets in the service and caches the result (see
47
47
  # +reload+)
48
48
  def buckets
49
- Proxy.new(lambda { list_all_my_buckets }, :owner => self, :extend => BucketsExtension)
49
+ Proxy.new(-> { list_all_my_buckets }, owner: self, extend: BucketsExtension)
50
50
  end
51
51
 
52
52
  # Returns the bucket with the given name. Does not check whether the
@@ -56,10 +56,15 @@ module S3
56
56
  Bucket.send(:new, self, name)
57
57
  end
58
58
 
59
+ # Returns the signature for POST operations done externally via javascript
60
+ def auth_sign
61
+ service_request(:post, use_authsign: true)
62
+ end
63
+
59
64
  # Returns "http://" or "https://", depends on <tt>:use_ssl</tt>
60
65
  # value from initializer
61
66
  def protocol
62
- use_ssl ? "https://" : "http://"
67
+ use_ssl ? 'https://' : 'http://'
63
68
  end
64
69
 
65
70
  # Returns 443 or 80, depends on <tt>:use_ssl</tt> value from
@@ -69,7 +74,7 @@ module S3
69
74
  end
70
75
 
71
76
  def inspect #:nodoc:
72
- "#<#{self.class}:#@access_key_id>"
77
+ "#<#{self.class}:#{@access_key_id}>"
73
78
  end
74
79
 
75
80
  private
@@ -81,18 +86,18 @@ module S3
81
86
  end
82
87
 
83
88
  def service_request(method, options = {})
84
- connection.request(method, options.merge(:path => "/#{options[:path]}"))
89
+ connection.request(method, options.merge(path: "/#{options[:path]}"))
85
90
  end
86
91
 
87
92
  def connection
88
93
  return @connection if defined?(@connection)
89
- @connection = Connection.new(:access_key_id => @access_key_id,
90
- :secret_access_key => @secret_access_key,
91
- :host => @host,
92
- :use_ssl => @use_ssl,
93
- :timeout => @timeout,
94
- :debug => @debug,
95
- :proxy => @proxy)
94
+ @connection = Connection.new(access_key_id: @access_key_id,
95
+ secret_access_key: @secret_access_key,
96
+ host: @host,
97
+ use_ssl: @use_ssl,
98
+ timeout: @timeout,
99
+ debug: @debug,
100
+ proxy: @proxy)
96
101
  end
97
102
  end
98
103
  end
data/lib/s3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module S3
2
- VERSION = "0.5"
2
+ VERSION = "0.6"
3
3
  end
data/radosgw-s3.gemspec CHANGED
@@ -20,15 +20,14 @@ Gem::Specification.new do |s|
20
20
  s.rubyforge_project = "s3"
21
21
 
22
22
  s.add_dependency "proxies", "~> 0.2.0"
23
- s.add_dependency "net-ssh"
24
- s.add_development_dependency "rake"
25
- s.add_development_dependency "json"
26
- s.add_development_dependency "test-unit"
27
- s.add_development_dependency "mocha"
28
- s.add_development_dependency "bundler"
23
+ s.add_dependency "net-ssh", "~> 3.0"
24
+ s.add_development_dependency "rake", "~> 10.4"
25
+ s.add_development_dependency "json", "~> 1.8"
26
+ s.add_development_dependency "test-unit", "~> 3.1"
27
+ s.add_development_dependency "mocha", "~> 1.1"
28
+ s.add_development_dependency "bundler", "~> 1.10"
29
29
 
30
30
  s.files = `git ls-files`.split("\n")
31
31
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
32
32
  s.require_path = "lib"
33
33
  end
34
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radosgw-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Alrin, Kishorekumar Neelamegam, Rajthilak, Kuba Kuźma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: proxies
@@ -28,86 +28,86 @@ dependencies:
28
28
  name: net-ssh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '1.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '1.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '1.10'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '1.10'
111
111
  description: 'radosgw-s3 library provides access to your ceph-radosgw. It supports
112
112
  both: radosgw user creation and bucket operation using REST API.'
113
113
  email:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: 1.3.6
165
165
  requirements: []
166
166
  rubyforge_project: s3
167
- rubygems_version: 2.4.7
167
+ rubygems_version: 2.4.8
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Library for accessing ceph objects and buckets