aws-sdk-core 2.0.0.rc2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -7
  3. data/.yardopts +1 -0
  4. data/Gemfile +5 -1
  5. data/README.md +26 -0
  6. data/apis/AutoScaling-2011-01-01.json +57 -0
  7. data/apis/CloudFormation-2010-05-15.json +29 -0
  8. data/apis/CloudFront-2012-05-05.json +33 -0
  9. data/apis/CloudFront-2013-05-12.json +33 -0
  10. data/apis/CloudFront-2013-08-26.json +33 -0
  11. data/apis/CloudSearch-2011-02-01.json +1 -0
  12. data/apis/CloudWatch-2010-08-01.json +22 -0
  13. data/apis/DataPipeline-2012-10-29.json +25 -0
  14. data/apis/DirectConnect-2012-10-25.json +1 -0
  15. data/apis/DynamoDB-2011-12-05.json +29 -0
  16. data/apis/DynamoDB-2012-08-10.json +29 -0
  17. data/apis/EC2-2013-06-15.json +29 -0
  18. data/apis/EC2-2013-10-01.json +29 -0
  19. data/apis/EMR-2009-03-31.json +958 -40
  20. data/apis/ElastiCache-2012-11-15.json +72 -0
  21. data/apis/ElastiCache-2013-06-15.json +72 -0
  22. data/apis/ElasticBeanstalk-2010-12-01.json +8 -0
  23. data/apis/ElasticLoadBalancing-2012-06-01.json +8 -0
  24. data/apis/ElasticTranscoder-2012-09-25.json +16 -3
  25. data/apis/Glacier-2012-06-01.json +35 -0
  26. data/apis/IAM-2010-05-08.json +129 -0
  27. data/apis/ImportExport-2010-06-01.json +9 -0
  28. data/apis/Kinesis-2013-12-02.json +409 -0
  29. data/apis/OpsWorks-2013-02-18.json +1 -0
  30. data/apis/RDS-2013-01-10.json +106 -0
  31. data/apis/RDS-2013-02-12.json +120 -0
  32. data/apis/RDS-2013-05-15.json +120 -0
  33. data/apis/Redshift-2012-12-01.json +90 -1
  34. data/apis/Route53-2012-12-12.json +27 -0
  35. data/apis/S3-2006-03-01.json +34 -0
  36. data/apis/SDB-2009-04-15.json +16 -0
  37. data/apis/SES-2010-12-01.json +8 -0
  38. data/apis/SNS-2010-03-31.json +22 -0
  39. data/apis/SQS-2012-11-05.json +1 -0
  40. data/apis/STS-2011-06-15.json +3 -1
  41. data/apis/SWF-2012-01-25.json +52 -1
  42. data/apis/StorageGateway-2012-06-30.json +15 -0
  43. data/apis/StorageGateway-2013-06-30.json +15 -0
  44. data/apis/Support-2013-04-15.json +15 -0
  45. data/apis/configuration/endpoints.json +88 -23
  46. data/apis/source/elasticmapreduce-2009-03-31.json +1529 -126
  47. data/apis/source/elasticmapreduce-2009-03-31.paginators.json +25 -0
  48. data/apis/source/importexport-2010-06-01.paginators.json +1 -0
  49. data/apis/source/kinesis-2013-12-02.json +894 -0
  50. data/apis/source/kinesis-2013-12-02.paginators.json +18 -0
  51. data/apis/source/rds-2013-01-10.paginators.json +1 -0
  52. data/apis/source/rds-2013-02-12.paginators.json +1 -0
  53. data/apis/source/rds-2013-05-15.paginators.json +1 -0
  54. data/apis/source/redshift-2012-12-01.paginators.json +1 -0
  55. data/apis/source/s3-2006-03-01.paginators.json +1 -1
  56. data/aws-sdk-core.gemspec +1 -0
  57. data/doc-src/plugins/stability.rb +1 -0
  58. data/features/glacier/client.feature +5 -0
  59. data/features/glacier/step_definitions.rb +56 -5
  60. data/features/kinesis/client.feature +18 -0
  61. data/features/kinesis/setup.rb +6 -0
  62. data/features/s3/buckets.feature +10 -0
  63. data/features/s3/objects.feature +9 -0
  64. data/features/s3/step_definitions.rb +29 -0
  65. data/lib/aws.rb +13 -2
  66. data/lib/aws/api/pagination_translator.rb +71 -0
  67. data/lib/aws/api/service_translators/glacier.rb +0 -7
  68. data/lib/aws/api/translator.rb +10 -3
  69. data/lib/aws/error_handler.rb +1 -1
  70. data/lib/aws/json/builder.rb +4 -2
  71. data/lib/aws/pageable_response.rb +230 -0
  72. data/lib/aws/plugins/glacier_checksums.rb +10 -29
  73. data/lib/aws/plugins/response_paging.rb +18 -0
  74. data/lib/aws/plugins/retry_errors.rb +3 -1
  75. data/lib/aws/plugins/s3_complete_multipart_upload_fix.rb +1 -1
  76. data/lib/aws/plugins/s3_get_bucket_location_fix.rb +9 -3
  77. data/lib/aws/plugins/signature_v4.rb +2 -1
  78. data/lib/aws/plugins/sqs_queue_urls.rb +7 -4
  79. data/lib/aws/plugins/user_agent.rb +3 -3
  80. data/lib/aws/response_handler.rb +1 -1
  81. data/lib/aws/signers/s3.rb +1 -1
  82. data/lib/aws/tree_hash.rb +69 -0
  83. data/lib/aws/version.rb +1 -1
  84. data/spec/aws/json/builder_spec.rb +12 -0
  85. data/spec/aws/pageable_response_spec.rb +195 -0
  86. data/spec/aws/plugins/retry_errors_spec.rb +13 -0
  87. data/spec/aws/plugins/signature_v4_spec.rb +65 -0
  88. data/spec/aws/plugins/sqs_queue_urls_spec.rb +41 -0
  89. data/spec/aws_spec.rb +4 -0
  90. data/spec/fixtures/operations/glacier/get_job_output.yml +23 -0
  91. data/spec/fixtures/operations/s3/get_bucket_policy.yml +8 -0
  92. data/tasks/endpoints.rake +15 -0
  93. data/tasks/handlers.rake +1 -1
  94. data/vendor/seahorse/lib/seahorse/client.rb +1 -0
  95. data/vendor/seahorse/lib/seahorse/client/base.rb +6 -0
  96. data/vendor/seahorse/lib/seahorse/client/configuration.rb +1 -1
  97. data/vendor/seahorse/lib/seahorse/client/handler_builder.rb +3 -3
  98. data/vendor/seahorse/lib/seahorse/client/handler_list.rb +2 -2
  99. data/vendor/seahorse/lib/seahorse/client/http/error.rb +17 -0
  100. data/vendor/seahorse/lib/seahorse/client/http/plain_string_io.rb +10 -0
  101. data/vendor/seahorse/lib/seahorse/client/logging/handler.rb +1 -1
  102. data/vendor/seahorse/lib/seahorse/client/net_http/handler.rb +13 -2
  103. data/vendor/seahorse/lib/seahorse/client/plugins/json_simple.rb +1 -1
  104. data/vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb +4 -2
  105. data/vendor/seahorse/lib/seahorse/client/plugins/restful_bindings.rb +9 -1
  106. data/vendor/seahorse/lib/seahorse/client/request.rb +14 -0
  107. data/vendor/seahorse/lib/seahorse/client/response.rb +8 -38
  108. data/vendor/seahorse/lib/seahorse/model/shapes/shape.rb +11 -3
  109. data/vendor/seahorse/spec/seahorse/client/configuration_spec.rb +13 -0
  110. data/vendor/seahorse/spec/seahorse/client/net_http/handler_spec.rb +6 -0
  111. data/vendor/seahorse/spec/seahorse/client/response_spec.rb +9 -63
  112. metadata +41 -3
