aws 2.1.11 → 2.1.12

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.
@@ -22,7 +22,7 @@
22
22
  #
23
23
 
24
24
  module Aws
25
-
25
+
26
26
  # = Aws::S3 -- RightScale's Amazon S3 interface
27
27
  # The Aws::S3 class provides a complete interface to Amazon's Simple
28
28
  # Storage Service.
@@ -35,25 +35,25 @@ module Aws
35
35
  # Error handling: all operations raise an Aws::AwsError in case
36
36
  # of problems. Note that transient errors are automatically retried.
37
37
  #
38
- # It is a good way to use domain naming style getting a name for the buckets.
38
+ # It is a good way to use domain naming style getting a name for the buckets.
39
39
  # See http://docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingBucket.html
40
40
  # about the naming convention for the buckets. This case they can be accessed using a virtual domains.
41
- #
41
+ #
42
42
  # Let assume you have 3 buckets: 'awesome-bucket', 'awesome_bucket' and 'AWEsomE-bucket'.
43
43
  # The first ones objects can be accessed as: http:// awesome-bucket.s3.amazonaws.com/key/object
44
- #
44
+ #
45
45
  # But the rest have to be accessed as:
46
46
  # http:// s3.amazonaws.com/awesome_bucket/key/object and http:// s3.amazonaws.com/AWEsomE-bucket/key/object
47
- #
47
+ #
48
48
  # See: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html for better explanation.
49
49
  #
50
50
  class S3
51
51
  attr_reader :interface
52
-
52
+
53
53
  # Create a new handle to an S3 account. All handles share the same per process or per thread
54
54
  # HTTP connection to Amazon S3. Each handle is for a specific account.
55
55
  # The +params+ are passed through as-is to Aws::S3Interface.new
56
- #
56
+ #
57
57
  # Params is a hash:
58
58
  #
59
59
  # {:server => 's3.amazonaws.com' # Amazon service host: 's3.amazonaws.com'(default)
@@ -64,7 +64,7 @@ module Aws
64
64
  def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
65
65
  @interface = S3Interface.new(aws_access_key_id, aws_secret_access_key, params)
66
66
  end
67
-
67
+
68
68
  # Retrieve a list of buckets.
69
69
  # Returns an array of Aws::S3::Bucket instances.
70
70
  # # Create handle to S3 account
@@ -77,7 +77,7 @@ module Aws
77
77
  Bucket.new(self, entry[:name], entry[:creation_date], owner)
78
78
  end
79
79
  end
80
-
80
+
81
81
  # Retrieve an individual bucket.
82
82
  # If the bucket does not exist and +create+ is set, a new bucket
83
83
  # is created on S3. Launching this method with +create+=+true+ may
@@ -93,26 +93,29 @@ module Aws
93
93
  # bucket2.keys #=> list of keys
94
94
  # # create a bucket at the European location with public read access
95
95
  # bucket3 = s3.bucket('my-awesome-bucket-3', true, 'public-read', :location => :eu)
96
- #
96
+ #
97
97
  # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
98
98
  # (section: Canned Access Policies)
99
99
  #
100
100
  def bucket(name, create=false, perms=nil, headers={})
101
101
  headers['x-amz-acl'] = perms if perms
102
102
  @interface.create_bucket(name, headers) if create
103
- buckets.each { |bucket| return bucket if bucket.name == name }
104
- nil
103
+ return Bucket.new(self, name)
104
+ # The old way below was too slow and unnecessary because it retreived all the buckets every time.
105
+ # owner = Owner.new(entry[:owner_id], entry[:owner_display_name])
106
+ # buckets.each { |bucket| return bucket if bucket.name == name }
107
+ # nil
105
108
  end
106
-
109
+
107
110
 
108
111
  class Bucket
109
112
  attr_reader :s3, :name, :owner, :creation_date
110
-
113
+
111
114
  # Create a Bucket instance.
112
115
  # If the bucket does not exist and +create+ is set, a new bucket
113
116
  # is created on S3. Launching this method with +create+=+true+ may
114
117
  # affect on the bucket's ACL if the bucket already exists.
115
- # Returns Bucket instance or +nil+ if the bucket does not exist
118
+ # Returns Bucket instance or +nil+ if the bucket does not exist
116
119
  # and +create+ is not set.
117
120
  #
118
121
  # s3 = Aws::S3.new(aws_access_key_id, aws_secret_access_key)
@@ -124,11 +127,11 @@ module Aws
124
127
  # bucket2.keys #=> list of keys
125
128
  # # create a bucket at the European location with public read access
126
129
  # bucket3 = Aws::S3::Bucket.create(s3,'my-awesome-bucket-3', true, 'public-read', :location => :eu)
127
- #
130
+ #
128
131
  # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
129
132
  # (section: Canned Access Policies)
130
133
  #
131
- def self.create(s3, name, create=false, perms=nil, headers={})
134
+ def self.create(s3, name, create=false, perms=nil, headers={})
132
135
  s3.bucket(name, create, perms, headers)
