aboisvert_aws 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ module RightAws #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3 unless defined?(MAJOR)
4
4
  MINOR = 0 unless defined?(MINOR)
5
- TINY = 0 unless defined?(TINY)
5
+ TINY = 1 unless defined?(TINY)
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
8
8
  end
@@ -24,11 +24,11 @@
24
24
  module RightAws
25
25
 
26
26
  class S3Interface < RightAwsBase
27
-
27
+
28
28
  USE_100_CONTINUE_PUT_SIZE = 1_000_000
29
-
29
+
30
30
  include RightAwsBaseInterface
31
-
31
+
32
32
  DEFAULT_HOST = 's3.amazonaws.com'
33
33
  DEFAULT_PORT = 443
34
34
  DEFAULT_PROTOCOL = 'https'
@@ -77,7 +77,7 @@ module RightAws
77
77
  # Creates new RightS3 instance.
78
78
  #
79
79
  # s3 = RightAws::S3Interface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:logger => Logger.new('/tmp/x.log')}) #=> #<RightAws::S3Interface:0xb7b3c27c>
80
- #
80
+ #
81
81
  # Params is a hash:
82
82
  #
83
83
  # {:server => 's3.amazonaws.com' # Amazon service host: 's3.amazonaws.com'(default)
@@ -87,13 +87,13 @@ module RightAws
87
87
  # :no_subdomains => true} # Force placing bucket name into path instead of domain name
88
88
  #
89
89
  def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
90
- init({ :name => 'S3',
91
- :default_host => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).host : DEFAULT_HOST,
90
+ init({ :name => 'S3',
91
+ :default_host => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).host : DEFAULT_HOST,
92
92
  :default_port => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).port : DEFAULT_PORT,
93
93
  :default_service => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).path : DEFAULT_SERVICE,
94
- :default_protocol => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).scheme : DEFAULT_PROTOCOL },
95
- aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
96
- aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
94
+ :default_protocol => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).scheme : DEFAULT_PROTOCOL },
95
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
96
+ aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
97
97
  params)
98
98
  end
99
99
 
@@ -193,12 +193,12 @@ module RightAws
193
193
  # set other headers
