aws-sdk 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/ELB-2011-08-15.yml +380 -0
  3. data/lib/aws/api_config/SNS-2010-03-31.yml +2 -2
  4. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +5 -5
  5. data/lib/aws/core.rb +18 -3
  6. data/lib/aws/core/client_logging.rb +5 -6
  7. data/lib/aws/core/collection.rb +241 -0
  8. data/lib/aws/core/collection/batchable.rb +133 -0
  9. data/lib/aws/core/collection/limitable.rb +92 -0
  10. data/lib/aws/core/collection/simple.rb +89 -0
  11. data/lib/aws/core/configuration.rb +23 -0
  12. data/lib/aws/core/option_grammar.rb +2 -0
  13. data/lib/aws/core/page_result.rb +73 -0
  14. data/lib/aws/ec2/security_group.rb +154 -89
  15. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +1 -2
  16. data/lib/aws/ec2/security_group/{ip_permission_collection.rb → ingress_ip_permission_collection.rb} +4 -1
  17. data/lib/aws/ec2/security_group/ip_permission.rb +23 -45
  18. data/lib/aws/elb.rb +65 -0
  19. data/lib/aws/elb/availability_zone_collection.rb +138 -0
  20. data/lib/aws/elb/backend_server_policy_collection.rb +150 -0
  21. data/lib/aws/elb/client.rb +35 -0
  22. data/lib/aws/elb/client/xml.rb +33 -0
  23. data/lib/aws/elb/config.rb +18 -0
  24. data/lib/aws/elb/errors.rb +30 -0
  25. data/lib/aws/elb/instance_collection.rb +174 -0
  26. data/lib/aws/elb/listener.rb +189 -0
  27. data/lib/aws/elb/listener_collection.rb +119 -0
  28. data/lib/aws/elb/listener_opts.rb +45 -0
  29. data/lib/aws/elb/listener_spec.rb +14 -0
  30. data/lib/aws/elb/load_balancer.rb +255 -0
  31. data/lib/aws/elb/load_balancer_collection.rb +113 -0
  32. data/lib/aws/elb/load_balancer_policy.rb +93 -0
  33. data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
  34. data/lib/aws/elb/request.rb +23 -0
  35. data/lib/aws/iam/collection.rb +24 -26
  36. data/lib/aws/iam/group_user_collection.rb +21 -28
  37. data/lib/aws/iam/server_certificate_collection.rb +1 -37
  38. data/lib/aws/record.rb +1 -1
  39. data/lib/aws/record/base.rb +14 -1
  40. data/lib/aws/record/finder_methods.rb +4 -1
  41. data/lib/aws/record/validations.rb +73 -32
  42. data/lib/aws/{core/api_config_transform.rb → record/validators/method.rb} +9 -12
  43. data/lib/aws/s3/bucket_collection.rb +6 -4
  44. data/lib/aws/s3/client.rb +37 -6
  45. data/lib/aws/s3/config.rb +3 -1
  46. data/lib/aws/s3/prefixed_collection.rb +1 -2
  47. data/lib/aws/s3/presigned_post.rb +37 -4
  48. data/lib/aws/s3/s3_object.rb +93 -1
  49. data/lib/aws/simple_db/domain.rb +8 -0
  50. data/lib/aws/simple_db/item.rb +15 -0
  51. data/lib/aws/simple_db/item_collection.rb +255 -201
  52. data/lib/aws/simple_db/item_data.rb +1 -1
  53. data/lib/aws/simple_email_service/client.rb +0 -1
  54. data/lib/aws/sns/client.rb +0 -1
  55. metadata +107 -55
  56. data/lib/aws/core/collections.rb +0 -229
  57. data/lib/aws/simple_email_service/client/options.rb +0 -21
  58. data/lib/aws/sns/client/options.rb +0 -21
@@ -117,45 +117,9 @@ module AWS
117
117
  ServerCertificate.new(name, :config => config)
118
118
  end
119
119
 