133
136
  end
134
137
 
@@ -145,7 +148,7 @@ module Aws
145
148
  @creation_date = Time.parse(@creation_date)
146
149
  end
147
150
  end
148
-
151
+
149
152
  # Return bucket name as a String.
150
153
  #
151
154
  # bucket = Aws::S3.bucket('my_awesome_bucket')
@@ -155,30 +158,30 @@ module Aws
155
158
  @name.to_s
156
159
  end
157
160
  alias_method :full_name, :to_s
158
-
161
+
159
162
  # Return a public link to bucket.
160
- #
163
+ #
161
164
  # bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'
162
165
  #
163
166
  def public_link
164
167
  params = @s3.interface.params
165
168
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
166
169
  end
167
-
170
+
168
171
  # Returns the bucket location
169
172
  def location
170
173
  @location ||= @s3.interface.bucket_location(@name)
171
174
  end
172
-
173
- # Retrieves the logging configuration for a bucket.
175
+
176
+ # Retrieves the logging configuration for a bucket.
174
177
  # Returns a hash of {:enabled, :targetbucket, :targetprefix}
175
- #
178
+ #
176
179
  # bucket.logging_info()
177
180
  # => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}
178
181
  def logging_info
179
182
  @s3.interface.get_logging_parse(:bucket => @name)
180
183
  end
181
-
184
+
182
185
  # Enables S3 server access logging on a bucket. The target bucket must have been properly configured to receive server
183
186
  # access logs.
184
187
  # Params:
@@ -193,17 +196,17 @@ module Aws
193
196
  xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><LoggingEnabled><TargetBucket>#{params[:targetbucket]}</TargetBucket><TargetPrefix>#{params[:targetprefix]}</TargetPrefix></LoggingEnabled></BucketLoggingStatus>"
194
197
  @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
195
198
  end
196
-
199
+
197
200
  # Disables S3 server access logging on a bucket. Takes no arguments.
198
201
  def disable_logging
199
202
  xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"></BucketLoggingStatus>"
200
203
  @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
201
204
  end
202
205
 
203
- # Retrieve a group of keys from Amazon.
204
- # +options+ is a hash: { 'prefix'=>'', 'marker'=>'', 'max-keys'=>5, 'delimiter'=>'' }).
205
- # Retrieves meta-headers information if +head+ it +true+.
206
- # Returns an array of Key instances.
206
+ # Retrieve a group of keys from Amazon.
207
+ # +options+ is a hash: { 'prefix'=>'', 'marker'=>'', 'max-keys'=>5, 'delimiter'=>'' }).
208
+ # Retrieves meta-headers information if +head+ it +true+.
209
+ # Returns an array of Key instances.
207
210
  #
208
211
  # bucket.keys #=> # returns all keys from bucket
209
212
  # bucket.keys('prefix' => 'logs') #=> # returns all keys that starts with 'logs'
@@ -212,7 +215,7 @@ module Aws
212
215
  keys_and_service(options, head)[0]
213
216
  end
214
217
 
215
- # Same as +keys+ method but return an array of [keys, service_data].
218
+ # Same as +keys+ method but return an array of [keys, service_data].
216
219
  # where +service_data+ is a hash with additional output information.
217
220
  #
218
221
  # keys, service = bucket.keys_and_service({'max-keys'=> 2, 'prefix' => 'logs'})
@@ -238,10 +241,10 @@ module Aws
238
241
  [list, service_data]
239
242
  end
240
243
 
241
- # Retrieve key information from Amazon.
242
- # The +key_name+ is a +String+ or Key instance.
243
- # Retrieves meta-header information if +head+ is +true+.
244
- # Returns new Key instance.
244
+ # Retrieve key information from Amazon.
245
+ # The +key_name+ is a +String+ or Key instance.
246
+ # Retrieves meta-header information if +head+ is +true+.
247
+ # Returns new Key instance.
245
248
  #
246
249
  # key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
247
250
  # # is the same as:
@@ -264,23 +267,23 @@ module Aws
264
267
  end
265
268
  key_instance
266
269
  end
267
-
268
- # Store object data.
269
- # The +key+ is a +String+ or Key instance.
270
+
271
+ # Store object data.
272
+ # The +key+ is a +String+ or Key instance.
270
273
  # Returns +true+.
271
274
  #
272
275
  # bucket.put('logs/today/1.log', 'Olala!') #=> true
273
276
  #
274
277
  def put(key, data=nil, meta_headers={}, perms=nil, headers={})
275
- key = Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(Key)
278
+ key = Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(Key)
276
279
  key.put(data, perms, headers)
277
280
  end
278
281
 
279
- # Retrieve object data from Amazon.
280
- # The +key+ is a +String+ or Key.
281
- # Returns Key instance.
282
+ # Retrieve object data from Amazon.
283
+ # The +key+ is a +String+ or Key.
284
+ # Returns Key instance.
282
285
  #