@@ -9,7 +9,7 @@ module Aws
9
9
  attr_accessor :handler
10
10
 
11
11
  def call(context)
12
- @handler.call(context).on_status(300..599) do |response|
12
+ @handler.call(context).on(300..599) do |response|
13
13
  if empty_body?(response)
14
14
  error_code = error_code_for_empty_response(response)
15
15
  error_message = ''
@@ -42,8 +42,10 @@ module Aws
42
42
  def structure(shape, values)
43
43
  data = {}
44
44
  values.each do |key, value|
45
- if member_shape = shape.members[key]
46
- data[member_shape.serialized_name] = member(member_shape, value)
45
+ unless value.nil?
46
+ if member_shape = shape.members[key]
47
+ data[member_shape.serialized_name] = member(member_shape, value)
48
+ end
47
49
  end
48
50
  end
49
51
  data
@@ -0,0 +1,230 @@
1
+ require 'jamespath'
2
+
3
+ module Aws
4
+
5
+ # A simple response pager.
6
+ #
7
+ # ## Basic Usage
8
+ #
9
+ # A pager is constructed with a response and a paging configuration.
10
+ # Typically, the paging configuration will already be present in
11
+ # the response context.
12
+ #
13
+ # The pager becomes a delegate to the response that allows you to
14
+ # discover if there are additional response pages to be requested.
15
+ #
16
+ # page = PageableResponse.new(response)
17
+ # page.last_page?(false)
18
+ #
19
+ # # sends a request to receive the next response page
20
+ # page = page.next_page
21
+ # page.last_page?(true)
22
+ #
23
+ # page.next_page
24
+ # #=> raises PageableResponse::LastPageError
25
+ #
26
+ # You can still access all of the attributes and methods of the
27
+ # wrapped response.
28
+ #
29
+ # # same
30
+ # response.data
31
+ # PageableResponse.new(response).data
32
+ #
33
+ # ## Paging Rules
34
+ #
35
+ # You can configure paging behavior by passing a `:paging_rules`
36
+ # hash to the constructor. If the hash is empty, then paging
37
+ # will be disabled.
38
+ #
39
+ # # disables pagigng
40
+ # page = PageableResponse.new(response, paging_rules: {})
41
+ # page.last_page?
42
+ # #=> true
43
+ #
44
+ # ### Tokens
45
+ #
46
+ # If you want to configure paging you must specify at least
47
+ # the `tokens` entry:
48
+ #
49
+ # paging_rules = {
50
+ # 'tokens' => {
51
+ # 'input_param' => 'response_key',
52
+ # }
53
+ # }
54
+ #
55
+ # Tokens should be a hash of request parameter names as keys, and
56
+ # response data member names as values. The `response.data` is
57
+ # inspected for a `response_key` member. If it is present,
58
+ # it will be sent to the next page request as `:input_param`.
59
+ #
60
+ # If all of the configured tokens return `nil` values, the response
61
+ # is assumed to be the last page of results.
62
+ #
63
+ # ### Truncation Indicator
64
+ #
65
+ # Some services do not specify a token, but rather expect you to
66
+ # extract the final value from some list to request the next page.
67
+ # When this is the case, they will typically provide some boolean
68
+ # response data value that indicates if the response is truncated.
69
+ # You can configure this via `truncated_if`:
70
+ #
71
+ # paging_rules['truncated_if'] = 'is_truncated'
72
+ #
73
+ # When `truncated_if` is configured, the tokens will not be checked,
74
+ # unless the configured member is `true`.
75
+ #
76
+ # @stability Unstable
77
+ # PageableResponse public methods should be considered stable.
78
+ # The structure of `:paging_rules` should be considered unstable
79
+ # and subject to change. If you are not providing custom
80
+ # paging rules, then you should not worry about backwards
81
+ # incompatible changes.
82
+ #
83
+ class PageableResponse < Seahorse::Client::Response
84
+
85
+ include Enumerable
86
+
87
+ # Raised when calling {PageableResponse#next_page} on a pager that
88
+ # is on the last page of results. You can call {PageableResponse#last_page?}
89
+ # or {PageableResponse#next_page?} to know if there are more pages.
90
+ class LastPageError < RuntimeError
91
+
92
+ # @param [Seahorse::Client::Response] response
93
+ def initialize(response)
94
+ @response = response
95
+ super("unable to fetch next page, end of results reached")
96
+ end
97
+
98
+ # @return [Seahorse::Client::Response]
99
+ attr_reader :response
100
+
101
+ end
102
+
103
+ # @param [Seahorse::Client::Response] response
104
+ #
105
+ # @option options [Hash] :paging_rules Defaults to the `paging`
106
+ # configuration in the response context. If one is not configured
107
+ # or you wish to override this paging configuration, you can
108
+ # pass the `:paging_rules` option. Passing an empty hash
109
+ # disable paging for this operation.
110
+ #
111
+ # See class level documentation above for more information about the
112
+ # structure of `:paging_rules`.
113
+ #
114
+ # @stability Experimental
115
+ # The structure of the `:paging_rules` option is subject to change.
116
+ # Using this class without a custom set of paging rules should
117
+ # be considered stable.
118
+ #
119
+ def initialize(response, options = {})
120
+ super(context:response.context, data:response.data, error:response.error)
121
+ @paging_rules = options[:paging_rules]
122
+ end
123
+
124
+ # Returns `true` if there are no more results. Calling {#next_page}
125
+ # when this method returns `false` will raise an error.
126
+ # @return [Boolean]
127
+ def last_page?
128
+ !next_page?
129
+ end
130
+
131
+ # Returns `true` if there are more results. Calling {#next_page} will
132
+ # return the next response.
133
+ # @return [Boolean]
134
+ def next_page?
135
+ @next_page = !!(pageable? && truncated?) if @next_page.nil?
136
+ @next_page
137
+ end
138
+
139
+ # @return [Seahorse::Client::Response]
140
+ def next_page(params = {})
141
+ if last_page?
142
+ raise LastPageError.new(self)
143
+ else
144
+ PageableResponse.new(next_response(params), paging_rules: paging_rules)
145
+ end
146
+ end
147
+
148
+ # Yields the current and each following response to the given block.
149
+ # @yieldparam [Response] response
150
+ # @return [Enumerable,nil] Returns a new Enumerable if no block is given.
151
+ def each_page(&block)
152
+ if block_given?
153
+ response = self
154
+ yield(response)
155
+ until response.last_page?
156
+ response = response.next_page
157
+ yield(response)
158
+ end
159
+ else
160
+ to_enum(__method__)
161
+ end
162
+ end
163
+ alias each each_page
164
+
165
+ # @api private
166
+ def eql?(other)
167
+ other.is_a?(Seahorse::Client::Response) &&
168
+ other.context == context &&
169
+ other.data == data &&
170
+ other.error == error
171
+ end
172
+ alias == eql?
173
+
174
+ private
175
+
176
+ # @return [Boolean] Returns `true` if the API operation is pageable.
177
+ # Returns `false` if the API operation always returns ALL results.
178
+ def pageable?
179
+ paging_rules.key?('tokens')
180
+ end
181
+
182
+ # @return [Boolean] Returns `true` if the response is truncated and
183
+ # there are more results to be had.
184
+ def truncated?
185
+ if condition = paging_rules['truncated_if']
186
+ Jamespath.search(condition, data)
187
+ else
188
+ !next_tokens.empty?
189
+ end
190
+ end
191
+
192
+ # @return [Hash] Extracts a hash of request parameters from
193
+ # the response data that are needed to request the next response
194
+ # page.
195
+ def next_tokens
196
+ @next_tokens ||= begin
197
+ paging_rules['tokens'].inject({}) do |tokens, (param, jamespath)|
198
+ value = Jamespath.search(jamespath, data)
199
+ tokens[param.to_sym] = value unless value.nil?
200
+ tokens
201
+ end
202
+ end
203
+ end
204
+
205
+ # @return [Hash, nil] Returns the rules for paging this response.
206
+ # Returns `nil` when the response is not pageable.
207
+ def paging_rules
208
+ @paging_rules ||= context.operation.metadata['paging'] || {}
209
+ end
210
+
211
+ # @param [Hash] params A hash of additional request params to
212
+ # merge into the next page request.
213
+ # @return [Seahorse::Client::Response] Returns the next page of
214
+ # results.
215
+ def next_response(params)
216
+ c = context
217
+ req = c.client.build_request(c.operation_name, next_page_params(params))
218
+ req.send_request
219
+ end
220
+
221
+ # @param [Hash] params A hash of additional request params to
222
+ # merge into the next page request.
223
+ # @return [Hash] Returns the hash of request parameters for the
224
+ # next page, merging any given params.
225
+ def next_page_params(params)
226
+ context.params.merge(next_tokens.merge(params))
227
+ end
228
+
229
+ end
230
+ end
@@ -23,7 +23,6 @@ module Aws
23
23
  class GlacierChecksums < Seahorse::Client::Plugin