120
- # Yields once for each server certificate
121
- #
122
- # You can limit the number of certificates yielded using
123
- # +:limit+ and +:path_prefix+.
124
- #
125
- # @param [Hash] options
126
- #
127
- # @option options [String] :path_prefix ('/') A path prefix that
128
- # filters according to the path of the certificate.
129
- #
130
- # @option options [Integer] :limit The maximum number of
131
- # certificates to yield.
132
- #
133
- # @option options [Integer] :batch_size The maximum number of
134
- # certificates to retrieve in each service request.
135
- #
136
- # @yieldparam [ServerCertificate] certificate
137
- # @return [nil]
138
- def each options = {}, &block
139
- super(options, &block)
140
- end
141
-
142
- # Returns an enumerable object for this collection. This can be
143
- # useful if you want to call an enumerable method that does
144
- # not accept options (e.g. +collect+, +first+, etc).
145
- #
146
- # certificates.enumerator(:path_prefix => '/production').
147
- # collect(&:name)
148
- #
149
- # @param (see #each)
150
- # @option (see #each)
151
- # @return [Enumerator]
152
- def enumerator options = {}
153
- super(options)
154
- end
155
-
156
120
  # @private
157
121
  protected
158
- def each_item(response, &block)
122
+ def each_item response, &block
159
123
  response.server_certificate_metadata_list.each do |sc|