283
- # key = bucket.get('logs/today/1.log') #=>
286
+ # key = bucket.get('logs/today/1.log') #=>
284
287
  # puts key.data #=> 'sasfasfasdf'
285
288
  #
286
289
  def get(key, headers={})
@@ -289,7 +292,7 @@ module Aws
289
292
  end
290
293
 
291
294
  # Rename object. Returns Aws::S3::Key instance.
292
- #
295
+ #
293
296
  # new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
294
297
  # puts key.name #=> 'logs/today/2.log'
295
298
  # key.exists? #=> true
@@ -301,7 +304,7 @@ module Aws
301
304
  end
302
305
 
303
306
  # Create an object copy. Returns a destination Aws::S3::Key instance.
304
- #
307
+ #
305
308
  # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
306
309
  # puts key.name #=> 'logs/today/2.log'
307
310
  # key.exists? #=> true
@@ -310,9 +313,9 @@ module Aws
310
313
  old_key_or_name = Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(Key)
311
314
  old_key_or_name.copy(new_key_or_name)
312
315
  end
313
-
316
+
314
317
  # Move an object to other location. Returns a destination Aws::S3::Key instance.
315
- #
318
+ #
316
319
  # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
317
320
  # puts key.name #=> 'logs/today/2.log'
318
321
  # key.exists? #=> true
@@ -321,18 +324,18 @@ module Aws
321
324
  old_key_or_name = Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(Key)
322
325
  old_key_or_name.move(new_key_or_name)
323
326
  end
324
-
325
- # Remove all keys from a bucket.
326
- # Returns +true+.
327
+
328
+ # Remove all keys from a bucket.
329
+ # Returns +true+.
327
330
  #
328
331
  # bucket.clear #=> true
329
332
  #
330
333
  def clear
331
- @s3.interface.clear_bucket(@name)
334
+ @s3.interface.clear_bucket(@name)
332
335
  end
333
336
 
334
337
  # Delete all keys where the 'folder_key' can be interpreted
335
- # as a 'folder' name.
338
+ # as a 'folder' name.
336
339
  # Returns an array of string keys that have been deleted.
337
340
  #
338
341
  # bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
@@ -341,10 +344,10 @@ module Aws
341
344
  def delete_folder(folder, separator='/')
342
345
  @s3.interface.delete_folder(@name, folder, separator)
343
346
  end
344
-
347
+
345
348
  # Delete a bucket. Bucket must be empty.
346
- # If +force+ is set, clears and deletes the bucket.
347
- # Returns +true+.
349
+ # If +force+ is set, clears and deletes the bucket.
350
+ # Returns +true+.
348
351
  #
349
352
  # bucket.delete(true) #=> true
350
353
  #
@@ -352,7 +355,7 @@ module Aws
352
355
  force ? @s3.interface.force_delete_bucket(@name) : @s3.interface.delete_bucket(@name)
353
356
  end
354
357
 
355
- # Return a list of grantees.
358
+ # Return a list of grantees.
356
359
  #
357
360
  def grantees
358
361
  Grantee::grantees(self)
@@ -378,7 +381,7 @@ module Aws
378
381
  end
379
382
  [hash, meta]
380
383
  end
381
-
384
+
382
385
  def self.add_meta_prefix(meta_headers, prefix=S3Interface::AMAZON_METADATA_PREFIX)
383
386
  meta = {}
384
387
  meta_headers.each do |meta_header, value|
@@ -392,9 +395,9 @@ module Aws
392
395
  end
393
396
 
394
397
 
395
- # Create a new Key instance, but do not create the actual key.
398
+ # Create a new Key instance, but do not create the actual key.
396
399
  # The +name+ is a +String+.
397
- # Returns a new Key instance.
400
+ # Returns a new Key instance.
398
401
  #
399
402
  # key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
400
403
  # key.exists? #=> true | false
@@ -404,12 +407,12 @@ module Aws
404
407
  def self.create(bucket, name, data=nil, meta_headers={})
405
408
  new(bucket, name, data, {}, meta_headers)
406
409
  end
407
-
410
+
408
411
  # Create a new Key instance, but do not create the actual key.
409
412
  # In normal use this method should not be called directly.
410
413
  # Use Aws::S3::Key.create or bucket.key() instead.
411
414
  #