24
24
 
25
25
  CHECKSUM_OPERATIONS = [
26
- :complete_multipart_upload,
27
26
  :upload_archive,
28
27
  :upload_multipart_part,
29
28
  ]
@@ -35,17 +34,18 @@ module Aws
35
34
 
36
35
  def call(context)
37
36
  unless context.http_request.headers[TREE_HASH]
38
- populate_checksum_headers(context.http_request)
37
+ populate_checksum_headers(context)
39
38
  end
40
39
  @handler.call(context)
41
40
  end
42
41
 
43
42
  private
44
43
 
45
- def populate_checksum_headers(http_req)
46
- compute_checksums(http_req.body) do |hash, tree_hash|
47
- http_req.headers[HASH] = hash
48
- http_req.headers[TREE_HASH] = tree_hash
44
+ def populate_checksum_headers(context)
45
+ compute_checksums(context.http_request.body) do |hash, tree_hash|
46
+ context.http_request.headers[HASH] = hash
47
+ context.http_request.headers[TREE_HASH] = tree_hash.digest
48
+ context[:tree_hash] = tree_hash
49
49
  end
50
50
  end
51
51
 
@@ -55,46 +55,27 @@ module Aws
55
55
  # here so the sigv4 signer does not need to re-read the body.
56
56
  def compute_checksums(body, &block)