160
124
  certificate = ServerCertificate.new_from(:list_server_certificates,
161
125
  sc,
@@ -21,7 +21,7 @@ module AWS
21
21
  end
22
22
 
23
23
  # @private
24
- class RecordNotFound < Exception; end
24
+ class RecordNotFound < StandardError; end
25
25
 
26
26
  # Sets a prefix to be applied to all SimpleDB domains associated with
27
27
  # AWS::Record::Base classes.
@@ -326,6 +326,19 @@ module AWS
326
326
  hash
327
327
  end
328
328
  end
329
+
330
+ # Acts like {#update} but does not call {#save}.
331
+ #
332
+ # record.attributes = { :name => 'abc', :age => 20 }
333
+ #
334
+ # @param [Hash] attributes A hash of attributes to set on this record
335
+ # without calling save.
336
+ #
337
+ # @return [Hash] Returns the attribute hash that was passed in.
338
+ #
339
+ def attributes= attributes
340
+ bulk_assign(attributes)
341
+ end
329
342
 
330
343
  # Persistence indicates if the record has been saved previously or not.
331
344
  #
@@ -348,7 +361,7 @@ module AWS
348
361
 
349
362
  # @return [Boolean] Returns true if this record has no validation errors.
350
363
  def valid?
351
- validate
364
+ run_validations
352
365
  errors.empty?
353
366
  end
354
367
 
@@ -150,13 +150,16 @@ module AWS
150
150
  # Car.where('color = ? OR style = ?', 'red', 'compact')
151
151
  #
152
152
  # # produces a condition using in, like: WHERE color IN ('red', 'blue')
153
- # Car.where('color = ?', ['red','blue'])
153
+ # Car.where('color IN ?', ['red','blue'])
154
154
  #
155
155
  # Hash arguments
156
156
  #
157
157
  # # WHERE age = '40' AND gender = 'male'
158
158
  # People.where(:age => 40, :gender => 'male').each {|person| ... }
159
159
  #
160
+ # # WHERE name IN ('John', 'Jane')
161
+ # People.where(:name => ['John', 'Jane']).each{|person| ... }
162
+ #
160
163
  # Chaining where with other scope modifiers
161
164
  #
162
165
  # # 10 most expensive red cars
@@ -21,6 +21,7 @@ require 'aws/record/validators/inclusion'
21
21
  require 'aws/record/validators/length'
22
22
  require 'aws/record/validators/numericality'
23
23
  require 'aws/record/validators/presence'
24
+ require 'aws/record/validators/method'
24
25
 
25
26
  module AWS
26
27
  module Record
@@ -100,17 +101,57 @@ module AWS
100
101
 
101
102
  def self.extended base
102
103
 
103
- base.send(:define_method, :validate) do
104
+ base.send(:define_method, :run_validations) do
104
105
  errors.clear!
105
106
  self.class.send(:validators).each do |validator|
106
107
  validator.validate(self)
107
108
  end
108
109
  end
109
110
 
110
- base.send(:private, :validate)
111
+ base.send(:private, :run_validations)
111
112
 
112
113
  end
113
114
 
115
+ # Registers a validation method.
116
+ #
117
+ # validate :ensure_age_is_greater_than_shoe_size
118
+ #
119
+ # def ensure_age_is_greater_than_shoe_size
120
+ # unless age > shoe_size
121
+ # errors.add(:age, 'should be greater than your shoe size')
122
+ # end
123
+ # end
124
+ #
125
+ # You can also pass a list of method names that should be called during
126
+ # validation.
127
+ #
128
+ # validate :some_complex_validation, :some_other_validation
129
+ #
130
+ # As with most other validation methods you can also pass a hash of
131
+ # options that affect when the named validation methods get called.
132
+ #
133
+ # validate :my_custom_validation, :unless => :new_record?
134
+ #
135
+ # @overload validate(*method_names, options = {})
136
+ # @param [Array<Symbol>] method_names A list of methods to call
137
+ # during validation.
138
+ # @param [Hash] options
139
+ # @option options [Symbol] :on (:save) When this validation is run.
140
+ # Valid values include:
141
+ # * +:save+
142
+ # * +:create+
143
+ # * +:update+
144
+ # @option options [Symbol,String,Proc] :if Specifies a method or proc
145
+ # to call. The validation will only be run if the return value is
146
+ # of the method/proc is true (e.g. +:if => :name_changed?+ or
147
+ # +:if => lambda{|book| book.in_stock? }+).
148
+ # @option options [Symbol,String,Proc] :unless Specifies a method or
149
+ # proc to call. The validation will *not* be run if the return value
150
+ # is of the method/proc is false.
151
+ def validate *args
152
+ validators << MethodValidator.new(self, *args)
153
+ end
154
+
114
155
  # This validation method is primariliy intended for ensuring a form
115
156
  # checkbox (like an EULA agreement or terms of service acknowledgement)
116
157
  # is checked.
@@ -178,9 +219,9 @@ module AWS
178
219
  # attribute value is +nil+.
179
220
  # @option options [Symbol] :on (:save) When this validation is run.
180
221
  # Valid values include:
181
- # * +:save:+
182
- # * +:create:+
183
- # * +:update:+
222
+ # * +:save+
223
+ # * +:create+
224
+ # * +:update+
184
225
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
185
226
  # to call. The validation will only be run if the return value is
186
227
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -233,9 +274,9 @@ module AWS
233
274
  # +:message+ is "doesn't match confirmation".
234
275
  # @option options [Symbol] :on (:save) When this validation is run.
235
276
  # Valid values include:
236
- # * +:save:+
237
- # * +:create:+
238
- # * +:update:+
277
+ # * +:save+
278
+ # * +:create+
279
+ # * +:update+
239
280
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
240
281
  # to call. The validation will only be run if the return value is
241
282
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -319,9 +360,9 @@ module AWS
319
360
  # number of values (should have exactly %{exactly}"</code>
320
361
  # @option options [Symbol] :on (:save) When this validation is run.
321
362
  # Valid values include:
322
- # * +:save:+
323
- # * +:create:+
324
- # * +:update:+
363
+ # * +:save+
364
+ # * +:create+
365
+ # * +:update+
325
366
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
326
367
  # to call. The validation will only be run if the return value is
327
368
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -354,9 +395,9 @@ module AWS
354
395
  # attribute value is +nil+.
355
396
  # @option options [Symbol] :on (:save) When this validation is run.
356
397
  # Valid values include:
357
- # * +:save:+
358
- # * +:create:+
359
- # * +:update:+
398
+ # * +:save+
399
+ # * +:create+
400
+ # * +:update+
360
401
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
361
402
  # to call. The validation will only be run if the return value is
362
403
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -400,9 +441,9 @@ module AWS
400
441
  # attribute value is +nil+.
401
442
  # @option options [Symbol] :on (:save) When this validation is run.
402
443
  # Valid values include:
403
- # * +:save:+
404
- # * +:create:+
405
- # * +:update:+
444
+ # * +:save+
445
+ # * +:create+
446
+ # * +:update+
406
447
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
407
448
  # to call. The validation will only be run if the return value is
408
449
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -449,9 +490,9 @@ module AWS
449
490
  # attribute value is +nil+.
450
491
  # @option options [Symbol] :on (:save) When this validation is run.
451
492
  # Valid values include:
452
- # * +:save:+
453
- # * +:create:+
454
- # * +:update:+
493
+ # * +:save+
494
+ # * +:create+
495
+ # * +:update+
455
496
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
456
497
  # to call. The validation will only be run if the return value is
457
498
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -486,9 +527,9 @@ module AWS
486
527
  # attribute value is +nil+.
487
528
  # @option options [Symbol] :on (:save) When this validation is run.
488
529
  # Valid values include:
489
- # * +:save:+
490
- # * +:create:+
491
- # * +:update:+
530
+ # * +:save+
531
+ # * +:create+
532
+ # * +:update+
492
533
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
493
534
  # to call. The validation will only be run if the return value is
494
535
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -547,9 +588,9 @@ module AWS
547
588
  # attribute value is +nil+.
548
589
  # @option options [Symbol] :on (:save) When this validation is run.
549
590
  # Valid values include:
550
- # * +:save:+
551
- # * +:create:+
552
- # * +:update:+
591
+ # * +:save+
592
+ # * +:create+
593
+ # * +:update+
553
594
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
554
595
  # to call. The validation will only be run if the return value is
555
596
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -597,9 +638,9 @@ module AWS
597
638
  # attribute value is +nil+.
598
639
  # @option options [Symbol] :on (:save) When this validation is run.
599
640
  # Valid values include:
600
- # * +:save:+
601
- # * +:create:+
602
- # * +:update:+
641
+ # * +:save+
642
+ # * +:create+
643
+ # * +:update+
603
644
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
604
645
  # to call. The validation will only be run if the return value is
605
646
  # of the method/proc is true (e.g. +:if => :name_changed?+ or
@@ -626,9 +667,9 @@ module AWS
626
667
  # +:message+ is "may not be blank".
627
668
  # @option options [Symbol] :on (:save) When this validation is run.
628
669
  # Valid values include:
629
- # * +:save:+
630
- # * +:create:+
631
- # * +:update:+
670
+ # * +:save+
671
+ # * +:create+
672
+ # * +:update+
632
673
  # @option options [Boolean] :allow_nil (false) Skip validation if the
633
674
  # attribute value is +nil+.
634
675
  # @option options [Symbol,String,Proc] :if Specifies a method or proc
@@ -11,24 +11,21 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
- require 'yaml'
14
+ require 'aws/record/validator'
15
15
 
16
16
  module AWS
17
- module Core
18
-
17
+ module Record
18
+
19
+ # Uses the base validator class to call user-defined validation methods.
19
20
  # @private
20
- class ApiConfigTransform
21
-
22
- def self.rename_input_list_to_membered_list api_config
23
- api_config[:operations].each_pair do |name,customizations|
24
-
25
- input = api_config[:operations][name][:input]
26
- fixed_input = input.to_yaml.gsub(/:list:/, ':membered_list:')
21
+ class MethodValidator < Validator
27
22
 
28
- api_config[:operations][name][:input] = YAML.load(fixed_input)
23
+ ACCEPTED_OPTIONS = [:on, :if, :unless]
29
24
 
25
+ def validate_attributes record
26
+ attribute_names.each do |method_name|
27
+ record.send(method_name)
30
28
  end
31
- api_config
32
29
  end
33
30
 
34
31
  end
@@ -85,10 +85,12 @@ module AWS
85
85
  config.s3_endpoint == 's3.amazonaws.com' or
86
86
  options[:location_constraint]
87
87
  then
88
- options[:location_constraint] = case config.s3_endpoint
89
- when 's3-eu-west-1.amazonaws.com' then 'EU'
90
- else config.s3_endpoint.match(/^s3-(.*)\.amazonaws\.com$/)[1]
91
- end
88
+ constraint =
89
+ case config.s3_endpoint
90
+ when 's3-eu-west-1.amazonaws.com' then 'EU'
91
+ when /^s3-(.*)\.amazonaws\.com$/ then $1
92
+ end
93
+ options[:location_constraint] = constraint if constraint
92
94
  end
93
95
 
94
96
  client.create_bucket(options.merge(:bucket_name => bucket_name))
@@ -459,9 +459,13 @@ module AWS
459
459
  :content_encoding => 'Content-Encoding',
460
460
  :content_type => 'Content-Type',
461
461
  :storage_class => 'x-amz-storage-class',
462
+ :server_side_encryption => 'x-amz-server-side-encryption',
462
463
  :expires => 'Expires'
463
464
  }) do
