aws-sdk 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/lib/aws/api_config/{IAM-2010-07-15.yml → IAM-2010-05-08.yml} +56 -4
  2. data/lib/aws/api_config/SNS-2010-03-31.yml +90 -81
  3. data/lib/aws/core.rb +26 -11
  4. data/lib/aws/core/client.rb +12 -4
  5. data/lib/aws/core/collection.rb +5 -12
  6. data/lib/aws/core/collection/limitable.rb +10 -3
  7. data/lib/aws/core/collection/simple.rb +1 -0
  8. data/lib/aws/core/configuration.rb +2 -0
  9. data/lib/aws/core/configured_json_client_methods.rb +5 -2
  10. data/lib/aws/core/http/httparty_handler.rb +1 -1
  11. data/lib/aws/core/http/net_http_handler.rb +2 -1
  12. data/lib/aws/core/http/request.rb +27 -0
  13. data/lib/aws/core/json_client.rb +41 -0
  14. data/lib/aws/core/lazy_error_classes.rb +2 -0
  15. data/lib/aws/core/option_grammar.rb +1 -1
  16. data/lib/aws/core/resource.rb +12 -14
  17. data/lib/aws/core/session_signer.rb +0 -5
  18. data/lib/aws/core/xml_grammar.rb +12 -2
  19. data/lib/aws/dynamo_db.rb +4 -1
  20. data/lib/aws/dynamo_db/client.rb +4 -17
  21. data/lib/aws/dynamo_db/item_collection.rb +15 -0
  22. data/lib/aws/ec2/security_group.rb +2 -1
  23. data/lib/aws/ec2/security_group/ip_permission.rb +2 -3
  24. data/lib/aws/elb/listener.rb +2 -2
  25. data/lib/aws/iam.rb +17 -0
  26. data/lib/aws/iam/client.rb +9 -6
  27. data/lib/aws/iam/mfa_device.rb +4 -2
  28. data/lib/aws/iam/mfa_device_collection.rb +14 -3
  29. data/lib/aws/iam/user.rb +10 -0
  30. data/lib/aws/iam/virtual_mfa_device.rb +139 -0
  31. data/lib/aws/iam/virtual_mfa_device_collection.rb +73 -0
  32. data/lib/aws/record/abstract_base.rb +1 -0
  33. data/lib/aws/record/hash_model/attributes.rb +8 -8
  34. data/lib/aws/record/hash_model/finder_methods.rb +10 -15
  35. data/lib/aws/record/model.rb +1 -3
  36. data/lib/aws/record/model/finder_methods.rb +3 -3
  37. data/lib/aws/s3.rb +1 -0
  38. data/lib/aws/s3/bucket.rb +83 -16
  39. data/lib/aws/s3/bucket_lifecycle_configuration.rb +360 -0
  40. data/lib/aws/s3/client.rb +50 -0
  41. data/lib/aws/s3/client/xml.rb +10 -0
  42. data/lib/aws/s3/object_version.rb +5 -0
  43. data/lib/aws/s3/object_version_collection.rb +15 -1
  44. data/lib/aws/s3/request.rb +1 -1
  45. data/lib/aws/s3/s3_object.rb +56 -1
  46. data/lib/aws/sns.rb +1 -0
  47. data/lib/aws/sns/has_delivery_policy.rb +68 -0
  48. data/lib/aws/sns/subscription.rb +62 -14
  49. data/lib/aws/sns/subscription_collection.rb +1 -1
  50. data/lib/aws/sns/topic.rb +22 -4
  51. data/lib/aws/sts.rb +3 -2
  52. data/lib/net/http/connection_pool.rb +1 -1
  53. metadata +27 -25
  54. data/lib/aws/core/collection/batchable.rb +0 -133
@@ -44,23 +44,16 @@ module AWS
44
44
  # collection.each {|item| ... }
45
45
  #
46
46
  # @note If you want fewer than all items, it is generally better