57
57
 
58
+ tree_hash = TreeHash.new
58
59
  digest = OpenSSL::Digest::Digest.new('sha256')
59
- tree_digest = OpenSSL::Digest::Digest.new('sha256')
60
- tree_parts = []
61
60
 
62
61
  # if the body is empty/EOF, then we should compute the
63
62
  # digests of the empty string
64
63
  if body.size == 0
65
- tree_parts << tree_digest.update('').digest
64
+ tree_hash.update('')
66
65
  digest.update('')
67
66
  end
68
67
 
69
68
  until body.eof?
70
69
  chunk = body.read(1024 * 1024) # read 1MB
71
- tree_parts << tree_digest.update(chunk).digest
72
- tree_digest.reset
70
+ tree_hash.update(chunk)
73
71
  digest.update(chunk)
74
72
  end
75
73
 
76
74
  body.rewind
77
75
 
78
- yield(digest.to_s, compute_tree_hash(tree_parts))
76
+ yield(digest.to_s, tree_hash)
79
77
 
80
78
  end
81
-
82
- def compute_tree_hash hashes
83
- digest = OpenSSL::Digest::Digest.new('sha256')
84
- until hashes.count == 1
85
- hashes = hashes.each_slice(2).map do |h1,h2|
86
- digest.reset
87
- if h2
88
- digest.update(h1)
89
- digest.update(h2)
90
- digest.digest
91
- else
92
- h1
93
- end
94
- end
95
- end
96
- hashes.first.bytes.map{|x| x.to_i.to_s(16).rjust(2,'0')}.join('')
97
- end
98
79
  end