412
- def initialize(bucket, name, data=nil, headers={}, meta_headers={},
415
+ def initialize(bucket, name, data=nil, headers={}, meta_headers={},
413
416
  last_modified=nil, e_tag=nil, size=nil, storage_class=nil, owner=nil)
414
417
  raise 'Bucket must be a Bucket instance.' unless bucket.is_a?(Bucket)
415
418
  @bucket = bucket
@@ -420,13 +423,13 @@ module Aws
420
423
  @storage_class = storage_class
421
424
  @owner = owner
422
425
  @last_modified = last_modified
423
- if @last_modified && !@last_modified.is_a?(Time)
426
+ if @last_modified && !@last_modified.is_a?(Time)
424
427
  @last_modified = Time.parse(@last_modified)
425
428
  end
426
429
  @headers, @meta_headers = self.class.split_meta(headers)
427
430
  @meta_headers.merge!(meta_headers)
428
431
  end
429
-
432
+
430
433
  # Return key name as a String.
431
434
  #
432
435
  # key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
@@ -435,24 +438,24 @@ module Aws
435
438
  def to_s
436
439
  @name.to_s
437
440
  end
438
-
441
+
439
442
  # Return the full S3 path to this key (bucket/key).
440
- #
443
+ #
441
444
  # key.full_name #=> 'my_awesome_bucket/cool_key'
442
445
  #
443
446
  def full_name(separator='/')
444
447
  "#{@bucket.to_s}#{separator}#{@name}"
445
448
  end
446
-
449
+
447
450
  # Return a public link to a key.
448
- #
451
+ #
449
452
  # key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'
450
453
  #
451
454
  def public_link
452
455
  params = @bucket.s3.interface.params
453
456
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name('/')}"
454
457
  end
455
-
458
+
456
459
  # Return Key data. Retrieve this data from Amazon if it is the first time call.
457
460
  # TODO TRB 6/19/07 What does the above mean? Clarify.
458
461
  #
@@ -460,9 +463,9 @@ module Aws
460
463
  get if !@data and exists?
461
464
  @data
462
465
  end
463
-
464
- # Retrieve object data and attributes from Amazon.
465
- # Returns a +String+.
466
+
467
+ # Retrieve object data and attributes from Amazon.
468
+ # Returns a +String+.
466
469
  #
467
470
  def get(headers={}, &block)
468
471
  response = @bucket.s3.interface.get(@bucket.name, @name, headers, &block)
@@ -471,9 +474,9 @@ module Aws
471
474
  refresh(false)
472
475
  @data
473
476
  end
474
-
475
- # Store object data on S3.
476
- # Parameter +data+ is a +String+ or S3Object instance.
477
+
478
+ # Store object data on S3.
479
+ # Parameter +data+ is a +String+ or S3Object instance.
477
480
  # Returns +true+.
478
481
  #
479
482
  # key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
@@ -488,9 +491,9 @@ module Aws
488
491
  meta = self.class.add_meta_prefix(@meta_headers)
489
492
  @bucket.s3.interface.put(@bucket.name, @name, @data, meta.merge(headers))
490
493
  end
491
-
494
+
492
495
  # Rename an object. Returns new object name.
493
- #
496
+ #
494
497
  # key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
495
498
  # key.rename('logs/today/2.log') #=> 'logs/today/2.log'
496
499
  # puts key.name #=> 'logs/today/2.log'
@@ -500,7 +503,7 @@ module Aws
500
503
  @bucket.s3.interface.rename(@bucket.name, @name, new_name)
501
504
  @name = new_name
502
505
  end
503
-
506
+
504
507
  # Create an object copy. Returns a destination Aws::S3::Key instance.
505
508
  #
506
509
  # # Key instance as destination
@@ -535,7 +538,7 @@ module Aws
535
538
  # key1.exists? #=> false
536
539
  # key2.exists? #=> true
537
540
  # puts key2.data #=> 'Olala!'
538
- #
541
+ #
539
542
  # # String as destination
540
543
  # key = Aws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
541
544
  # key.put('Olala!') #=> true
@@ -548,10 +551,10 @@ module Aws
548
551
  @bucket.s3.interface.move(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name)
549
552
  new_key_or_name
550
553
  end
551
-
554
+
552
555
  # Retrieve key info from bucket and update attributes.
553
- # Refresh meta-headers (by calling +head+ method) if +head+ is set.
554
- # Returns +true+ if the key exists in bucket and +false+ otherwise.
556
+ # Refresh meta-headers (by calling +head+ method) if +head+ is set.
557
+ # Returns +true+ if the key exists in bucket and +false+ otherwise.
555
558
  #
556
559
  # key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
557
560
  # key.e_tag #=> nil
@@ -577,7 +580,7 @@ module Aws
577
580
  end
578
581
 
579
582
  # Updates headers and meta-headers from S3.
580
- # Returns +true+.
583
+ # Returns +true+.
581
584
  #
582
585
  # key.meta_headers #=> {"family"=>"qwerty"}
583
586
  # key.head #=> true
@@ -587,7 +590,7 @@ module Aws
587
590
  @headers, @meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name))
588
591
  true
589
592
  end
590
-
593
+
591
594
  # Reload meta-headers only. Returns meta-headers hash.
592
595
  #
593
596
  # key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
@@ -595,7 +598,7 @@ module Aws
595
598
  def reload_meta
596
599
  @meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name)).last
597
600
  end
598
-
601
+
599
602
  # Replace meta-headers by new hash at S3. Returns new meta-headers hash.
600
603
  #
601
604
  # key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