194
194
  request['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
195
195
  # prepare output hash
196
- { :request => request,
196
+ { :request => request,
197
197
  :server => server,
198
198
  :port => @params[:port],
199
199
  :protocol => @params[:protocol] }
200
200
  end
201
-
201
+
202
202
  # Sends request to Amazon and parses the response.
203
203
  # Raises AwsError if any banana happened.
204
204
  def request_info(request, parser, &block) # :nodoc:
@@ -207,7 +207,7 @@ module RightAws
207
207
 
208
208
  # Returns an array of customer's buckets. Each item is a +hash+.
209
209
  #
210
- # s3.list_all_my_buckets #=>
210
+ # s3.list_all_my_buckets #=>
211
211
  # [{:owner_id => "00000000009314cc309ffe736daa2b264357476c7fea6efb2c3347ac3ab2792a",
212
212
  # :owner_display_name => "root",
213
213
  # :name => "bucket_name",
@@ -219,7 +219,7 @@ module RightAws
219
219
  rescue
220
220
  on_exception
221
221
  end
222
-
222
+
223
223
  # Creates new bucket. Returns +true+ or an exception.
224
224
  #
225
225
  # # create a bucket at American server
@@ -234,7 +234,7 @@ module RightAws
234
234
  when 'eu' then 'EU'
235
235
  else headers[:location].to_s
236
236
  end
237
-
237
+
238
238
  unless location.right_blank?
239
239
  data = "<CreateBucketConfiguration><LocationConstraint>#{location}</LocationConstraint></CreateBucketConfiguration>"
240
240
  end
@@ -244,9 +244,9 @@ module RightAws
244
244
  # if the bucket exists AWS returns an error for the location constraint interface. Drop it
245
245
  e.is_a?(RightAws::AwsError) && e.message.include?('BucketAlreadyOwnedByYou') ? true : on_exception
246
246
  end
247
-
247
+
248
248
  # Retrieve bucket location
249
- #
249
+ #
250
250
  # s3.create_bucket('my-awesome-bucket-us') #=> true
251
251
  # puts s3.bucket_location('my-awesome-bucket-us') #=> '' (Amazon's default value assumed)
252
252
  #
@@ -259,14 +259,14 @@ module RightAws
259
259
  rescue
260
260
  on_exception
261
261
  end
262
-
263
- # Retrieves the logging configuration for a bucket.
262
+
263
+ # Retrieves the logging configuration for a bucket.
264
264
  # Returns a hash of {:enabled, :targetbucket, :targetprefix}
265
- #
265
+ #
266
266
  # s3.interface.get_logging_parse(:bucket => "asset_bucket")
267
267
  # => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}
268
268
  #
269
- #
269
+ #
270
270
  def get_logging_parse(params)
271
271
  AwsUtils.mandatory_arguments([:bucket], params)
272
272
  AwsUtils.allow_only([:bucket, :headers], params)
@@ -276,12 +276,12 @@ module RightAws
276
276
  rescue
277
277
  on_exception
278
278
  end
279
-
279
+
280
280
  # Sets logging configuration for a bucket from the XML configuration document.
281
281
  # params:
282
282
  # :bucket
283
283
  # :xmldoc
284
- def put_logging(params)
284
+ def put_logging(params)
285
285
  AwsUtils.mandatory_arguments([:bucket,:xmldoc], params)
286
286
  AwsUtils.allow_only([:bucket,:xmldoc, :headers], params)
287
287
  params[:headers] = {} unless params[:headers]
@@ -294,7 +294,7 @@ module RightAws
294
294
  # Deletes new bucket. Bucket must be empty! Returns +true+ or an exception.
295
295
  #
296
296
  # s3.delete_bucket('my_awesome_bucket') #=> true
297
- #
297
+ #
298
298
  # See also: force_delete_bucket method
299
299
  #
300
300
  def delete_bucket(bucket, headers={})
@@ -303,7 +303,7 @@ module RightAws
303
303
  rescue
304
304
  on_exception
305
305
  end
306
-
306
+
307
307
  # Returns an array of bucket's keys. Each array item (key data) is a +hash+.
308
308
  #
309
309
  # s3.list_bucket('my_awesome_bucket', { 'prefix'=>'t', 'marker'=>'', 'max-keys'=>5, delimiter=>'' }) #=>
@@ -329,7 +329,7 @@ module RightAws
329
329
  end
330
330
 
331
331
  # Incrementally list the contents of a bucket. Yields the following hash to a block:
332
- # s3.incrementally_list_bucket('my_awesome_bucket', { 'prefix'=>'t', 'marker'=>'', 'max-keys'=>5, delimiter=>'' }) yields
332
+ # s3.incrementally_list_bucket('my_awesome_bucket', { 'prefix'=>'t', 'marker'=>'', 'max-keys'=>5, delimiter=>'' }) yields
333
333
  # {
334
334
  # :name => 'bucketname',
335
335
  # :prefix => 'subfolder/',
@@ -357,7 +357,7 @@ module RightAws
357
357
  # }
358
358
  def incrementally_list_bucket(bucket, options={}, headers={}, &block)
359
359
  internal_options = options.right_symbolize_keys
360
- begin
360
+ begin
361
361
  internal_bucket = bucket.dup
362
362
  internal_bucket += '?'+internal_options.map{|k, v| "#{k.to_s}=#{CGI::escape v.to_s}"}.join('&') unless internal_options.right_blank?
363
363
  req_hash = generate_rest_request('GET', headers.merge(:url=>internal_bucket))
@@ -366,7 +366,7 @@ module RightAws
366
366
  if(there_are_more_keys)
367
367
  internal_options[:marker] = decide_marker(response)
368
368
  total_results = response[:contents].length + response[:common_prefixes].length
369
- internal_options[:'max-keys'] ? (internal_options[:'max-keys'] -= total_results) : nil
369
+ internal_options[:'max-keys'] ? (internal_options[:'max-keys'] -= total_results) : nil
370
370
  end
371
371
  yield response
372
372
  end while there_are_more_keys && under_max_keys(internal_options)
@@ -374,8 +374,8 @@ module RightAws
374
374
  rescue
375
375
  on_exception
376
376
  end
377
-
378
-
377
+
378
+
379
379
  private
380
380
  def decide_marker(response)
381
381
  return response[:next_marker].dup if response[:next_marker]
@@ -390,11 +390,11 @@ module RightAws
390
390
  last_key > last_prefix ? last_key.dup : last_prefix.dup
391
391
  end
392
392
  end
393
-
393
+
394
394
  def under_max_keys(internal_options)
395
395
  internal_options[:'max-keys'] ? internal_options[:'max-keys'] > 0 : true
396
396
  end
397
-
397
+
398
398
  public
399
399
  # Saves object to Amazon. Returns +true+ or an exception.
400
400
  # Any header starting with AMAZON_METADATA_PREFIX is considered
@@ -420,16 +420,16 @@ module RightAws
420
420
  # methods. Be sure that your class returns 'nil' from read() after having
421
421
  # read 'size' bytes. Otherwise S3 will drop the socket after
422
422
  # 'Content-Length' bytes have been uploaded, and HttpConnection will
423
- # interpret this as an error.
424
- #
423
+ # interpret this as an error.
424
+ #
425
425
  # This method now supports very large PUTs, where very large
426
- # is > 2 GB.
427
- #
426
+ # is > 2 GB.
427
+ #
428
428
  # For Win32 users: Files and IO objects should be opened in binary mode. If
429
429
  # a text mode IO object is passed to PUT, it will be converted to binary
430
430
  # mode.
431
431
  #
432
-
432
+
433
433
  def put(bucket, key, data=nil, headers={})
434
434
  # On Windows, if someone opens a file in text mode, we must reset it so
435
435
  # to binary mode for streaming to work properly
@@ -445,9 +445,9 @@ module RightAws
445
445
  rescue
446
446
  on_exception
447
447
  end
448
-
449
-
450
-
448
+
449
+
450
+
451
451
  # New experimental API for uploading objects, introduced in RightAws 1.8.1.
452
452
  # store_object is similar in function to the older function put, but returns the full response metadata. It also allows for optional verification
453
453
  # of object md5 checksums on upload. Parameters are passed as hash entries and are checked for completeness as well as for spurious arguments.
@@ -459,34 +459,34 @@ module RightAws
459
459
  # The optional argument of :headers allows the caller to specify arbitrary request header values.
460
460
  #
461
461
  # s3.store_object(:bucket => "foobucket", :key => "foo", :md5 => "a507841b1bc8115094b00bbe8c1b2954", :data => "polemonium" )
462
- # => {"x-amz-id-2"=>"SVsnS2nfDaR+ixyJUlRKM8GndRyEMS16+oZRieamuL61pPxPaTuWrWtlYaEhYrI/",
463
- # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
464
- # "date"=>"Mon, 29 Sep 2008 18:57:46 GMT",
465
- # :verified_md5=>true,
466
- # "x-amz-request-id"=>"63916465939995BA",
467
- # "server"=>"AmazonS3",
462
+ # => {"x-amz-id-2"=>"SVsnS2nfDaR+ixyJUlRKM8GndRyEMS16+oZRieamuL61pPxPaTuWrWtlYaEhYrI/",
463
+ # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
464
+ # "date"=>"Mon, 29 Sep 2008 18:57:46 GMT",
465
+ # :verified_md5=>true,
466
+ # "x-amz-request-id"=>"63916465939995BA",
467
+ # "server"=>"AmazonS3",
468
468
  # "content-length"=>"0"}
469
469
  #
470
470
  # s3.store_object(:bucket => "foobucket", :key => "foo", :data => "polemonium" )
471
- # => {"x-amz-id-2"=>"MAt9PLjgLX9UYJ5tV2fI/5dBZdpFjlzRVpWgBDpvZpl+V+gJFcBMW2L+LBstYpbR",
472
- # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
473
- # "date"=>"Mon, 29 Sep 2008 18:58:56 GMT",
474
- # :verified_md5=>false,
475
- # "x-amz-request-id"=>"3B25A996BC2CDD3B",
476
- # "server"=>"AmazonS3",
471
+ # => {"x-amz-id-2"=>"MAt9PLjgLX9UYJ5tV2fI/5dBZdpFjlzRVpWgBDpvZpl+V+gJFcBMW2L+LBstYpbR",
472
+ # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
473
+ # "date"=>"Mon, 29 Sep 2008 18:58:56 GMT",
474
+ # :verified_md5=>false,
475
+ # "x-amz-request-id"=>"3B25A996BC2CDD3B",
476
+ # "server"=>"AmazonS3",
477
477
  # "content-length"=>"0"}
478
-
478
+
479
479
  def store_object(params)
480
480
  AwsUtils.allow_only([:bucket, :key, :data, :headers, :md5], params)
481
481
  AwsUtils.mandatory_arguments([:bucket, :key, :data], params)
482
482
  params[:headers] = {} unless params[:headers]
483
-
483
+
484
484
  params[:data].binmode if(params[:data].respond_to?(:binmode)) # On Windows, if someone opens a file in text mode, we must reset it to binary mode for streaming to work properly
485
485
  if (params[:data].respond_to?(:lstat) && params[:data].lstat.size >= USE_100_CONTINUE_PUT_SIZE) ||
486
486
  (params[:data].respond_to?(:size) && params[:data].size >= USE_100_CONTINUE_PUT_SIZE)
487
487
  params[:headers]['expect'] = '100-continue'
488
488
  end
489
-
489
+
490
490
  req_hash = generate_rest_request('PUT', params[:headers].merge(:url=>"#{params[:bucket]}/#{CGI::escape params[:key]}", :data=>params[:data]))
491
491
  resp = request_info(req_hash, S3HttpResponseHeadParser.new)
492
492
  if(params[:md5])
@@ -498,47 +498,47 @@ module RightAws
498
498
  rescue
499
499
  on_exception
500
500
  end
501
-
501
+
502
502
  # Identical in function to store_object, but requires verification that the returned ETag is identical to the checksum passed in by the user as the 'md5' argument.
503
503
  # If the check passes, returns the response metadata with the "verified_md5" field set true. Raises an exception if the checksums conflict.
504
504
  # This call is implemented as a wrapper around store_object and the user may gain different semantics by creating a custom wrapper.
505
- #
505
+ #
506
506
  # s3.store_object_and_verify(:bucket => "foobucket", :key => "foo", :md5 => "a507841b1bc8115094b00bbe8c1b2954", :data => "polemonium" )
507
- # => {"x-amz-id-2"=>"IZN3XsH4FlBU0+XYkFTfHwaiF1tNzrm6dIW2EM/cthKvl71nldfVC0oVQyydzWpb",
508
- # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
509
- # "date"=>"Mon, 29 Sep 2008 18:38:32 GMT",
510
- # :verified_md5=>true,
511
- # "x-amz-request-id"=>"E8D7EA4FE00F5DF7",
512
- # "server"=>"AmazonS3",
507
+ # => {"x-amz-id-2"=>"IZN3XsH4FlBU0+XYkFTfHwaiF1tNzrm6dIW2EM/cthKvl71nldfVC0oVQyydzWpb",
508
+ # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
509
+ # "date"=>"Mon, 29 Sep 2008 18:38:32 GMT",
510
+ # :verified_md5=>true,
511
+ # "x-amz-request-id"=>"E8D7EA4FE00F5DF7",
512
+ # "server"=>"AmazonS3",
513
513
  # "content-length"=>"0"}
514
514
  #
515
515
  # s3.store_object_and_verify(:bucket => "foobucket", :key => "foo", :md5 => "a507841b1bc8115094b00bbe8c1b2953", :data => "polemonium" )
516
- # RightAws::AwsError: Uploaded object failed MD5 checksum verification: {"x-amz-id-2"=>"HTxVtd2bf7UHHDn+WzEH43MkEjFZ26xuYvUzbstkV6nrWvECRWQWFSx91z/bl03n",
517
- # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
518
- # "date"=>"Mon, 29 Sep 2008 18:38:41 GMT",
519
- # :verified_md5=>false,
520
- # "x-amz-request-id"=>"0D7ADE09F42606F2",
521
- # "server"=>"AmazonS3",
516
+ # RightAws::AwsError: Uploaded object failed MD5 checksum verification: {"x-amz-id-2"=>"HTxVtd2bf7UHHDn+WzEH43MkEjFZ26xuYvUzbstkV6nrWvECRWQWFSx91z/bl03n",
517
+ # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
518
+ # "date"=>"Mon, 29 Sep 2008 18:38:41 GMT",
519
+ # :verified_md5=>false,
520
+ # "x-amz-request-id"=>"0D7ADE09F42606F2",
521
+ # "server"=>"AmazonS3",
522
522
  # "content-length"=>"0"}
523
523
  def store_object_and_verify(params)
524
524
  AwsUtils.mandatory_arguments([:md5], params)
525
525
  r = store_object(params)
526
526
  r[:verified_md5] ? (return r) : (raise AwsError.new("Uploaded object failed MD5 checksum verification: #{r.inspect}"))
527
527
  end
528
-
528
+
529
529
  # Retrieves object data from Amazon. Returns a +hash+ or an exception.
530
530
  #
531
531
  # s3.get('my_awesome_bucket', 'log/curent/1.log') #=>
532
532
  #
533
- # {:object => "Ola-la!",
534
- # :headers => {"last-modified" => "Wed, 23 May 2007 09:08:04 GMT",
535
- # "content-type" => "",
536
- # "etag" => "\"000000000096f4ee74bc4596443ef2a4\"",
537
- # "date" => "Wed, 23 May 2007 09:08:03 GMT",
538
- # "x-amz-id-2" => "ZZZZZZZZZZZZZZZZZZZZ1HJXZoehfrS4QxcxTdNGldR7w/FVqblP50fU8cuIMLiu",
533
+ # {:object => "Ola-la!",
534
+ # :headers => {"last-modified" => "Wed, 23 May 2007 09:08:04 GMT",
535
+ # "content-type" => "",
536
+ # "etag" => "\"000000000096f4ee74bc4596443ef2a4\"",
537
+ # "date" => "Wed, 23 May 2007 09:08:03 GMT",
538
+ # "x-amz-id-2" => "ZZZZZZZZZZZZZZZZZZZZ1HJXZoehfrS4QxcxTdNGldR7w/FVqblP50fU8cuIMLiu",
539
539
  # "x-amz-meta-family" => "Woho556!",
540
- # "x-amz-request-id" => "0000000C246D770C",
541
- # "server" => "AmazonS3",
540
+ # "x-amz-request-id" => "0000000C246D770C",
541
+ # "server" => "AmazonS3",
542
542
  # "content-length" => "7"}}
543
543
  #
544
544
  # If a block is provided, yields incrementally to the block as
@@ -551,7 +551,7 @@ module RightAws
551
551
  # foo.write(chunk)
552
552
  # end
553
553
  # foo.close
554
- #
554
+ #
555
555
 
556
556
  def get(bucket, key, headers={}, &block)
557
557
  req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}/#{CGI::escape key}"))
@@ -559,7 +559,7 @@ module RightAws
559
559
  rescue
560
560
  on_exception
561
561
  end
562
-
562
+
563
563
  # New experimental API for retrieving objects, introduced in RightAws 1.8.1.
564
564
  # retrieve_object is similar in function to the older function get. It allows for optional verification
565
565
  # of object md5 checksums on retrieval. Parameters are passed as hash entries and are checked for completeness as well as for spurious arguments.
@@ -575,27 +575,27 @@ module RightAws
575
575
  # :headers - hash of additional HTTP headers to include with the request
576
576
  # :md5 - MD5 checksum against which to verify the retrieved object
577
577
  #
578
- # s3.retrieve_object(:bucket => "foobucket", :key => "foo")
579
- # => {:verified_md5=>false,
580
- # :headers=>{"last-modified"=>"Mon, 29 Sep 2008 18:58:56 GMT",
581
- # "x-amz-id-2"=>"2Aj3TDz6HP5109qly//18uHZ2a1TNHGLns9hyAtq2ved7wmzEXDOPGRHOYEa3Qnp",
582
- # "content-type"=>"",
583
- # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
584
- # "date"=>"Tue, 30 Sep 2008 00:52:44 GMT",
585
- # "x-amz-request-id"=>"EE4855DE27A2688C",
586
- # "server"=>"AmazonS3",
587
- # "content-length"=>"10"},
578
+ # s3.retrieve_object(:bucket => "foobucket", :key => "foo")
579
+ # => {:verified_md5=>false,
580
+ # :headers=>{"last-modified"=>"Mon, 29 Sep 2008 18:58:56 GMT",
581
+ # "x-amz-id-2"=>"2Aj3TDz6HP5109qly//18uHZ2a1TNHGLns9hyAtq2ved7wmzEXDOPGRHOYEa3Qnp",
582
+ # "content-type"=>"",
583
+ # "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
584
+ # "date"=>"Tue, 30 Sep 2008 00:52:44 GMT",
585
+ # "x-amz-request-id"=>"EE4855DE27A2688C",
586
+ # "server"=>"AmazonS3",
587
+ # "content-length"=>"10"},
588
588
  # :object=>"polemonium"}
589
589
  #
590
- # s3.retrieve_object(:bucket => "foobucket", :key => "foo", :md5=>'a507841b1bc8115094b00bbe8c1b2954')
591
- # => {:verified_md5=>true,
592
- # :headers=>{"last-modified"=>"Mon, 29 Sep 2008 18:58:56 GMT",
593
- # "x-amz-id-2"=>"mLWQcI+VuKVIdpTaPXEo84g0cz+vzmRLbj79TS8eFPfw19cGFOPxuLy4uGYVCvdH",
594
- # "content-type"=>"", "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
595
- # "date"=>"Tue, 30 Sep 2008 00:53:08 GMT",
596
- # "x-amz-request-id"=>"6E7F317356580599",
597
- # "server"=>"AmazonS3",
598
- # "content-length"=>"10"},
590
+ # s3.retrieve_object(:bucket => "foobucket", :key => "foo", :md5=>'a507841b1bc8115094b00bbe8c1b2954')
591
+ # => {:verified_md5=>true,
592
+ # :headers=>{"last-modified"=>"Mon, 29 Sep 2008 18:58:56 GMT",
593
+ # "x-amz-id-2"=>"mLWQcI+VuKVIdpTaPXEo84g0cz+vzmRLbj79TS8eFPfw19cGFOPxuLy4uGYVCvdH",
594
+ # "content-type"=>"", "etag"=>"\"a507841b1bc8115094b00bbe8c1b2954\"",
595
+ # "date"=>"Tue, 30 Sep 2008 00:53:08 GMT",
596
+ # "x-amz-request-id"=>"6E7F317356580599",
597
+ # "server"=>"AmazonS3",
598
+ # "content-length"=>"10"},
599
599
  # :object=>"polemonium"}
600
600
  # If a block is provided, yields incrementally to the block as
601
601
  # the response is read. For large responses, this function is ideal as
@@ -615,7 +615,7 @@ module RightAws
615
615
  rescue
616
616
  on_exception
617
617
  end
618
-
618
+
619
619
  # Identical in function to retrieve_object, but requires verification that the returned ETag is identical to the checksum passed in by the user as the 'md5' argument.
620
620
  # If the check passes, returns the response metadata with the "verified_md5" field set true. Raises an exception if the checksums conflict.
621
621
  # This call is implemented as a wrapper around retrieve_object and the user may gain different semantics by creating a custom wrapper.
@@ -629,14 +629,14 @@ module RightAws
629
629
  # Retrieves object metadata. Returns a +hash+ of http_response_headers.
630
630
  #
631
631
  # s3.head('my_awesome_bucket', 'log/curent/1.log') #=>
632
- # {"last-modified" => "Wed, 23 May 2007 09:08:04 GMT",
633
- # "content-type" => "",
634
- # "etag" => "\"000000000096f4ee74bc4596443ef2a4\"",
635
- # "date" => "Wed, 23 May 2007 09:08:03 GMT",
636
- # "x-amz-id-2" => "ZZZZZZZZZZZZZZZZZZZZ1HJXZoehfrS4QxcxTdNGldR7w/FVqblP50fU8cuIMLiu",
632
+ # {"last-modified" => "Wed, 23 May 2007 09:08:04 GMT",
633
+ # "content-type" => "",
634
+ # "etag" => "\"000000000096f4ee74bc4596443ef2a4\"",
635
+ # "date" => "Wed, 23 May 2007 09:08:03 GMT",
636
+ # "x-amz-id-2" => "ZZZZZZZZZZZZZZZZZZZZ1HJXZoehfrS4QxcxTdNGldR7w/FVqblP50fU8cuIMLiu",
637
637
  # "x-amz-meta-family" => "Woho556!",
638
- # "x-amz-request-id" => "0000000C246D770C",
639
- # "server" => "AmazonS3",
638
+ # "x-amz-request-id" => "0000000C246D770C",
639
+ # "server" => "AmazonS3",
640
640
  # "content-length" => "7"}
641
641
  #
642
642
  def head(bucket, key, headers={})
@@ -685,13 +685,13 @@ module RightAws
685
685
  on_exception
686
686
  end
687
687
 
688
- # Copy an object.
688
+ # Copy an object.
689
689
  # directive: :copy - copy meta-headers from source (default value)
690
690
  # :replace - replace meta-headers by passed ones
691
691
  #
692
692
  # # copy a key with meta-headers
693
693
  # s3.copy('b1', 'key1', 'b1', 'key1_copy') #=> {:e_tag=>"\"e8b...8d\"", :last_modified=>"2008-05-11T10:25:22.000Z"}
694
- #
694
+ #
695
695
  # # copy a key, overwrite meta-headers
696
696
  # s3.copy('b1', 'key2', 'b1', 'key2_copy', :replace, 'x-amz-meta-family'=>'Woho555!') #=> {:e_tag=>"\"e8b...8d\"", :last_modified=>"2008-05-11T10:26:22.000Z"}
697
697
  #
@@ -707,17 +707,17 @@ module RightAws
707
707
  rescue
708
708
  on_exception
709
709
  end
710
-
711
- # Move an object.
710
+
711
+ # Move an object.
712
712
  # directive: :copy - copy meta-headers from source (default value)
713
713
  # :replace - replace meta-headers by passed ones
714
714
  #
715
715
  # # move bucket1/key1 to bucket1/key2
716
716
  # s3.move('bucket1', 'key1', 'bucket1', 'key2') #=> {:e_tag=>"\"e8b...8d\"", :last_modified=>"2008-05-11T10:27:22.000Z"}
717
- #
717
+ #
718
718
  # # move bucket1/key1 to bucket2/key2 with new meta-headers assignment
719
719
  # s3.copy('bucket1', 'key1', 'bucket2', 'key2', :replace, 'x-amz-meta-family'=>'Woho555!') #=> {:e_tag=>"\"e8b...8d\"", :last_modified=>"2008-05-11T10:28:22.000Z"}
720
- #
720
+ #
721
721
  def move(src_bucket, src_key, dest_bucket, dest_key=nil, directive=:copy, headers={})
722
722
  copy_result = copy(src_bucket, src_key, dest_bucket, dest_key, directive, headers)
723
723
  # delete an original key if it differs from a destination one
@@ -725,15 +725,15 @@ module RightAws
725
725
  copy_result
726
726
  end
727
727
 
728
- # Rename an object.
729
- #
728
+ # Rename an object.
729
+ #
730
730
  # # rename bucket1/key1 to bucket1/key2
731
731
  # s3.rename('bucket1', 'key1', 'key2') #=> {:e_tag=>"\"e8b...8d\"", :last_modified=>"2008-05-11T10:29:22.000Z"}
732
- #
732
+ #
733
733
  def rename(src_bucket, src_key, dest_key, headers={})
734
734
  move(src_bucket, src_key, src_bucket, dest_key, :copy, headers)
735
735
  end
736
-
736
+
737
737
  # Retieves the ACL (access control policy) for a bucket or object. Returns a hash of headers and xml doc with ACL data. See: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html.
738
738
  #
739
739
  # s3.get_acl('my_awesome_bucket', 'log/curent/1.log') #=>
@@ -752,12 +752,12 @@ module RightAws
752
752
  def get_acl(bucket, key='', headers={})
753
753
  key = key.right_blank? ? '' : "/#{CGI::escape key}"
754
754
  req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}#{key}?acl"))