99
80
 
100
81
  handler(Handler, operations: CHECKSUM_OPERATIONS)
@@ -0,0 +1,18 @@
1
+ module Aws
2
+ module Plugins
3
+ class ResponsePaging < Seahorse::Client::Plugin
4
+
5
+ # @api private
6
+ class Handler < Seahorse::Client::Handler
7
+
8
+ def call(context)
9
+ PageableResponse.new(@handler.call(context))
10
+ end
11
+
12
+ end
13
+
14
+ handler(Handler)
15
+
16
+ end
17
+ end
18
+ end
@@ -61,7 +61,9 @@ module Aws
61
61
  end
62
62
 
63
63
  def networking?
64
- NETWORKING_ERRORS.include?(@name) || @http_status_code == 0
64
+ @error.is_a?(Seahorse::Client::Http::Error) ||
65
+ NETWORKING_ERRORS.include?(@name) ||
66
+ @http_status_code == 0
65
67
  end
66
68
 
67
69
  def server?
@@ -7,7 +7,7 @@ module Aws
7
7
  class Handler < Seahorse::Client::Handler
8
8
 
9
9
  def call(context)
10
- @handler.call(context).on_success do |response|
10
+ @handler.call(context).on(200) do |response|
11
11
  if error = check_for_error(response)