47
- # to call #{page} than {#each} with a +:limit+.
47
+ # to call {#page} than {#each} with a +:limit+.
48
48
  #
49
49
  # @param [Hash] options
50
50
  #
51
51
  # @option options [Integer] :limit (nil) The maximum number of
52
52
  # items to enumerate from this collection.
53
53
  #
54
- # @option options [next_token] :next_token (nil) Next tokens
55
- # act as offsets into the collection. Next tokens vary in
56
- # format from one service to the next, (e.g. may be a number,
57
- # an opaque string, a hash of values, etc).
58
- #
59
- # {#each} and {#each_batch} return a +:next_token+ when called
60
- # with +:limit+ and there were more items matching the request.
61
- #
62
- # *NOTE* It is generally better to call {#page} if you only
63
- # want a few items with the ability to request more later.
54
+ # @option options [next_token] :next_token (nil)
55
+ # Acts as an offset. +:next_token+ may be returned by {#each} and
56
+ # {#each_batch} when a +:limit+ is provided.
64
57
  #
65
58
  # @return [nil_or_next_token] Returns nil if all items were enumerated.
66
59
  # If some items were excluded because of a +:limit+ option then
@@ -205,7 +198,7 @@ module AWS
205
198
  # the next page of results. You can not choose an offset
206
199
  # or know how many pages of results there will be.
207
200
  #
208
- # @params [Hash] options A hash of options that modifies the
201
+ # @param [Hash] options A hash of options that modifies the
209
202
  # items returned in the page of results.
210
203
  #
211
204
  # @option options [Integer] :per_page (10) The number of results
@@ -30,11 +30,18 @@ module AWS
30
30
  def each_batch options = {}, &block
31
31
 
32
32
  each_opts = options.dup
33
- limit = each_opts.delete(:limit) || _limit
34
- next_token = each_opts.delete(:next_token)
33
+
34
+ ## limit and batch size should accept string values like '10'
35
+
36
+ limit = each_opts.delete(:limit) || _limit
37
+ limit = limit.to_i if limit
38
+
35
39
  batch_size = each_opts.delete(:batch_size)
40
+ batch_size = batch_size.to_i if batch_size
41
+
42
+ next_token = each_opts.delete(:next_token)
36
43
 
37
- total = 0 # count of items yeileded across all batches
44
+ total = 0 # count of items yeilded across all batches
38
45
 
39
46
  begin
40
47
 
@@ -40,6 +40,7 @@ module AWS
40
40
 
41
41
  each_opts = options.dup
42
42
  limit = each_opts.delete(:limit)
43
+ limit = limit.to_i if limit
43
44
  next_token = each_opts.delete(:next_token)
44
45
  offset = next_token ? next_token.to_i - 1 : 0
45
46
  total = 0
@@ -379,6 +379,8 @@ module AWS
379
379
 
380
380
  add_option :ssl_ca_file,
381
381
  File.expand_path(File.dirname(__FILE__) + "/../../../ca-bundle.crt")
382
+
383
+ add_option :ssl_ca_path
382
384
 
383
385
  add_option :stub_requests, false, :boolean => true
384
386
 
@@ -39,13 +39,16 @@ module AWS
39
39
  option_grammar = self::Options.operation_grammar(name)
40
40
  target_prefix = self::TARGET_PREFIX
41
41
  add_client_request_method(Inflection.ruby_name(name).to_sym) do
42
+
42
43
  configure_request do |request, options|
43
44
  request.headers["x-amz-target"] = target_prefix + name
44
45
  request.body = option_grammar.to_json(options)
45
46
  end
46
47
 
47
48
  process_response do |response|
48
- data = JSON.load(response.http_response.body)
49
+ response_body = response.http_response.body
50
+ response_body = "{}" if response_body == ""
51
+ data = JSON.load(response_body)
49
52
  MetaUtils.extend_method(response, :data) { data }
50
53
  end
51
54
 
@@ -53,6 +56,7 @@ module AWS
53
56
  data = {}