@@ -607,9 +610,9 @@ module Aws
607
610
  @bucket.s3.interface.copy(@bucket.name, @name, @bucket.name, @name, :replace, meta)
608
611
  @meta_headers = self.class.split_meta(meta)[1]
609
612
  end
610
-
611
- # Check for existence of the key in the given bucket.
612
- # Returns +true+ or +false+.
613
+
614
+ # Check for existence of the key in the given bucket.
615
+ # Returns +true+ or +false+.
613
616
  #
614
617
  # key = Aws::S3::Key.create(bucket,'logs/today/1.log')
615
618
  # key.exists? #=> false
@@ -619,53 +622,53 @@ module Aws
619
622
  def exists?
620
623
  @bucket.key(self).last_modified ? true : false
621
624
  end
622
-
623
- # Remove key from bucket.
624
- # Returns +true+.
625
+
626
+ # Remove key from bucket.
627
+ # Returns +true+.
625
628
  #
626
629
  # key.delete #=> true
627
630
  #
628
631
  def delete
629
632
  raise 'Key name must be specified.' if @name.blank?
630
- @bucket.s3.interface.delete(@bucket, @name)
633
+ @bucket.s3.interface.delete(@bucket, @name)
631
634
  end
632
-
633
- # Return a list of grantees.
635
+
636
+ # Return a list of grantees.
634
637
  #
635
638
  def grantees
636
639
  Grantee::grantees(self)
637
640
  end
638
-
641
+
639
642
  end
640
-
643
+
641
644
 
642
645
  class Owner
643
646
  attr_reader :id, :name
644
-
647
+
645
648
  def initialize(id, name)
646
649
  @id = id
647
650
  @name = name
648
651
  end
649
-
652
+
650
653
  # Return Owner name as a +String+.
651
654
  def to_s
652
655
  @name
653
656
  end
654
657
  end
655
-
656
-
658
+
659
+
657
660
  # There are 2 ways to set permissions for a bucket or key (called a +thing+ below):
658
661
  #
659
- # 1 . Use +perms+ param to set 'Canned Access Policies' when calling the <tt>bucket.create</tt>,
660
- # <tt>bucket.put</tt> and <tt>key.put</tt> methods.
662
+ # 1 . Use +perms+ param to set 'Canned Access Policies' when calling the <tt>bucket.create</tt>,
663
+ # <tt>bucket.put</tt> and <tt>key.put</tt> methods.
661
664
  # The +perms+ param can take these values: 'private', 'public-read', 'public-read-write' and
662
- # 'authenticated-read'.
665
+ # 'authenticated-read'.
663
666
  # (see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html).
664
667
  #
665
668
  # bucket = s3.bucket('bucket_for_kd_test_13', true, 'public-read')
666
669
  # key.put('Woohoo!','public-read-write' )
667
670
  #
668
- # 2 . Use Grantee instances (the permission is a +String+ or an +Array+ of: 'READ', 'WRITE',
671
+ # 2 . Use Grantee instances (the permission is a +String+ or an +Array+ of: 'READ', 'WRITE',
669
672
  # 'READ_ACP', 'WRITE_ACP', 'FULL_CONTROL'):
670
673
  #
671
674
  # bucket = s3.bucket('my_awesome_bucket', true)
@@ -690,9 +693,9 @@ module Aws
690
693
  attr_reader :name
691
694
  # Array of permissions.
692
695
  attr_accessor :perms
693
-
696
+
694
697
  # Retrieve Owner information and a list of Grantee instances that have
695
- # a access to this thing (bucket or key).
698
+ # a access to this thing (bucket or key).
696
699
  #
697
700
  # bucket = s3.bucket('my_awesome_bucket', true, 'public-read')
698
701
  # ...
@@ -706,7 +709,7 @@ module Aws
706
709
  end
707
710
  hash = bucket.s3.interface.get_acl_parse(bucket.to_s, key.to_s)
708
711
  owner = Owner.new(hash[:owner][:id], hash[:owner][:display_name])
709
-
712
+
710
713
  grantees = []
711
714
  hash[:grantees].each do |id, params|
712
715
  grantees << new(thing, id, params[:permissions], nil, params[:display_name])
@@ -714,7 +717,7 @@ module Aws
714
717
  [owner, grantees]
715
718
  end
716
719
 
717
- # Retrieves a list of Grantees instances that have an access to this thing(bucket or key).
720
+ # Retrieves a list of Grantees instances that have an access to this thing(bucket or key).
718
721
  #
719
722
  # bucket = s3.bucket('my_awesome_bucket', true, 'public-read')
720
723
  # ...
@@ -742,11 +745,11 @@ module Aws
742
745
  bucket.s3.interface.put_acl(bucket.to_s, key.to_s, body)
743
746
  end
744
747
 
745
- # Create a new Grantee instance.
748
+ # Create a new Grantee instance.
746
749
  # Grantee +id+ must exist on S3. If +action+ == :refresh, then retrieve