464
465
  configure_request do |request, options, block|
466
+ options[:server_side_encryption] =
467
+ options[:server_side_encryption].to_s.upcase if
468
+ options[:server_side_encryption].kind_of?(Symbol)
465
469
  super(request, options)
466
470
  set_request_data(request, options, block)
467
471
  request.metadata = options[:metadata]
@@ -479,6 +483,7 @@ module AWS
479
483
  Core::MetaUtils.extend_method(response, :last_modified) do
480
484
  Time.parse(response.http_response.header('Last-Modified'))
481
485
  end
486
+ add_sse_to_response(response)
482
487
  end
483
488
 
484
489
  simulate_response do |response|
@@ -583,6 +588,7 @@ module AWS
583
588
  Core::MetaUtils.extend_method(resp, :version_id) do
584
589
  http_response.header('x-amz-version-id')
585
590
  end
591
+ add_sse_to_response(resp)
586
592
  end
587
593
  end
588
594
 
@@ -625,6 +631,8 @@ module AWS
625
631
  Core::MetaUtils.extend_method(resp, :content_length) do
626
632
  http_response.header('content-length').to_i
627
633
  end
634
+
635
+ add_sse_to_response(resp)
628
636
  end
629
637
  end
630
638
 
@@ -664,14 +672,22 @@ module AWS
664
672
  :content_encoding => 'Content-Encoding',