54
57
  MetaUtils.extend_method(response, :data) { data }
55
58
  end
59
+
56
60
  end
57
61
  end
58
62
 
@@ -68,4 +72,3 @@ module AWS
68
72
 
69
73
  end
70
74
  end
71
-
@@ -44,7 +44,7 @@ module AWS
44
44
  # that +:body+, +:headers+, +:parser+, and +:ssl_ca_file+ are
45
45
  # ignored. If you need to set the CA file, you should use the
46
46
  # +:ssl_ca_file+ option to {AWS.config} or
47
- # {AWS::Configuration} instead.
47
+ # {Configuration} instead.
48
48
  def initialize options = {}
49
49
  @default_request_options = options
50
50
  end
@@ -34,7 +34,8 @@ module AWS
34
34
  options[:ssl] = request.use_ssl?
35
35
  options[:proxy_uri] = request.proxy_uri
36
36
  options[:ssl_verify_peer] = request.ssl_verify_peer?
37
- options[:ssl_ca_file] = request.ssl_ca_file
37
+ options[:ssl_ca_file] = request.ssl_ca_file if request.ssl_ca_file
38
+ options[:ssl_ca_path] = request.ssl_ca_path if request.ssl_ca_path
38
39
 
39
40
  connection = self.class.pool.connection_for(request.host, options)
40
41
 
@@ -26,7 +26,13 @@ module AWS
26
26
  @headers = CaseInsensitiveHash.new
27
27
  @params = []
28
28
  @use_ssl = true
29
+ @read_timeout = 60
29
30
  end
31
+
32
+ # @return [Integer] The number of seconds the service has to respond
33
+ # before a timeout error is raised on the request. Defaults to
34
+ # 60 seconds.
35
+ attr_accessor :read_timeout
30
36
 
31
37
  # @return [String] hostname of the request
32
38
  attr_accessor :host
@@ -88,6 +94,20 @@ module AWS
88
94
  @ssl_ca_file
89
95
  end
90
96
 
97
+ # @param [String] ca_path Path to a bundle of CA certs in PEM
98
+ # format; the HTTP handler should use this to verify all HTTPS
99
+ # requests if {#ssl_verify_peer?} is true.
100
+ def ssl_ca_path=(ca_path)
101
+ @ssl_ca_path = ca_path
102
+ end
103
+
104
+ # @return [String] Path to a bundle of CA certs in PEM format;
105
+ # the HTTP handler should use this to verify all HTTPS
106
+ # requests if {#ssl_verify_peer?} is true.
107
+ def ssl_ca_path
108
+ @ssl_ca_path
109
+ end
110
+
91
111
  # Adds a request param.
92
112
  #
93
113
  # @overload add_param(param_name, param_value = nil)
@@ -106,12 +126,19 @@ module AWS
106
126
  @params << Param.new(name_or_param, value)
107
127
  end
108
128
  end
129
+ alias_method :[]=, :add_param
109
130
 
110
131
  # @private
111
132
  def get_param param_name
112
133
  @params.detect{|p| p.name == param_name } ||
113
134
  raise("undefined param #{param_name}")
114
135
  end
136
+
137
+ # @private
138
+ def param_value_for param_name
139
+ param = @params.detect{|p| p.name == param_name }
140
+ param ? param.value : nil
141
+ end
115
142
 
116
143
  # @return [String] the request uri
117
144
  def uri
@@ -0,0 +1,41 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ module Core
16
+
17
+ class JsonClient < Client
18
+
19
+ include Core::ConfiguredJsonClientMethods
20
+
21
+ protected
22
+ def new_request
23
+ req = super
24
+ req.headers["content-type"] = "application/x-amz-json-1.0"
25
+ req
26
+ end
27
+
28
+ protected
29
+ def extract_error_code response
30
+ if response.http_response.status >= 300 and
31
+ body = response.http_response.body and
32
+ json = (JSON.load(body) rescue nil) and
33
+ type = json["__type"] and
34
+ type =~ /\#(.*)$/
35
+ $1
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -11,6 +11,8 @@
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 'thread'
15
+
14
16
  module AWS