12
12
  response.http_response.status_code = 500
13
13
  response.data = nil
@@ -5,10 +5,16 @@ module Aws
5
5
  class Handler < Seahorse::Client::Handler
6
6
 
7
7
  def call(context)
8
- @handler.call(context).on_success do |response|
8
+ @handler.call(context).on(200) do |response|
9
9
  xml = MultiXml.parse(response.http_response.body_contents)
10
- if constraint = xml['LocationConstraint']
11
- response.data[:location_constraint] = constraint['__content__'].to_s
10
+ if xml.key?('LocationConstraint')
11
+ constraint = xml['LocationConstraint']
12
+ response.data[:location_constraint] =
13
+ case constraint
14
+ when String then constraint
15
+ when Hash then constraint['__content__'].to_s
16
+ when nil then ''
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -8,7 +8,8 @@ module Aws
8
8
  class SignatureV4 < Seahorse::Client::Plugin
9
9
 
10
10
  option(:sigv4_name) do |config|
11
- config.api.metadata['endpoint_prefix']
11
+ config.api.metadata['signing_name'] ||
12
+ config.api.metadata['endpoint_prefix']
12
13
  end
13
14
 
14
15
  option(:sigv4_region) do |config|
@@ -18,10 +18,13 @@ module Aws
18
18
  end
19
19
 
20
20
  def update_region(context, url)
21
- region = url.split('.')[1]
22
- context.config = context.config.dup
23
- context.config.region = region
24
- context.config.sigv4_region = region
21
+ if region = url.split('.')[1]
22
+ context.config = context.config.dup
23
+ context.config.region = region
24
+ context.config.sigv4_region = region
25
+ else
26
+ raise ArgumentError, "invalid queue url `#{url}'"
27
+ end
25
28
  end
26
29
 
27
30
  end
@@ -2,7 +2,7 @@ module Aws
2
2
  module Plugins
3
3
  class UserAgent < Seahorse::Client::Plugin
4
4
 
5
- option(:user_agent_prefix)
5
+ option(:user_agent_suffix)
6
6
 
7
7
  # @api private
8
8
  class Handler < Seahorse::Client::Handler
@@ -13,12 +13,12 @@ module Aws
13
13
  end
14
14
 
15
15
  def set_user_agent(context)
16
- ua = "%s aws-sdk-ruby/#{VERSION} %s/%s %s Seahorse/%s" % [
17
- context.config.user_agent_prefix,
16
+ ua = "aws-sdk-ruby2/#{VERSION} %s/%s %s Seahorse/%s %s" % [
18
17
  (RUBY_ENGINE rescue nil or "ruby"),
19
18
  RUBY_VERSION,
20
19
  RUBY_PLATFORM,
21
20
  Seahorse::VERSION,
21
+ context.config.user_agent_suffix,
22
22
  ]
23
23
  context.http_request.headers['User-Agent'] = ua.strip
24
24
  end