aws-sdk 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ca-bundle.crt +2 -348
- data/lib/aws.rb +24 -49
- data/lib/aws/{common.rb → core.rb} +120 -9
- data/lib/aws/{api_config.rb → core/api_config.rb} +19 -20
- data/lib/aws/core/api_config_transform.rb +36 -0
- data/lib/aws/core/async_handle.rb +91 -0
- data/lib/aws/core/authorize_v2.rb +39 -0
- data/lib/aws/{authorize_v3.rb → core/authorize_v3.rb} +16 -15
- data/lib/aws/{api_config_transform.rb → core/authorize_with_session_token.rb} +9 -12
- data/lib/aws/core/autoloader.rb +64 -0
- data/lib/aws/core/cacheable.rb +78 -0
- data/lib/aws/core/client.rb +471 -0
- data/lib/aws/core/client_logging.rb +125 -0
- data/lib/aws/core/collections.rb +229 -0
- data/lib/aws/core/configuration.rb +358 -0
- data/lib/aws/core/configured_client_methods.rb +76 -0
- data/lib/aws/core/configured_grammars.rb +63 -0
- data/lib/aws/{configured_option_grammars.rb → core/configured_option_grammars.rb} +18 -20
- data/lib/aws/{configured_xml_grammars.rb → core/configured_xml_grammars.rb} +19 -21
- data/lib/aws/core/default_signer.rb +67 -0
- data/lib/aws/core/http/curb_handler.rb +129 -0
- data/lib/aws/core/http/handler.rb +77 -0
- data/lib/aws/core/http/httparty_handler.rb +113 -0
- data/lib/aws/core/http/net_http_handler.rb +124 -0
- data/lib/aws/core/http/request.rb +207 -0
- data/lib/aws/core/http/response.rb +73 -0
- data/lib/aws/{ignore_result_element.rb → core/ignore_result_element.rb} +14 -18
- data/lib/aws/core/indifferent_hash.rb +88 -0
- data/lib/aws/core/inflection.rb +47 -0
- data/lib/aws/core/lazy_error_classes.rb +62 -0
- data/lib/aws/{uri_escape.rb → core/meta_utils.rb} +24 -23
- data/lib/aws/core/model.rb +57 -0
- data/lib/aws/{authorize_with_session_token.rb → core/naming.rb} +9 -8
- data/lib/aws/core/option_grammar.rb +562 -0
- data/lib/aws/core/policy.rb +914 -0
- data/lib/aws/core/resource.rb +380 -0
- data/lib/aws/core/resource_cache.rb +40 -0
- data/lib/aws/core/response.rb +125 -0
- data/lib/aws/core/response_cache.rb +50 -0
- data/lib/aws/core/service_interface.rb +60 -0
- data/lib/aws/core/uri_escape.rb +46 -0
- data/lib/aws/core/xml_grammar.rb +926 -0
- data/lib/aws/ec2.rb +47 -16
- data/lib/aws/ec2/attachment.rb +0 -2
- data/lib/aws/ec2/attachment_collection.rb +1 -6
- data/lib/aws/ec2/availability_zone.rb +0 -2
- data/lib/aws/ec2/availability_zone_collection.rb +0 -3
- data/lib/aws/ec2/client.rb +6 -9
- data/lib/aws/ec2/client/xml.rb +3 -6
- data/lib/aws/ec2/collection.rb +1 -4
- data/lib/aws/ec2/config.rb +18 -0
- data/lib/aws/ec2/elastic_ip.rb +0 -2
- data/lib/aws/ec2/elastic_ip_collection.rb +0 -4
- data/lib/aws/ec2/errors.rb +1 -4
- data/lib/aws/ec2/has_permissions.rb +0 -2
- data/lib/aws/ec2/image.rb +0 -5
- data/lib/aws/ec2/image_collection.rb +0 -6
- data/lib/aws/ec2/instance.rb +23 -9
- data/lib/aws/ec2/instance_collection.rb +85 -22
- data/lib/aws/ec2/key_pair.rb +0 -2
- data/lib/aws/ec2/key_pair_collection.rb +1 -4
- data/lib/aws/ec2/permission_collection.rb +2 -5
- data/lib/aws/ec2/region.rb +0 -2
- data/lib/aws/ec2/region_collection.rb +0 -4
- data/lib/aws/ec2/request.rb +4 -9
- data/lib/aws/ec2/reserved_instances.rb +0 -3
- data/lib/aws/ec2/reserved_instances_collection.rb +0 -4
- data/lib/aws/ec2/reserved_instances_offering.rb +0 -3
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +0 -4
- data/lib/aws/ec2/resource.rb +3 -5
- data/lib/aws/ec2/resource_tag_collection.rb +1 -6
- data/lib/aws/ec2/security_group.rb +204 -72
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +53 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +92 -10
- data/lib/aws/ec2/security_group/ip_permission_collection.rb +14 -15
- data/lib/aws/ec2/security_group_collection.rb +11 -8
- data/lib/aws/ec2/snapshot.rb +0 -4
- data/lib/aws/ec2/snapshot_collection.rb +0 -4
- data/lib/aws/ec2/tag.rb +0 -3
- data/lib/aws/ec2/tag_collection.rb +1 -8
- data/lib/aws/ec2/tagged_item.rb +1 -3
- data/lib/aws/ec2/volume.rb +0 -6
- data/lib/aws/ec2/volume_collection.rb +0 -4
- data/lib/aws/errors.rb +0 -3
- data/lib/aws/iam.rb +33 -12
- data/lib/aws/iam/access_key.rb +0 -3
- data/lib/aws/iam/access_key_collection.rb +0 -3
- data/lib/aws/iam/account_alias_collection.rb +0 -2
- data/lib/aws/iam/client.rb +6 -8
- data/lib/aws/iam/client/xml.rb +4 -8
- data/lib/aws/iam/collection.rb +2 -5
- data/lib/aws/iam/config.rb +18 -0
- data/lib/aws/iam/errors.rb +2 -4
- data/lib/aws/iam/group.rb +0 -5
- data/lib/aws/iam/group_collection.rb +0 -3
- data/lib/aws/iam/group_policy_collection.rb +0 -2
- data/lib/aws/iam/group_user_collection.rb +1 -4
- data/lib/aws/iam/login_profile.rb +0 -2
- data/lib/aws/iam/mfa_device.rb +1 -3
- data/lib/aws/iam/mfa_device_collection.rb +0 -3
- data/lib/aws/iam/policy.rb +2 -4
- data/lib/aws/iam/policy_collection.rb +0 -3
- data/lib/aws/iam/request.rb +3 -7
- data/lib/aws/iam/resource.rb +1 -4
- data/lib/aws/iam/server_certificate.rb +0 -2
- data/lib/aws/iam/server_certificate_collection.rb +0 -3
- data/lib/aws/iam/signing_certificate.rb +0 -2
- data/lib/aws/iam/signing_certificate_collection.rb +0 -3
- data/lib/aws/iam/user.rb +0 -7
- data/lib/aws/iam/user_collection.rb +0 -3
- data/lib/aws/iam/user_group_collection.rb +0 -3
- data/lib/aws/iam/user_policy.rb +0 -2
- data/lib/aws/iam/user_policy_collection.rb +0 -3
- data/lib/aws/rails.rb +5 -4
- data/lib/aws/record.rb +4 -1
- data/lib/aws/record/base.rb +3 -2
- data/lib/aws/record/errors.rb +1 -3
- data/lib/aws/s3.rb +31 -6
- data/lib/aws/s3/access_control_list.rb +0 -2
- data/lib/aws/s3/acl_object.rb +10 -12
- data/lib/aws/s3/bucket.rb +1 -9
- data/lib/aws/s3/bucket_collection.rb +2 -5
- data/lib/aws/s3/bucket_version_collection.rb +1 -5
- data/lib/aws/s3/client.rb +34 -37
- data/lib/aws/s3/client/xml.rb +11 -14
- data/lib/aws/{resource_cache.rb → s3/config.rb} +6 -20
- data/lib/aws/s3/errors.rb +6 -7
- data/lib/aws/s3/multipart_upload.rb +1 -4
- data/lib/aws/s3/multipart_upload_collection.rb +1 -6
- data/lib/aws/s3/object_collection.rb +1 -5
- data/lib/aws/s3/object_metadata.rb +1 -3
- data/lib/aws/s3/object_upload_collection.rb +1 -7
- data/lib/aws/s3/object_version.rb +1 -4
- data/lib/aws/s3/object_version_collection.rb +1 -4
- data/lib/aws/s3/policy.rb +3 -5
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +0 -2
- data/lib/aws/s3/prefixed_collection.rb +0 -2
- data/lib/aws/s3/presigned_post.rb +1 -3
- data/lib/aws/s3/request.rb +2 -5
- data/lib/aws/s3/s3_object.rb +1 -8
- data/lib/aws/s3/tree.rb +8 -6
- data/lib/aws/s3/tree/branch_node.rb +0 -3
- data/lib/aws/s3/tree/child_collection.rb +1 -5
- data/lib/aws/s3/tree/leaf_node.rb +0 -5
- data/lib/aws/s3/tree/parent.rb +1 -4
- data/lib/aws/s3/uploaded_part.rb +1 -3
- data/lib/aws/s3/uploaded_part_collection.rb +1 -5
- data/lib/aws/simple_db.rb +21 -6
- data/lib/aws/simple_db/attribute.rb +1 -6
- data/lib/aws/simple_db/attribute_collection.rb +1 -7
- data/lib/aws/simple_db/client.rb +7 -9
- data/lib/aws/simple_db/client/options.rb +2 -4
- data/lib/aws/simple_db/client/xml.rb +5 -10
- data/lib/aws/{naming.rb → simple_db/config.rb} +3 -14
- data/lib/aws/simple_db/delete_attributes.rb +0 -2
- data/lib/aws/simple_db/domain.rb +1 -6
- data/lib/aws/simple_db/domain_collection.rb +1 -4
- data/lib/aws/simple_db/domain_metadata.rb +1 -3
- data/lib/aws/simple_db/errors.rb +1 -4
- data/lib/aws/simple_db/item.rb +1 -7
- data/lib/aws/simple_db/item_collection.rb +22 -23
- data/lib/aws/simple_db/put_attributes.rb +0 -2
- data/lib/aws/simple_db/request.rb +3 -7
- data/lib/aws/simple_email_service.rb +11 -6
- data/lib/aws/simple_email_service/client.rb +7 -9
- data/lib/aws/simple_email_service/client/options.rb +3 -6
- data/lib/aws/simple_email_service/client/xml.rb +4 -8
- data/lib/aws/simple_email_service/config.rb +19 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +1 -3
- data/lib/aws/simple_email_service/errors.rb +1 -4
- data/lib/aws/simple_email_service/quotas.rb +1 -3
- data/lib/aws/simple_email_service/request.rb +3 -7
- data/lib/aws/sns.rb +15 -8
- data/lib/aws/sns/client.rb +7 -8
- data/lib/aws/sns/client/options.rb +3 -6
- data/lib/aws/sns/client/xml.rb +4 -8
- data/lib/aws/sns/config.rb +18 -0
- data/lib/aws/sns/errors.rb +1 -4
- data/lib/aws/sns/policy.rb +3 -5
- data/lib/aws/sns/request.rb +4 -9
- data/lib/aws/sns/subscription.rb +1 -5
- data/lib/aws/sns/subscription_collection.rb +1 -5
- data/lib/aws/sns/topic.rb +1 -6
- data/lib/aws/sns/topic_collection.rb +1 -4
- data/lib/aws/sns/topic_subscription_collection.rb +1 -4
- data/lib/aws/sqs.rb +14 -5
- data/lib/aws/sqs/client.rb +6 -9
- data/lib/aws/sqs/client/xml.rb +4 -7
- data/lib/aws/sqs/config.rb +18 -0
- data/lib/aws/sqs/errors.rb +1 -4
- data/lib/aws/sqs/policy.rb +3 -5
- data/lib/aws/sqs/queue.rb +2 -7
- data/lib/aws/sqs/queue_collection.rb +4 -5
- data/lib/aws/sqs/received_message.rb +1 -3
- data/lib/aws/sqs/received_sns_message.rb +2 -2
- data/lib/aws/sqs/request.rb +4 -7
- data/lib/aws/sts.rb +12 -6
- data/lib/aws/sts/client.rb +6 -8
- data/lib/aws/sts/client/xml.rb +4 -8
- data/lib/aws/sts/config.rb +18 -0
- data/lib/aws/sts/errors.rb +1 -4
- data/lib/aws/sts/federated_session.rb +0 -2
- data/lib/aws/sts/policy.rb +3 -5
- data/lib/aws/sts/request.rb +3 -7
- metadata +60 -50
- data/lib/aws/async_handle.rb +0 -90
- data/lib/aws/authorize_v2.rb +0 -37
- data/lib/aws/base_client.rb +0 -488
- data/lib/aws/cacheable.rb +0 -79
- data/lib/aws/client_logging.rb +0 -122
- data/lib/aws/collections.rb +0 -230
- data/lib/aws/configuration.rb +0 -357
- data/lib/aws/configured_client_methods.rb +0 -81
- data/lib/aws/configured_grammars.rb +0 -65
- data/lib/aws/default_signer.rb +0 -65
- data/lib/aws/http/curb_handler.rb +0 -127
- data/lib/aws/http/handler.rb +0 -77
- data/lib/aws/http/httparty_handler.rb +0 -103
- data/lib/aws/http/request.rb +0 -165
- data/lib/aws/http/request_param.rb +0 -64
- data/lib/aws/http/response.rb +0 -72
- data/lib/aws/indifferent_hash.rb +0 -86
- data/lib/aws/inflection.rb +0 -46
- data/lib/aws/lazy_error_classes.rb +0 -64
- data/lib/aws/meta_utils.rb +0 -43
- data/lib/aws/model.rb +0 -57
- data/lib/aws/option_grammar.rb +0 -565
- data/lib/aws/policy.rb +0 -914
- data/lib/aws/resource.rb +0 -381
- data/lib/aws/response.rb +0 -125
- data/lib/aws/response_cache.rb +0 -50
- data/lib/aws/service_interface.rb +0 -60
- data/lib/aws/xml_grammar.rb +0 -925
data/lib/aws/base_client.rb
DELETED
@@ -1,488 +0,0 @@
|
|
1
|
-
# Copyright 2011 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
|
-
require 'aws/errors'
|
15
|
-
require 'aws/inflection'
|
16
|
-
require 'aws/naming'
|
17
|
-
require 'aws/response'
|
18
|
-
require 'aws/async_handle'
|
19
|
-
require 'aws/http/handler'
|
20
|
-
require 'aws/http/request'
|
21
|
-
require 'aws/http/response'
|
22
|
-
require 'aws/xml_grammar'
|
23
|
-
require 'aws/option_grammar'
|
24
|
-
require 'aws/client_logging'
|
25
|
-
require 'benchmark'
|
26
|
-
require 'set'
|
27
|
-
|
28
|
-
module AWS
|
29
|
-
|
30
|
-
# Base class for all of the Amazon AWS service clients.
|
31
|
-
# @private
|
32
|
-
class BaseClient
|
33
|
-
|
34
|
-
include ClientLogging
|
35
|
-
|
36
|
-
extend Naming
|
37
|
-
|
38
|
-
CACHEABLE_REQUESTS = Set.new
|
39
|
-
|
40
|
-
# Creates a new low-level client.
|
41
|
-
#
|
42
|
-
# == Required Options
|
43
|
-
#
|
44
|
-
# To create a client you must provide access to AWS credentials.
|
45
|
-
# There are two options:
|
46
|
-
#
|
47
|
-
# * +:signer+ -- An object that responds to +access_key_id+
|
48
|
-
# (to return the AWS Access Key ID) and to
|
49
|
-
# <code>sign(string_to_sign)</code> (to return a signature
|
50
|
-
# for a given string). An example implementation is
|
51
|
-
# AWS::DefaultSigner. This option is useful if you want to
|
52
|
-
# more tightly control access to your secret access key (for
|
53
|
-
# example by moving the signature computation into a
|
54
|
-
# different process).
|
55
|
-
#
|
56
|
-
# * +:access_key_id+ and +:secret_access_key+ -- You can use
|
57
|
-
# these options to provide the AWS Access Key ID and AWS
|
58
|
-
# Secret Access Key directly to the client.
|
59
|
-
#
|
60
|
-
# == Optional
|
61
|
-
#
|
62
|
-
# * +:http_handler+ -- Any object that implements a
|
63
|
-
# <code>handle(request, response)</code> method; an example
|
64
|
-
# is BuiltinHttpHandler. This method is used to perform the
|
65
|
-
# HTTP requests that this client constructs.
|
66
|
-
#
|
67
|
-
def initialize options = {}
|
68
|
-
|
69
|
-
if options[:endpoint]
|
70
|
-
options[:"#{self.class.service_ruby_name}_endpoint"] =
|
71
|
-
options.delete(:endpoint)
|
72
|
-
end
|
73
|
-
|
74
|
-
options_without_config = options.dup
|
75
|
-
@config = options_without_config.delete(:config)
|
76
|
-
@config ||= AWS.config
|
77
|
-
@config = @config.with(options_without_config)
|
78
|
-
@signer = @config.signer
|
79
|
-
@http_handler = @config.http_handler
|
80
|
-
@stubs = {}
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# @return [Configuration] This clients configuration.
|
85
|
-
attr_reader :config
|
86
|
-
|
87
|
-
# @return [DefaultSigner,Object] Returns the signer for this client.
|
88
|
-
# This is normally a DefaultSigner, but it can be configured to
|
89
|
-
# an other object.
|
90
|
-
attr_reader :signer
|
91
|
-
|
92
|
-
# @return [String] the configured endpoint for this client.
|
93
|
-
def endpoint
|
94
|
-
config.send(:"#{self.class.service_ruby_name}_endpoint")
|
95
|
-
end
|
96
|
-
|
97
|
-
# Returns a copy of the client with a different HTTP handler.
|
98
|
-
# You can pass an object like BuiltinHttpHandler or you can
|
99
|
-
# use a block; for example:
|
100
|
-
#
|
101
|
-
# s3_with_logging = s3.with_http_handler do |request, response|
|
102
|
-
# $stderr.puts request.inspect
|
103
|
-
# super
|
104
|
-
# end
|
105
|
-
#
|
106
|
-
# The block executes in the context of an HttpHandler
|
107
|
-
# instance, and +super+ delegates to the HTTP handler used by
|
108
|
-
# this client. This provides an easy way to spy on requests
|
109
|
-
# and responses. See HttpHandler, HttpRequest, and
|
110
|
-
# HttpResponse for more details on how to implement a fully
|
111
|
-
# functional HTTP handler using a different HTTP library than
|
112
|
-
# the one that ships with Ruby.
|
113
|
-
# @param handler (nil) A new http handler. Leave blank and pass a
|
114
|
-
# block to wrap the current handler with the block.
|
115
|
-
# @return [BaseClient] Returns a new instance of the client class with
|
116
|
-
# the modified or wrapped http handler.
|
117
|
-
def with_http_handler(handler = nil, &blk)
|
118
|
-
handler ||= Http::Handler.new(@http_handler, &blk)
|
119
|
-
with_options(:http_handler => handler)
|
120
|
-
end
|
121
|
-
|
122
|
-
# @param [Hash] options
|
123
|
-
# @see AWS.config detailed list of accepted options.
|
124
|
-
def with_options options
|
125
|
-
with_config(config.with(options))
|
126
|
-
end
|
127
|
-
|
128
|
-
# @param [Configuration] The configuration object to use.
|
129
|
-
# @return [BaseClient] Returns a new client object with the given
|
130
|
-
# configuration.
|
131
|
-
def with_config config
|
132
|
-
self.class.new(:config => config)
|
133
|
-
end
|
134
|
-
|
135
|
-
# The stub returned is memoized.
|
136
|
-
# @see new_stub_for
|
137
|
-
# @private
|
138
|
-
def stub_for method_name
|
139
|
-
@stubs[method_name] ||= new_stub_for(method_name)
|
140
|
-
end
|
141
|
-
|
142
|
-
# Primarily used for testing, this method returns an empty psuedo
|
143
|
-
# service response without making a request. Its used primarily for
|
144
|
-
# testing the ligher level service interfaces.
|
145
|
-
# @private
|
146
|
-
def new_stub_for method_name
|
147
|
-
response = Response.new(Http::Request.new, Http::Response.new)
|
148
|
-
response.request_type = method_name
|
149
|
-
response.request_options = {}
|
150
|
-
send("simulate_#{method_name}_response", response)
|
151
|
-
response.signal_success
|
152
|
-
response
|
153
|
-
end
|
154
|
-
|
155
|
-
protected
|
156
|
-
def new_request
|
157
|
-
req = self.class::REQUEST_CLASS.new
|
158
|
-
req.http_method = 'POST'
|
159
|
-
req.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
160
|
-
req.add_param 'Timestamp', Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
161
|
-
req.add_param 'Version', self.class::API_VERSION
|
162
|
-
req
|
163
|
-
end
|
164
|
-
|
165
|
-
protected
|
166
|
-
def new_response(*args, &block)
|
167
|
-
Response.new(*args, &block)
|
168
|
-
end
|
169
|
-
|
170
|
-
private
|
171
|
-
def make_async_request response
|
172
|
-
|
173
|
-
pauses = async_request_with_retries(response, response.http_request)
|
174
|
-
|
175
|
-
response
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
private
|
180
|
-
def async_request_with_retries response, http_request, retry_delays = nil
|
181
|
-
|
182
|
-
response.http_response = AWS::Http::Response.new
|
183
|
-
|
184
|
-
handle = Object.new
|
185
|
-
handle.extend AsyncHandle
|
186
|
-
handle.on_complete do |status|
|
187
|
-
case status
|
188
|
-
when :failure
|
189
|
-
response.error = StandardError.new("failed to contact the service")
|
190
|
-
response.signal_failure
|
191
|
-
when :success
|
192
|
-
populate_error(response)
|
193
|
-
retry_delays ||= sleep_durations(response)
|
194
|
-
if should_retry?(response) and !retry_delays.empty?
|
195
|
-
response.rebuild_request
|
196
|
-
@http_handler.sleep_with_callback(retry_delays.shift) do
|
197
|
-
async_request_with_retries(response, response.http_request, retry_delays)
|
198
|
-
end
|
199
|
-
else
|
200
|
-
response.error ?
|
201
|
-
response.signal_failure :
|
202
|
-
response.signal_success
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
@http_handler.handle_async(http_request, response.http_response, handle)
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
private
|
212
|
-
def make_sync_request response
|
213
|
-
retry_server_errors do
|
214
|
-
|
215
|
-
response.http_response = http_response =
|
216
|
-
AWS::Http::Response.new
|
217
|
-
|
218
|
-
@http_handler.handle(response.http_request, http_response)
|
219
|
-
|
220
|
-
populate_error(response)
|
221
|
-
response.signal_success unless response.error
|
222
|
-
response
|
223
|
-
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
private
|
228
|
-
def retry_server_errors &block
|
229
|
-
|
230
|
-
response = yield
|
231
|
-
|
232
|
-
sleeps = sleep_durations(response)
|
233
|
-
while should_retry?(response)
|
234
|
-
break if sleeps.empty?
|
235
|
-
Kernel.sleep(sleeps.shift)
|
236
|
-
|
237
|
-
# rebuild the request to get a fresh signature
|
238
|
-
response.rebuild_request
|
239
|
-
response = yield
|
240
|
-
end
|
241
|
-
|
242
|
-
response
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
private
|
247
|
-
def sleep_durations response
|
248
|
-
factor = scaling_factor(response)
|
249
|
-
Array.new(config.max_retries) {|n| (2 ** n) * factor }
|
250
|
-
end
|
251
|
-
|
252
|
-
private
|
253
|
-
def scaling_factor response
|
254
|
-
response.throttled? ? (0.5 + Kernel.rand * 0.1) : 0.3
|
255
|
-
end
|
256
|
-
|
257
|
-
private
|
258
|
-
def should_retry? response
|
259
|
-
response.timeout? or
|
260
|
-
response.throttled? or
|
261
|
-
response.error.kind_of?(Errors::ServerError)
|
262
|
-
end
|
263
|
-
|
264
|
-
private
|
265
|
-
def return_or_raise options, &block
|
266
|
-
response = yield
|
267
|
-
unless options[:async]
|
268
|
-
raise response.error if response.error
|
269
|
-
end
|
270
|
-
response
|
271
|
-
end
|
272
|
-
|
273
|
-
protected
|
274
|
-
def populate_error response
|
275
|
-
|
276
|
-
# clear out a previous error
|
277
|
-
response.error = nil
|
278
|
-
status = response.http_response.status
|
279
|
-
code = nil
|
280
|
-
code = xml_error_grammar.parse(response.http_response.body).code if
|
281
|
-
xml_error_response?(response)
|
282
|
-
|
283
|
-
|
284
|
-
case
|
285
|
-
when response.timeout?
|
286
|
-
response.error = Timeout::Error.new
|
287
|
-
|
288
|
-
when code
|
289
|
-
response.error =
|
290
|
-
service_module::Errors.error_class(code).new(response.http_request,
|
291
|
-
response.http_response)
|
292
|
-
when status >= 500
|
293
|
-
response.error =
|
294
|
-
Errors::ServerError.new(response.http_request, response.http_response)
|
295
|
-
|
296
|
-
when status >= 300
|
297
|
-
response.error =
|
298
|
-
Errors::ClientError.new(response.http_request, response.http_response)
|
299
|
-
end
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
protected
|
304
|
-
def xml_error_response? response
|
305
|
-
response.http_response.status >= 300 and
|
306
|
-
response.http_response.body and
|
307
|
-
xml_error_grammar.parse(response.http_response.body).respond_to?(:code)
|
308
|
-
end
|
309
|
-
|
310
|
-
protected
|
311
|
-
def xml_error_grammar
|
312
|
-
if service_module::const_defined?(:Errors) and
|
313
|
-
service_module::Errors::const_defined?(:BASE_ERROR_GRAMMAR)
|
314
|
-
service_module::Errors::BASE_ERROR_GRAMMAR
|
315
|
-
else
|
316
|
-
XmlGrammar
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
protected
|
321
|
-
def service_module
|
322
|
-
AWS.const_get(self.class.to_s[/(\w+)::Client/, 1])
|
323
|
-
end
|
324
|
-
|
325
|
-
private
|
326
|
-
def client_request name, options, &block
|
327
|
-
return_or_raise(options) do
|
328
|
-
log_client_request(name, options) do
|
329
|
-
|
330
|
-
if config.stub_requests?
|
331
|
-
|
332
|
-
response = stub_for(name)
|
333
|
-
response.http_request = build_request(name, options, &block)
|
334
|
-
response.request_options = options
|
335
|
-
response
|
336
|
-
|
337
|
-
else
|
338
|
-
|
339
|
-
client = self
|
340
|
-
response = new_response { client.send(:build_request, name, options, &block) }
|
341
|
-
response.request_type = name
|
342
|
-
response.request_options = options
|
343
|
-
|
344
|
-
if self.class::CACHEABLE_REQUESTS.include?(name) and
|
345
|
-
cache = AWS.response_cache and
|
346
|
-
cached_response = cache.cached(response)
|
347
|
-
cached_response.cached = true
|
348
|
-
cached_response
|
349
|
-
else
|
350
|
-
# process the http request
|
351
|
-
options[:async] ?
|
352
|
-
make_async_request(response) :
|
353
|
-
make_sync_request(response)
|
354
|
-
|
355
|
-
# process the http response
|
356
|
-
response.on_success do
|
357
|
-
send("process_#{name}_response", response)
|
358
|
-
if cache = AWS.response_cache
|
359
|
-
cache.add(response)
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
response
|
364
|
-
|
365
|
-
end
|
366
|
-
|
367
|
-
end
|
368
|
-
|
369
|
-
end
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
private
|
374
|
-
def build_request(name, options, &block)
|
375
|
-
# we dont want to pass the async option to the configure block
|
376
|
-
opts = options.dup
|
377
|
-
opts.delete(:async)
|
378
|
-
|
379
|
-
http_request = new_request
|
380
|
-
|
381
|
-
# configure the http request
|
382
|
-
http_request.host = endpoint
|
383
|
-
http_request.proxy_uri = config.proxy_uri
|
384
|
-
http_request.use_ssl = config.use_ssl?
|
385
|
-
http_request.ssl_verify_peer = config.ssl_verify_peer?
|
386
|
-
http_request.ssl_ca_file = config.ssl_ca_file
|
387
|
-
|
388
|
-
send("configure_#{name}_request", http_request, opts, &block)
|
389
|
-
http_request.headers["user-agent"] = user_agent_string
|
390
|
-
http_request.add_authorization!(signer)
|
391
|
-
http_request
|
392
|
-
end
|
393
|
-
|
394
|
-
private
|
395
|
-
def user_agent_string
|
396
|
-
engine = (RUBY_ENGINE rescue nil or "ruby")
|
397
|
-
user_agent = "%s aws-sdk-ruby/#{VERSION} %s/%s %s" %
|
398
|
-
[config.user_agent_prefix, engine, RUBY_VERSION, RUBY_PLATFORM]
|
399
|
-
user_agent.strip!
|
400
|
-
if AWS.memoizing?
|
401
|
-
user_agent << " memoizing"
|
402
|
-
end
|
403
|
-
user_agent
|
404
|
-
end
|
405
|
-
|
406
|
-
private
|
407
|
-
def self.add_client_request_method method_name, options = {}, &block
|
408
|
-
|
409
|
-
method = ClientRequestMethodBuilder.new(self, method_name, &block)
|
410
|
-
|
411
|
-
if xml_grammar = options[:xml_grammar]
|
412
|
-
|
413
|
-
method.process_response do |resp|
|
414
|
-
xml_grammar.parse(resp.http_response.body, :context => resp)
|
415
|
-
super(resp)
|
416
|
-
end
|
417
|
-
|
418
|
-
method.simulate_response do |resp|
|
419
|
-
xml_grammar.simulate(resp)
|
420
|
-
super(resp)
|
421
|
-
end
|
422
|
-
|
423
|
-
end
|
424
|
-
|
425
|
-
module_eval <<-END
|
426
|
-
def #{method_name}(*args, &block)
|
427
|
-
options = args.first ? args.first : {}
|
428
|
-
client_request(#{method_name.inspect}, options, &block)
|
429
|
-
end
|
430
|
-
END
|
431
|
-
|
432
|
-
end
|
433
|
-
|
434
|
-
protected
|
435
|
-
def self.configure_client
|
436
|
-
|
437
|
-
module_eval('module Options; end')
|
438
|
-
module_eval('module XML; end')
|
439
|
-
|
440
|
-
name = :"#{service_ruby_name}_client"
|
441
|
-
needs = [:signer, :http_handler, "#{service_ruby_name}_endpoint"]
|
442
|
-
create_block = lambda {|config| new(:config => config) }
|
443
|
-
|
444
|
-
Configuration.add_option_with_needs(name, needs, &create_block)
|
445
|
-
|
446
|
-
end
|
447
|
-
|
448
|
-
# @private
|
449
|
-
class ClientRequestMethodBuilder
|
450
|
-
|
451
|
-
def initialize client_class, method_name, &block
|
452
|
-
@client_class = client_class
|
453
|
-
@method_name = method_name
|
454
|
-
configure_request {|request, options|}
|
455
|
-
process_response {|response|}
|
456
|
-
simulate_response {|response|}
|
457
|
-
instance_eval(&block)
|
458
|
-
end
|
459
|
-
|
460
|
-
def configure_request options = {}, &block
|
461
|
-
name = "configure_#{@method_name}_request"
|
462
|
-
MetaUtils.class_extend_method(@client_class, name, &block)
|
463
|
-
|
464
|
-
if block.arity == 3
|
465
|
-
m = Module.new
|
466
|
-
m.module_eval(<<-END)
|
467
|
-
def #{name}(req, options, &block)
|
468
|
-
super(req, options, block)
|
469
|
-
end
|
470
|
-
END
|
471
|
-
@client_class.send(:include, m)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
def process_response &block
|
476
|
-
name = "process_#{@method_name}_response"
|
477
|
-
MetaUtils.class_extend_method(@client_class, name, &block)
|
478
|
-
end
|
479
|
-
|
480
|
-
def simulate_response &block
|
481
|
-
name = "simulate_#{@method_name}_response"
|
482
|
-
MetaUtils.class_extend_method(@client_class, name, &block)
|
483
|
-
end
|
484
|
-
|
485
|
-
end
|
486
|
-
|
487
|
-
end
|
488
|
-
end
|