747
750
  # permissions from S3 and update @perms. If +action+ == :apply, then apply
748
751
  # perms to +thing+ at S3. If +action+ == :apply_and_refresh then it performs.
749
- # both the actions. This is used for the new grantees that had no perms to
752
+ # both the actions. This is used for the new grantees that had no perms to
750
753
  # this thing before. The default action is :refresh.
751
754
  #
752
755
  # bucket = s3.bucket('my_awesome_bucket', true, 'public-read')
@@ -766,7 +769,7 @@ module Aws
766
769
  when :apply_and_refresh then apply; refresh
767
770
  end
768
771
  end
769
-
772
+
770
773
  # Return +true+ if the grantee has any permissions to the thing.
771
774
  def exists?
772
775
  self.class.grantees(@thing).each do |grantee|
@@ -774,26 +777,26 @@ module Aws
774
777
  end
775
778
  false
776
779
  end
777
-
780
+
778
781
  # Return Grantee type (+String+): "Group" or "CanonicalUser".
779
782
  def type
780
783
  @id[/^http:/] ? "Group" : "CanonicalUser"
781
784
  end
782
-
785
+
783
786
  # Return a name or an id.
784
787
  def to_s
785
788
  @name || @id
786
789
  end
787
-
788
- # Add permissions for grantee.
789
- # Permissions: 'READ', 'WRITE', 'READ_ACP', 'WRITE_ACP', 'FULL_CONTROL'.
790
+
791
+ # Add permissions for grantee.
792
+ # Permissions: 'READ', 'WRITE', 'READ_ACP', 'WRITE_ACP', 'FULL_CONTROL'.
790
793
  # See http://docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingPermissions.html .
791
- # Returns +true+.
794
+ # Returns +true+.
792
795
  #
793
796
  # grantee.grant('FULL_CONTROL') #=> true
794
797
  # grantee.grant('FULL_CONTROL','WRITE','READ') #=> true
795
798
  # grantee.grant(['WRITE_ACP','READ','READ_ACP']) #=> true
796
- #
799
+ #
797
800
  def grant(*permissions)
798
801
  permissions.flatten!
799
802
  old_perms = @perms.dup
@@ -802,11 +805,11 @@ module Aws
802
805
  return true if @perms == old_perms
803
806
  apply
804
807
  end
805
-
806
- # Revoke permissions for grantee.
808
+
809
+ # Revoke permissions for grantee.
807
810
  # Permissions: 'READ', 'WRITE', 'READ_ACP', 'WRITE_ACP', 'FULL_CONTROL'
808
811
  # See http://docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingPermissions.html .
809
- # Default value is 'FULL_CONTROL'.
812
+ # Default value is 'FULL_CONTROL'.
810
813
  # Returns +true+.
811
814
  #
812
815
  # grantee.revoke('READ') #=> true
@@ -821,8 +824,8 @@ module Aws
821
824
  return true if @perms == old_perms
822
825
  apply
823
826
  end
824
-
825
- # Revoke all permissions for this grantee.
827
+
828
+ # Revoke all permissions for this grantee.
826
829
  # Returns +true+.
827
830
  #
828
831
  # grantee.drop #=> true
@@ -831,7 +834,7 @@ module Aws
831
834
  @perms = []
832
835
  apply
833
836
  end
834
-
837
+
835
838
  # Refresh grantee perms for its +thing+.
836
839
  # Returns +true+ if the grantee has perms for this +thing+ or
837
840
  # +false+ otherwise, and updates @perms value as a side-effect.
@@ -856,7 +859,7 @@ module Aws
856
859
  # Apply current grantee @perms to +thing+. This method is called internally by the +grant+
857
860
  # and +revoke+ methods. In normal use this method should not
858
861
  # be called directly.
859
- #
862
+ #
860
863
  # grantee.perms = ['FULL_CONTROL']
861
864
  # grantee.apply #=> true
862
865
  #
@@ -885,7 +888,7 @@ module Aws
885
888
  end
886
889
 
887
890
  end
888
-
891
+
889
892
  end
890
893
 
891
894
  # Aws::S3Generator and Aws::S3Generator::Bucket methods:
@@ -927,11 +930,11 @@ module Aws
927
930
  #
928
931
  class S3Generator
929
932
  attr_reader :interface
930
-
933
+
931
934
  def initialize(aws_access_key_id, aws_secret_access_key, params={})
932
935
  @interface = S3Interface.new(aws_access_key_id, aws_secret_access_key, params)
933
936
  end
934
-
937
+
935
938
  # Generate link to list all buckets
936
939
  #
937
940
  # s3.buckets(1.hour)
@@ -947,41 +950,41 @@ module Aws
947
950
  def bucket(name, expires=nil, headers={})
948
951
  Bucket.create(self, name.to_s)
949
952
  end
950
-
953
+
951
954
  class Bucket
952
955
  attr_reader :s3, :name