15
17
  module Core
16
18
 
@@ -338,7 +338,7 @@ module AWS
338
338
 
339
339
  module Map
340
340
 
341
- def self.apply(option, members)
341
+ def self.apply option, members = {}
342
342
 
343
343
  option.extend self
344
344
 
@@ -60,12 +60,11 @@ module AWS
60
60
 
61
61
  # @return [Boolean] Returns true if the objects references the same
62
62
  # AWS resource.
63
- def == other
63
+ def eql? other
64
64
  other.kind_of?(self.class) and
65
65
  resource_identifiers == other.resource_identifiers
66
66
  end
67
-
68
- alias_method :eql?, :==
67
+ alias_method :==, :eql?
69
68
 
70
69
  # @private
71
70
  protected
@@ -152,7 +151,6 @@ module AWS
152
151
  end
153
152
  end
154
153
 
155
-
156
154
  class << self
157
155
 
158
156
  # @private
@@ -299,9 +297,9 @@ module AWS
299
297
  return nil if value.nil? and @translates_nil != true
300
298
 
301
299
  case
302
- when @options[:to_sym] then value.tr('-','_').downcase.to_sym
300
+ when @options[:to_sym] then value.tr('-','_').downcase.to_sym
303
301
  when @options[:timestamp] then Time.at(value.to_i)
304
- when @output_translator then @output_translator.call(value)
302
+ when @output_translator then @output_translator.call(value)
305
303
  else value
306
304
  end
307
305
 
@@ -326,7 +324,7 @@ module AWS
326
324
  end
327
325
 
328
326
  def finder_method
329
- "find_in_response_#{@id}"
327
+ "_find_in_#{request_types.join('_or_')}_response_#{@id}"
330
328
  end
331
329
 
332
330
  # Indicates that all of the the named attributes can be retrieved
@@ -366,13 +364,13 @@ module AWS
366
364
  method = options[:get_as] || attr.get_as
367
365
 
368
366
  v = case
369
- when resp_obj.respond_to?(method)
370
- resp_obj.send(method)
371
- when resp_obj.respond_to?(:key?) && resp_obj.key?(method)
372
- resp_obj[method]
373
- else
374
- nil
375
- end
367
+ when resp_obj.respond_to?(:key?) && resp_obj.key?(method.to_s)
368
+ resp_obj[method.to_s]
369
+ when resp_obj.respond_to?(method)
370
+ resp_obj.send(method)
371
+ else
372
+ nil
373
+ end
376
374
  v = v.value if v and options[:value_wrapped]
377
375
  v = attr.translate_output_value(v)
378
376
 
@@ -76,11 +76,6 @@ module AWS
76
76
  session = get_session
77
77
  end
78
78
 
79
- if session.expires_at < (Time.now + 15 * 60)
80
- refresh_session
81
- session = get_session
82
- end
83
-
84
79
  session
85
80
 
86
81
  end
@@ -14,6 +14,7 @@
14
14
  require 'rexml/document'
15
15
  require 'rexml/streamlistener'
16
16
  require 'base64'
17
+ require 'time'
17
18
 
18
19
  begin
19
20
  require 'nokogiri'
@@ -254,14 +255,22 @@ module AWS
254
255
  end
255
256
 
256
257
  alias_method :float, :float_value
257
-
258
+
258
259
  def symbol_value
259
260
  format_value do |value|
260
261
  value = super(value)
261
262
  ['', nil].include?(value) ? nil : Inflection.ruby_name(value).to_sym
262
263
  end
263
264
  end
264
-
265
+
266
+ def blob_value
267
+ format_value do |value|
268
+ value = super(value)
269
+ Base64.decode64(value) if value
270
+ end
271
+ end
272
+ alias_method :blob, :blob_value
273
+
265
274
  def format_value &block
266
275
  @current[:value_formatter] ||= ValueFormatter.new