665
673
  :content_type => 'Content-Type',
666
674
  :storage_class => 'x-amz-storage-class',
675
+ :server_side_encryption => 'x-amz-server-side-encryption',
667
676
  :expires => 'Expires'
668
677
  }) do
669
678
  configure_request do |req, options|
679
+ options[:server_side_encryption] =
680
+ options[:server_side_encryption].to_s.upcase if
681
+ options[:server_side_encryption].kind_of?(Symbol)
670
682
  super(req, options)
671
683
  req.metadata = options[:metadata]
672
684
  req.canned_acl = options[:acl]
673
685
  req.storage_class = options[:storage_class]
674
686
  end
687
+
688
+ process_response do |response|
689
+ add_sse_to_response(response)
690
+ end
675
691
  end
676
692
 
677
693
  bucket_method(:list_multipart_uploads,
@@ -711,6 +727,7 @@ module AWS
711
727
  Core::MetaUtils.extend_method(response, :last_modified) do
712
728
  Time.parse(response.http_response.header('Last-Modified'))
713
729
  end
730
+ add_sse_to_response(response)
714
731
  end
715
732
 
716
733
  simulate_response do |response|
@@ -739,6 +756,7 @@ module AWS
739
756
  Core::MetaUtils.extend_method(response, :version_id) do
740
757
  response.http_response.header('x-amz-version-id')
741
758
  end
759
+ add_sse_to_response(response)
742
760
  end
743
761
 
744
762
  simulate_response do |response|
@@ -779,12 +797,12 @@ module AWS
779
797
  # @option options [Symbol] :acl
780
798
  #
781
799
  object_method(:copy_object, :put,
782
- :header_options => {
783
- :copy_source => 'x-amz-copy-source',
784
- :metadata_directive => 'x-amz-metadata-directive',
785
- :storage_class => 'x-amz-storage-class',
786
- }
787
- ) do
800
+ :header_options => {
801
+ :copy_source => 'x-amz-copy-source',
802
+ :metadata_directive => 'x-amz-metadata-directive',
803
+ :storage_class => 'x-amz-storage-class',
804
+ :server_side_encryption => 'x-amz-server-side-encryption',
805
+ }) do
788
806
 
789
807
  configure_request do |req, options|
790
808
  # TODO : validate metadata directive COPY / REPLACE
@@ -794,6 +812,9 @@ module AWS
794
812
  "may not be blank" if options[:copy_source].to_s.empty?
795
813
  end
796
814
  options = options.merge(:copy_source => escape_path(options[:copy_source]))
815
+ options[:server_side_encryption] =
816
+ options[:server_side_encryption].to_s.upcase if
817
+ options[:server_side_encryption].kind_of?(Symbol)
797
818
  super(req, options)
798
819
  req.canned_acl = options[:acl]
799
820
  req.metadata = options[:metadata]
@@ -813,6 +834,7 @@ module AWS
813
834
  Core::MetaUtils.extend_method(response, :last_modified) do
814
835
  Time.parse(response.http_response.header('Last-Modified'))
815
836
  end
837
+ add_sse_to_response(response)
816
838
  end
817
839
 
818
840
  end
@@ -856,6 +878,15 @@ module AWS
856
878
  S3::Request.new
857
879
  end
858
880
 
881
+ protected
882
+ def add_sse_to_response(response)
883
+ sse = nil
884
+ if value = response.http_response.header('x-amz-server-side-encryption')
885
+ sse = value.downcase.to_sym
886
+ end
887
+ Core::MetaUtils.extend_method(response, :server_side_encryption) { sse }
888
+ end
889
+
859
890
  module Validators
860
891
 
861
892
  # Returns true if the given bucket name is valid.