755
- request_info(req_hash, S3HttpResponseBodyParser.new)
755
+ request_info(req_hash, S3HttpResponseBodyParser.new)
756
756
  rescue
757
757
  on_exception
758
758
  end
759
-
760
- # Retieves the ACL (access control policy) for a bucket or object.
759
+
760
+ # Retieves the ACL (access control policy) for a bucket or object.
761
761
  # Returns a hash of {:owner, :grantees}
762
762
  #
763
763
  # s3.get_acl_parse('my_awesome_bucket', 'log/curent/1.log') #=>
@@ -791,7 +791,7 @@ module RightAws
791
791
  if result[:grantees].key?(key)
792
792
  result[:grantees][key][:permissions] << grantee[:permissions]
793
793
  else
794
- result[:grantees][key] =
794
+ result[:grantees][key] =
795
795
  { :display_name => grantee[:display_name] || grantee[:uri].to_s[/[^\/]*$/],
796
796
  :permissions => Array(grantee[:permissions]),
797
797
  :attributes => grantee[:attributes] }
@@ -801,7 +801,7 @@ module RightAws
801
801
  rescue
802
802
  on_exception
803
803
  end
804
-
804
+
805
805
  # Sets the ACL on a bucket or object.
806
806
  def put_acl(bucket, key, acl_xml_doc, headers={})
807
807
  key = key.right_blank? ? '' : "/#{CGI::escape key}"
@@ -810,14 +810,14 @@ module RightAws
810
810
  rescue
811
811
  on_exception
812
812
  end
813
-
813
+
814
814
  # Retieves the ACL (access control policy) for a bucket. Returns a hash of headers and xml doc with ACL data.
815
815
  def get_bucket_acl(bucket, headers={})
816
816
  return get_acl(bucket, '', headers)
817
817
  rescue
818
818
  on_exception
819
819
  end
820
-
820
+
821
821
  # Sets the ACL on a bucket only.
822
822
  def put_bucket_acl(bucket, acl_xml_doc, headers={})
823
823
  return put_acl(bucket, '', acl_xml_doc, headers)
@@ -838,7 +838,7 @@ module RightAws
838
838
  rescue
839
839
  on_exception
840
840
  end
841
-
841
+
842
842
  # Deletes all keys in bucket then deletes bucket. Returns +true+ or an exception.
843
843
  #
844
844
  # s3.force_delete_bucket('my_awesome_bucket')
@@ -849,7 +849,7 @@ module RightAws
849
849
  rescue
850
850
  on_exception
851
851
  end
852
-
852
+
853
853
  # Deletes all keys where the 'folder_key' may be assumed as 'folder' name. Returns an array of string keys that have been deleted.
854
854
  #
855
855
  # s3.list_bucket('my_awesome_bucket').map{|key_data| key_data[:key]} #=> ['test','test/2/34','test/3','test1','test1/logs']
@@ -867,7 +867,7 @@ module RightAws
867
867
  rescue
868
868
  on_exception
869
869
  end
870
-
870
+
871
871
  # Retrieves object data only (headers are omitted). Returns +string+ or an exception.
872
872
  #
873
873
  # s3.get('my_awesome_bucket', 'log/curent/1.log') #=> 'Ola-la!'
@@ -877,7 +877,7 @@ module RightAws
877
877
  rescue
878
878
  on_exception
879
879
  end
880
-
880
+
881
881
  #-----------------------------------------------------------------
882
882
  # Query API: Links
883
883
  #-----------------------------------------------------------------
@@ -903,7 +903,7 @@ module RightAws
903
903
  rescue
904
904
  on_exception
905
905
  end
906
-
906
+
907
907
  # Generates link for 'ListAllMyBuckets'.
908
908
  #
909
909
  # s3.list_all_my_buckets_link #=> url string
@@ -913,7 +913,7 @@ module RightAws
913
913
  rescue
914
914
  on_exception
915
915
  end
916
-
916
+
917
917
  # Generates link for 'CreateBucket'.