267
276
  @current[:value_formatter].extend_format_value(&block)
@@ -405,6 +414,7 @@ module AWS
405
414
  allow_methods = %w(
406
415
  rename attribute_name boolean integer long float list force
407
416
  ignore collect_values symbol_value timestamp map_entry map
417
+ blob
408
418
  )
409
419
  unless allow_methods.include?(method.to_s)
410
420
  raise "#{method} cannot be used in configuration"
@@ -11,6 +11,9 @@
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 'aws/core'
15
+ require 'aws/dynamo_db/config'
16
+
14
17
  module AWS
15
18
 
16
19
  # Provides a high-level interface for using DynamoDB.
@@ -43,7 +46,7 @@ module AWS
43
46
  # "MyTable",
44
47
  # :hash_key => { :id => :string }
45
48
  # )
46
- # sleep 1 while t.status == :creating
49
+ # sleep 1 while table.status == :creating
47
50
  #
48
51
  # See {Table} and {TableCollection} for more information on creating
49
52
  # and managing tables.
@@ -15,7 +15,7 @@ module AWS
15
15
  class DynamoDB
16
16
 
17
17
  # @private
18
- class Client < Core::Client
18
+ class Client < Core::JsonClient
19
19
 
20
20
  API_VERSION = '2011-06-01'
21
21
 
@@ -27,8 +27,6 @@ module AWS
27
27
 
28
28
  CACHEABLE_REQUESTS = Set[:list_tables, :describe_table]
29
29
 
30
- include Core::ConfiguredJsonClientMethods
31
-
32
30
  configure_client
33
31
 
34
32
  def initialize *args
@@ -45,23 +43,12 @@ module AWS
45
43
 
46
44
  end
47
45
 
48
- protected
49
- def new_request
50
- req = super
51
- req.headers["content-type"] = "application/x-amz-json-1.0"
52
- req
53
- end
54
-
55
46
  protected
56
47
  def extract_error_code response
57
48
  if response.http_response.status == 413
58
49
  'RequestEntityTooLarge'
59
- elsif response.http_response.status >= 300 and
60
- body = response.http_response.body and
61
- json = (JSON.load(body) rescue nil) and
62
- type = json["__type"] and
63
- type =~ /\#(.*)$/
64
- $1
50
+ else
51
+ super(response)
65
52
  end
66
53
  end
67
54
 
@@ -111,7 +98,7 @@ module AWS
111
98
  # our signer is capible of getting new short-term credentials
112
99
  def possible_expired_credentials? response
113
100
  signer.respond_to?(:refresh_session) and
114
- response.error.is_a?(Errors::AccessDeniedException)
101
+ response.error.is_a?(Errors::ExpiredTokenException)
115
102
  end
116
103
 
117
104
  end
@@ -645,6 +645,20 @@ module AWS
645
645
  # * +:range_lte+
646
646
  # * +:range_begins_with+
647
647
  #
648
+ # @option [Boolean] :scan_index_forward (true) Specifies which
649
+ # order records will be returned. Defaults to returning them
650
+ # in ascending range key order. Pass false to reverse this.
651
+ #
652
+ # @option :select (nil) By default {#query} yields {Item}
653
+ # objects without any attribute data. If you want to select
654
+ # specific attributes, pass a list of them to :select.
655
+ #
656
+ # :select => [:id, :category, :size]
657
+ #
658
+ # If you want to select ALL attributes, pass the symbol +:all+
659
+ #
660
+ # :select => :all
661
+ #
648
662
  # @option options [String, Numeric] :hash_value Attribute value
649
663
  # of the hash component of the composite primary key.
650
664
  #
@@ -679,6 +693,7 @@ module AWS
679
693
  # @option options [String, Numeric] :range_begins_with Matches
680
694
  # items where the range key value begins with this value.
681
695
  # This option is only valid if the range key is a string.
696
+ #
682
697
  def query(options = {}, &block)
683
698
 
684
699
  options = options.merge(:query => true)