953
-
956
+
954
957
  def to_s
955
958
  @name
956
959
  end
957
960
  alias_method :full_name, :to_s
958
-
961
+
959
962
  # Return a public link to bucket.
960
- #
963
+ #
961
964
  # bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'
962
965
  #
963
966
  def public_link
964
967
  params = @s3.interface.params
965
968
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
966
969
  end
967
-
968
- # Create new S3LinkBucket instance and generate creation link for it.
970
+
971
+ # Create new S3LinkBucket instance and generate creation link for it.
969
972
  def self.create(s3, name, expires=nil, headers={})
970
973
  new(s3, name.to_s)
971
974
  end
972
-
973
- # Create new S3LinkBucket instance.
975
+
976
+ # Create new S3LinkBucket instance.
974
977
  def initialize(s3, name)
975
978
  @s3, @name = s3, name.to_s
976
979
  end
977
-
978
- # Return a link to create this bucket.
980
+
981
+ # Return a link to create this bucket.
979
982
  #
980
983
  def create_link(expires=nil, headers={})
981
984
  @s3.interface.create_bucket_link(@name, expires, headers)
982
985
  end
983
986
 
984
- # Generate link to list keys.
987
+ # Generate link to list keys.
985
988
  #
986
989
  # bucket.keys
987
990
  # bucket.keys('prefix'=>'logs')
@@ -999,7 +1002,7 @@ module Aws
999
1002
  Key.new(self, name)
1000
1003
  end
1001
1004
 
1002
- # Generates link to PUT key data.
1005
+ # Generates link to PUT key data.
1003
1006
  #
1004
1007
  # puts bucket.put('logs/today/1.log', 2.hour)
1005
1008
  #
@@ -1007,16 +1010,16 @@ module Aws
1007
1010
  meta = Aws::S3::Key.add_meta_prefix(meta_headers)
1008
1011
  @s3.interface.put_link(@name, key.to_s, nil, expires, meta.merge(headers))
1009
1012
  end
1010
-
1011
- # Generate link to GET key data.
1013
+
1014
+ # Generate link to GET key data.
1012
1015
  #
1013
1016
  # bucket.get('logs/today/1.log', 1.hour)
1014
1017
  #
1015
1018
  def get(key, expires=nil, headers={})
1016
1019
  @s3.interface.get_link(@name, key.to_s, expires, headers)
1017
1020
  end
1018
-
1019
- # Generate link to delete bucket.
1021
+
1022
+ # Generate link to delete bucket.
1020
1023
  #
1021
1024
  # bucket.delete(2.hour)
1022
1025
  #
@@ -1028,60 +1031,60 @@ module Aws
1028
1031
 
1029
1032
  class Key
1030
1033
  attr_reader :bucket, :name
1031
-
1034
+
1032
1035
  def to_s
1033
1036
  @name
1034
1037
  end
1035
-
1038
+
1036
1039
  # Return a full S# name (bucket/key).
1037
- #
1040
+ #
1038
1041
  # key.full_name #=> 'my_awesome_bucket/cool_key'
1039
1042
  #
1040
1043
  def full_name(separator='/')
1041
1044
  "#{@bucket.to_s}#{separator}#{@name}"
1042
1045
  end
1043
-
1046
+
1044
1047
  # Return a public link to key.
1045
- #
1048
+ #
1046
1049
  # key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'
1047
1050
  #
1048
1051
  def public_link
1049
1052
  params = @bucket.s3.interface.params
1050
1053
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name('/')}"
1051
1054
  end
1052
-
1055
+
1053
1056
  def initialize(bucket, name, meta_headers={})
1054
1057
  @bucket = bucket
1055
1058
  @name = name.to_s
1056
1059
  @meta_headers = meta_headers
1057
1060
  raise 'Key name can not be empty.' if @name.blank?
1058
1061
  end
1059
-
1060
- # Generate link to PUT key data.
1062
+
1063
+ # Generate link to PUT key data.
1061
1064
  #
1062
1065
  # puts bucket.put('logs/today/1.log', '123', 2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=B...D&Expires=1180820032&AWSAccessKeyId=1...2
1063
1066
  #
1064
1067
  def put(expires=nil, headers={})
1065
1068
  @bucket.put(@name.to_s, @meta_headers, expires, headers)
1066
1069
  end
1067
-
1068
- # Generate link to GET key data.
1070
+
1071
+ # Generate link to GET key data.
1069
1072
  #
1070
1073
  # bucket.get('logs/today/1.log', 1.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=h...M%3D&Expires=1180820032&AWSAccessKeyId=1...2
1071
1074
  #
1072
1075
  def get(expires=nil, headers={})
1073
1076
  @bucket.s3.interface.get_link(@bucket.to_s, @name, expires, headers)
1074
1077
  end
1075
-
1076
- # Generate link to delete key.
1078
+
1079
+ # Generate link to delete key.
1077
1080
  #