918
918
  #
919
919
  # s3.create_bucket_link('my_awesome_bucket') #=> url string
@@ -923,7 +923,7 @@ module RightAws
923
923
  rescue
924
924
  on_exception
925
925
  end
926
-
926
+
927
927
  # Generates link for 'DeleteBucket'.
928
928
  #
929
929
  # s3.delete_bucket_link('my_awesome_bucket') #=> url string
@@ -933,7 +933,7 @@ module RightAws
933
933
  rescue
934
934
  on_exception
935
935
  end
936
-
936
+
937
937
  # Generates link for 'ListBucket'.
938
938
  #
939
939
  # s3.list_bucket_link('my_awesome_bucket') #=> url string
@@ -944,7 +944,7 @@ module RightAws
944
944
  rescue
945
945
  on_exception
946
946
  end
947
-
947
+
948
948
  # Generates link for 'PutObject'.
949
949
  #
950
950
  # s3.put_link('my_awesome_bucket',key, object) #=> url string
@@ -954,16 +954,16 @@ module RightAws
954
954
  rescue
955
955
  on_exception
956
956
  end
957
-
957
+
958
958
  # Generates link for 'GetObject'.
959
959
  #
960
- # if a bucket comply with virtual hosting naming then retuns a link with the
960
+ # if a bucket comply with virtual hosting naming then retuns a link with the
961
961
  # bucket as a part of host name:
962
- #
962
+ #
963
963
  # s3.get_link('my-awesome-bucket',key) #=> https://my-awesome-bucket.s3.amazonaws.com:443/asia%2Fcustomers?Signature=nh7...
964
- #
964
+ #
965
965
  # otherwise returns an old style link (the bucket is a part of path):
966
- #
966
+ #
967
967
  # s3.get_link('my_awesome_bucket',key) #=> https://s3.amazonaws.com:443/my_awesome_bucket/asia%2Fcustomers?Signature=QAO...
968
968
  #
969
969
  # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html
@@ -984,7 +984,7 @@ module RightAws
984
984
  rescue
985
985
  on_exception
986
986
  end
987
-
987
+
988
988
  # Generates link for 'HeadObject'.
989
989
  #
990
990
  # s3.head_link('my_awesome_bucket',key) #=> url string
@@ -994,7 +994,7 @@ module RightAws
994
994
  rescue
995
995
  on_exception
996
996
  end
997
-
997
+
998
998
  # Generates link for 'DeleteObject'.
999
999
  #
1000
1000
  # s3.delete_link('my_awesome_bucket',key) #=> url string
@@ -1004,8 +1004,8 @@ module RightAws
1004
1004
  rescue
1005
1005
  on_exception
1006
1006
  end
1007
-
1008
-
1007
+
1008
+
1009
1009
  # Generates link for 'GetACL'.
1010
1010
  #
1011
1011
  # s3.get_acl_link('my_awesome_bucket',key) #=> url string
@@ -1015,7 +1015,7 @@ module RightAws
1015
1015
  rescue
1016
1016
  on_exception
1017
1017
  end
1018
-
1018
+
1019
1019
  # Generates link for 'PutACL'.
1020
1020
  #
1021
1021
  # s3.put_acl_link('my_awesome_bucket',key) #=> url string
@@ -1025,7 +1025,7 @@ module RightAws
1025
1025
  rescue
1026
1026
  on_exception
1027
1027
  end
1028
-
1028
+
1029
1029
  # Generates link for 'GetBucketACL'.
1030
1030
  #
1031
1031
  # s3.get_acl_link('my_awesome_bucket',key) #=> url string
@@ -1035,7 +1035,7 @@ module RightAws
1035
1035
  rescue
1036
1036
  on_exception
1037
1037
  end
1038
-
1038
+
1039
1039
  # Generates link for 'PutBucketACL'.
1040
1040
  #
1041
1041
  # s3.put_acl_link('my_awesome_bucket',key) #=> url string
@@ -1046,6 +1046,23 @@ module RightAws
1046
1046
  on_exception
1047
1047
  end
1048
1048
 
1049
+ class S3DeleteMultipleParser < RightAWSParser # :nodoc:
1050
+ def reset
1051
+ @result = []
1052
+ end
1053
+ def tagstart(name, attributes)
1054
+ @error = {} if name == 'Error'
1055
+ end
1056
+ def tagend(name)
1057
+ case name
1058
+ when 'Key' then @error[:key] = @text
1059
+ when 'Code' then @error[:code] = @text
1060
+ when 'Message' then @error[:message] = @text
1061
+ when 'Error' then @result << @error
1062
+ end
1063
+ end
1064
+ end
1065
+
1049
1066
  #-----------------------------------------------------------------
1050
1067
  # PARSERS:
1051
1068
  #-----------------------------------------------------------------
@@ -1139,7 +1156,7 @@ module RightAws
1139
1156
  when 'DisplayName' then @current_key[:owner_display_name] = @text
1140
1157
  when 'Contents' then @result[:contents] << @current_key
1141
1158
  # Common Prefix stuff
1142
- when 'CommonPrefixes'
1159
+ when 'CommonPrefixes'
1143
1160
  @result[:common_prefixes] = @common_prefixes
1144
1161
  @in_common_prefixes = false
1145
1162
  end
@@ -1187,7 +1204,7 @@ module RightAws
1187
1204
  end
1188
1205
  end
1189
1206
  end
1190
-
1207
+
1191
1208
  class S3LoggingParser < RightAWSParser # :nodoc:
1192
1209
  def reset
1193
1210
  @result = {:enabled => false, :targetbucket => '', :targetprefix => ''}
@@ -1221,24 +1238,7 @@ module RightAws
1221
1238
  end
1222
1239
  end
1223
1240
  end
1224
-
1225
- class S3DeleteMultipleParser < RightAWSParser # :nodoc:
1226
- def reset
1227
- @result = []
1228
- end
1229
- def tagstart(name, attributes)
1230
- @error = {}
1231
- end
1232
- def tagend(name)
1233
- case name
1234
- when 'Key' then current[:key] = @text
1235
- when 'Code' then current[:code] = @text
1236
- when 'Message' then current[:message] = @text
1237
- when 'Error' then @result << @error
1238
- end
1239
- end
1240
- end
1241
-
1241
+
1242
1242
  #-----------------------------------------------------------------
1243
1243
  # PARSERS: Non XML
1244
1244
  #-----------------------------------------------------------------
@@ -1260,8 +1260,8 @@ module RightAws
1260
1260
 
1261
1261
  class S3HttpResponseBodyParser < S3HttpResponseParser # :nodoc:
1262
1262
  def parse(response)
1263
- @result = {
1264
- :object => response.body,
1263
+ @result = {
1264
+ :object => response.body,
1265
1265
  :headers => headers_to_string(response.to_hash)
1266
1266
  }
1267
1267
  end
@@ -1272,7 +1272,7 @@ module RightAws
1272
1272
  @result = headers_to_string(response.to_hash)
1273
1273
  end
1274
1274
  end
1275
-
1275
+
1276
1276
  end
1277
1277
 
1278
1278
  end