1078
1081
  # bucket.delete(2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=4...D&Expires=1180820032&AWSAccessKeyId=1...2
1079
1082
  #
1080
1083
  def delete(expires=nil, headers={})
1081
1084
  @bucket.s3.interface.delete_link(@bucket.to_s, @name, expires, headers)
1082
1085
  end
1083
-
1084
- # Generate link to head key.
1086
+
1087
+ # Generate link to head key.
1085
1088
  #
1086
1089
  # bucket.head(2.hour) #=> https://s3.amazonaws.com:443/my_awesome_bucket/logs%2Ftoday%2F1.log?Signature=4...D&Expires=1180820032&AWSAccessKeyId=1...2
1087
1090
  #
@@ -383,7 +383,8 @@ module Aws
383
383
  @next_token = query_result[:next_token]
384
384
  items = query_result[:items].map do |hash|
385
385
  id, attributes = hash.shift
386
- new_item = self.new( attributes.merge({ 'id' => id }))
386
+ new_item = self.new( )
387
+ new_item.initialize_from_db(attributes.merge({ 'id' => id }))
387
388
  new_item.mark_as_old
388
389
  new_item
389
390
  end
@@ -600,6 +601,11 @@ module Aws
600
601
  @new_record = true
601
602
  end
602
603
 
604
+ # This is to separate initialization from user vs coming from db (ie: find())
605
+ def initialize_from_db(attrs={})
606
+ initialize(attrs)
607
+ end
608
+
603
609
  # Create and save new Item instance.
604
610
  # +Attributes+ is a hash: { attribute1 => values1, ..., attributeN => valuesN }.
605
611
  #
@@ -794,6 +800,7 @@ module Aws
794
800
  def save(options={})
795
801
  pre_save2
796
802
  atts_to_save = @attributes.dup
803
+ #puts 'atts_to_save=' + atts_to_save.inspect
797
804
  #options = params.first.is_a?(Hash) ? params.pop : {}
798
805
  if options[:except]
799
806
  options[:except].each do |e|
@@ -805,6 +812,7 @@ module Aws
805
812
  dirty_atts = options[:dirty_atts]
806
813
  atts_to_save.delete_if { |key, value| !dirty_atts.has_key?(key) }
807
814
  end
815
+ #puts 'atts_to_save2=' + atts_to_save.inspect
808
816
  connection.put_attributes(domain, id, atts_to_save, :replace)
809
817
  apres_save2
810
818
  @attributes
@@ -122,7 +122,20 @@ module Aws
122
122
  conn_mode = @params[:connection_mode]
123
123
  if conn_mode == :per_request
124
124
  http_conn = Rightscale::HttpConnection.new(:exception => AwsError, :logger => @logger)
125
- ret = request_info_impl(http_conn, @@bench, request, parser)
125
+ retry_count = 1
126
+ count = 0
127
+ while count < retry_count
128
+ puts 'RETRYING QUERY due to QueryTimeout...' if count > 0
129
+ begin
130
+ ret = request_info_impl(http_conn, @@bench, request, parser)
131
+ break
132
+ rescue Aws::AwsError => ex
133
+ if !ex.include?(/QueryTimeout/)
134
+ raise ex
135
+ end
136
+ end
137
+ count += 1
138
+ end
126
139
  http_conn.finish
127
140
  elsif conn_mode == :per_thread || conn_mode == :single
128
141
  thread = conn_mode == :per_thread ? Thread.current : Thread.main
@@ -87,8 +87,9 @@ module Aws
87
87
  # Aws::Sqs.queue('my_awesome_queue') #=> #<Aws::Sqs::Queue:0xb7b626e4 ... >
88
88
  #
89
89
  def queue(queue_name, create=true, visibility=nil)
90
- url = @interface.queue_url_by_name(queue_name)
91
- url = (create ? @interface.create_queue(queue_name, visibility) : nil) unless url
90
+ # url = @interface.queue_url_by_name(queue_name)
91
+ # url = (create ? @interface.create_queue(queue_name, visibility) : nil) unless url
92
+ url = @interface.create_queue(queue_name, visibility) # this returns the url even if it exists
92
93
  url ? Queue.new(self, url) : nil
93
94
  end
94
95
 
@@ -38,10 +38,10 @@ module Aws
38
38
  class SqsInterface < AwsBase
39
39
  include AwsBaseInterface
40
40
 
41
- API_VERSION = "2008-01-01"
41
+ API_VERSION = "2009-02-01"
42
42
  DEFAULT_HOST = "queue.amazonaws.com"
43
- DEFAULT_PORT = 80
44
- DEFAULT_PROTOCOL = 'http'
43
+ DEFAULT_PORT = 443
44
+ DEFAULT_PROTOCOL = 'https'
45
45
  REQUEST_TTL = 30
46
46
  DEFAULT_VISIBILITY_TIMEOUT = 30
47
47
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.11
4
+ version: 2.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-12-04 00:00:00 -08:00
14
+ date: 2009-12-18 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency