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
@@ -0,0 +1,380 @@
|
|
1
|
+
|
2
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
5
|
+
# may not use this file except in compliance with the License. A copy of
|
6
|
+
# the License is located at
|
7
|
+
#
|
8
|
+
# http://aws.amazon.com/apache2.0/
|
9
|
+
#
|
10
|
+
# or in the "license" file accompanying this file. This file is
|
11
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
12
|
+
# ANY KIND, either express or implied. See the License for the specific
|
13
|
+
# language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
module AWS
|
16
|
+
module Core
|
17
|
+
|
18
|
+
# @private
|
19
|
+
class Resource
|
20
|
+
|
21
|
+
include Model
|
22
|
+
include Cacheable
|
23
|
+
|
24
|
+
# @private
|
25
|
+
class NotFound < StandardError; end
|
26
|
+
|
27
|
+
def initialize *args
|
28
|
+
|
29
|
+
super
|
30
|
+
|
31
|
+
# cache static attributes passed into options
|
32
|
+
|
33
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
34
|
+
options.each_pair do |opt_name,opt_value|
|
35
|
+
if
|
36
|
+
self.class.attributes.has_key?(opt_name) and
|
37
|
+
self.class.attributes[opt_name].static?
|
38
|
+
then
|
39
|
+
static_attributes[opt_name] = opt_value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String] Returns a simple string representation of this resource.
|
46
|
+
def inspect
|
47
|
+
|
48
|
+
identifiers = []
|
49
|
+
resource_identifiers.each do |key, value|
|
50
|
+
if attr = self.class.attributes.values.find{|a| a.get_as == key }
|
51
|
+
identifiers << "#{attr.name}:#{value}"
|
52
|
+
else
|
53
|
+
identifiers << "#{key}:#{value}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
"<#{self::class} #{identifiers.join(' ')}>"
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Boolean] Returns true if the objects references the same
|
62
|
+
# AWS resource.
|
63
|
+
def == other
|
64
|
+
other.kind_of?(self.class) and
|
65
|
+
resource_identifiers == other.resource_identifiers
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :eql?, :==
|
69
|
+
|
70
|
+
# @private
|
71
|
+
protected
|
72
|
+
def get_resource attr_name
|
73
|
+
raise NotImplementedError
|
74
|
+
end
|
75
|
+
|
76
|
+
# @private
|
77
|
+
protected
|
78
|
+
def update_resource attr, value
|
79
|
+
raise NotImplementedError
|
80
|
+
end
|
81
|
+
|
82
|
+
# Overide this method is subclasses of Resource. This method should
|
83
|
+
# return an array of identifying key/value pairs.
|
84
|
+
#
|
85
|
+
# # @private
|
86
|
+
# protected
|
87
|
+
# def resource_identifiers
|
88
|
+
# [[:user_name, name]]
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# @private
|
92
|
+
protected
|
93
|
+
def resource_identifiers
|
94
|
+
raise NotImplementedError
|
95
|
+
end
|
96
|
+
|
97
|
+
# @protected
|
98
|
+
protected
|
99
|
+
def resource_options(additional = {})
|
100
|
+
Hash[resource_identifiers].merge(additional)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @private
|
104
|
+
protected
|
105
|
+
def local_cache_key
|
106
|
+
resource_identifiers.collect{|name,value| value.to_s }.join(":")
|
107
|
+
end
|
108
|
+
|
109
|
+
# @private
|
110
|
+
protected
|
111
|
+
def static_attributes
|
112
|
+
@static_attributes ||= {}
|
113
|
+
end
|
114
|
+
|
115
|
+
# @private
|
116
|
+
protected
|
117
|
+
def ruby_name
|
118
|
+
@ruby_name ||= Inflection.ruby_name(self.class.name)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @private
|
122
|
+
public
|
123
|
+
def attributes_from_response resp
|
124
|
+
|
125
|
+
attributes = {}
|
126
|
+
|
127
|
+
self.class.attribute_providers_for(resp.request_type).each do |provider|
|
128
|
+
attributes.merge!(provider.attributes_from_response(self, resp))
|
129
|
+
end
|
130
|
+
|
131
|
+
# cache static attributes
|
132
|
+
attributes.each do |attr_name,value|
|
133
|
+
if self.class.attributes[attr_name].static?
|
134
|
+
static_attributes[attr_name] = value
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
attributes.empty? ? nil : attributes
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
# @private
|
143
|
+
protected
|
144
|
+
def cache_static_attributes request_type, resp_obj
|
145
|
+
self.class.attribute_providers_for(request_type).each do |provider|
|
146
|
+
attributes = provider.attributes_from_response_object(resp_obj)
|
147
|
+
attributes.each_pair do |attr_name,value|
|
148
|
+
if self.class.attributes[attr_name].static?
|
149
|
+
static_attributes[attr_name] = value
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
class << self
|
157
|
+
|
158
|
+
# @private
|
159
|
+
def new_from request_type, resp_obj, *args
|
160
|
+
resource = new(*args)
|
161
|
+
resource.send(:cache_static_attributes, request_type, resp_obj)
|
162
|
+
resource
|
163
|
+
end
|
164
|
+
|
165
|
+
# @private
|
166
|
+
def attributes
|
167
|
+
@attributes ||= Hash.new do |hash,attr_name|
|
168
|
+
raise "uknown attribute #{attr_name}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# @private
|
173
|
+
def attribute_providers
|
174
|
+
@attribute_providers ||= []
|
175
|
+
end
|
176
|
+
|
177
|
+
# @private
|
178
|
+
def attribute_providers_for request_type
|
179
|
+
attribute_providers.select do |provider|
|
180
|
+
provider.request_types.include?(request_type)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# @private
|
185
|
+
protected
|
186
|
+
def attribute name, options = {}, &block
|
187
|
+
attr = Attribute.new(name, options)
|
188
|
+
attr.instance_eval(&block) if block_given?
|
189
|
+
define_attribute_getter(attr)
|
190
|
+
define_attribute_setter(attr) if attr.mutable?
|
191
|
+
attributes[attr.name] = attr
|
192
|
+
end
|
193
|
+
|
194
|
+
# @private
|
195
|
+
protected
|
196
|
+
def mutable_attribute name, options = {}, &block
|
197
|
+
attribute(name, options.merge(:mutable => true), &block)
|
198
|
+
end
|
199
|
+
|
200
|
+
# @private
|
201
|
+
protected
|
202
|
+
def define_attribute_getter attribute
|
203
|
+
define_method(attribute.name) do
|
204
|
+
|
205
|
+
return static_attributes[attribute.name] if
|
206
|
+
static_attributes.has_key?(attribute.name)
|
207
|
+
|
208
|
+
begin
|
209
|
+
retrieve_attribute(attribute) { get_resource(attribute) }
|
210
|
+
rescue Cacheable::NoData => e
|
211
|
+
name = ruby_name.tr("_", " ")
|
212
|
+
raise NotFound, "unable to find the #{name}"
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# @private
|
219
|
+
protected
|
220
|
+
def define_attribute_setter attribute
|
221
|
+
setter = attribute.name.to_s.sub(/\?/, '') + '='
|
222
|
+
define_method(setter) do |value|
|
223
|
+
translated_value = attribute.translate_input_value(value)
|
224
|
+
update_resource(attribute, translated_value)
|
225
|
+
if attribute.static?
|
226
|
+
static_attributes[attribute.name] = translated_value
|
227
|
+
end
|
228
|
+
value
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# @private
|
233
|
+
protected
|
234
|
+
def populates_from *request_types, &block
|
235
|
+
provider = provider(*request_types)
|
236
|
+
provider.find(&block)
|
237
|
+
provider.provides(*attributes.keys)
|
238
|
+
provider
|
239
|
+
end
|
240
|
+
|
241
|
+
# @private
|
242
|
+
protected
|
243
|
+
def provider *request_types, &block
|
244
|
+
provider = AttributeProvider.new(self, request_types)
|
245
|
+
if block_given?
|
246
|
+
yield(provider)
|
247
|
+
end
|
248
|
+
attribute_providers << provider
|
249
|
+
provider
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
# @private
|
255
|
+
class Attribute
|
256
|
+
|
257
|
+
def initialize name, options = {}
|
258
|
+
@name = name
|
259
|
+
@options = options
|
260
|
+
@request_types = []
|
261
|
+
end
|
262
|
+
|
263
|
+
attr_reader :name
|
264
|
+
|
265
|
+
attr_reader :request_types
|
266
|
+
|
267
|
+
def get_as
|
268
|
+
@get_as ||= (@options[:get_as] || @options[:as] || name)
|
269
|
+
end
|
270
|
+
|
271
|
+
def set_as
|
272
|
+
@set_as ||= (@options[:set_as] || @options[:as] || name)
|
273
|
+
end
|
274
|
+
|
275
|
+
def mutable?
|
276
|
+
@options[:mutable] == true
|
277
|
+
end
|
278
|
+
|
279
|
+
def static?
|
280
|
+
@options[:static] == true
|
281
|
+
end
|
282
|
+
|
283
|
+
def translates_input &block
|
284
|
+
@input_translator = block
|
285
|
+
end
|
286
|
+
|
287
|
+
def translates_output options = {}, &block
|
288
|
+
@translates_nil = options[:nil]
|
289
|
+
@output_translator = block
|
290
|
+
end
|
291
|
+
|
292
|
+
def translate_input_value value
|
293
|
+
@input_translator ? @input_translator.call(value) : value
|
294
|
+
end
|
295
|
+
|
296
|
+
def translate_output_value value
|
297
|
+
|
298
|
+
# by default nil values are not translated
|
299
|
+
return nil if value.nil? and @translates_nil != true
|
300
|
+
|
301
|
+
case
|
302
|
+
when @options[:to_sym] then value.tr('-','_').downcase.to_sym
|
303
|
+
when @output_translator then @output_translator.call(value)
|
304
|
+
else value
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
# @private
|
312
|
+
class AttributeProvider
|
313
|
+
|
314
|
+
def initialize klass, request_types
|
315
|
+
@klass = klass
|
316
|
+
@id = klass.attribute_providers.length
|
317
|
+
@request_types = request_types
|
318
|
+
@provides = {}
|
319
|
+
end
|
320
|
+
|
321
|
+
attr_reader :request_types
|
322
|
+
|
323
|
+
def find &block
|
324
|
+
@klass.send(:define_method, finder_method, &block)
|
325
|
+
end
|
326
|
+
|
327
|
+
def finder_method
|
328
|
+
"find_in_response_#{@id}"
|
329
|
+
end
|
330
|
+
|
331
|
+
# Indicates that all of the the named attributes can be retrieved
|
332
|
+
# from an appropriate response object.
|
333
|
+
#
|
334
|
+
# @param [Symbol] attr_names A list of attributes provided
|
335
|
+
# @param [Hash] options
|
336
|
+
# @option options [Boolean] :value_wrapped (false) If true, then
|
337
|
+
# the value returned by the response object will also receive
|
338
|
+
# the message :value before it is translated and returned.
|
339
|
+
# @option options [Symbol] :get_as Defaults to the method named
|
340
|
+
# by the attribute. This is useful when you have two providers
|
341
|
+
# for the same attribute but their response object name
|
342
|
+
# them differently.
|
343
|
+
def provides *attr_names
|
344
|
+
options = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
|
345
|
+
attr_names.each do |attr_name|
|
346
|
+
attr = @klass.attributes[attr_name]
|
347
|
+
attr.request_types.push(*request_types)
|
348
|
+
@provides[attr_name] = options
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def attributes_from_response resource, response
|
353
|
+
if response_object = resource.send(finder_method, response)
|
354
|
+
attributes_from_response_object(response_object)
|
355
|
+
else
|
356
|
+
{}
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
def attributes_from_response_object resp_obj
|
361
|
+
attributes = {}
|
362
|
+
@provides.each do |attr_name, options|
|
363
|
+
|
364
|
+
attr = @klass.attributes[attr_name]
|
365
|
+
method = options[:get_as] || attr.get_as
|
366
|
+
|
367
|
+
v = resp_obj.respond_to?(method) ? resp_obj.send(method) : nil
|
368
|
+
v = v.value if v and options[:value_wrapped]
|
369
|
+
v = attr.translate_output_value(v)
|
370
|
+
|
371
|
+
attributes[attr_name] = v
|
372
|
+
|
373
|
+
end
|
374
|
+
attributes
|
375
|
+
end
|
376
|
+
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
|
17
|
+
# @private
|
18
|
+
class ResourceCache
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@cache = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def store(key, attributes)
|
25
|
+
(@cache[key] ||= {}).merge!(attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cached?(key, attribute)
|
29
|
+
attributes = @cache[key] and attributes.has_key?(attribute)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get(key, attribute)
|
33
|
+
raise "No cached value for attribute :#{attribute} of #{key}" unless
|
34
|
+
cached?(key, attribute)
|
35
|
+
@cache[key][attribute]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,125 @@
|
|
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
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
|
17
|
+
# @private
|
18
|
+
class Response
|
19
|
+
|
20
|
+
include AsyncHandle
|
21
|
+
|
22
|
+
# @return [AWS::Error] Returns nil unless the request failed.
|
23
|
+
# Normally this will be nil unless you are using the Asynchronous
|
24
|
+
# interface.
|
25
|
+
attr_accessor :error
|
26
|
+
|
27
|
+
# @return [Hash] The hash of options passed to the low level request
|
28
|
+
# method that generated this response.
|
29
|
+
attr_accessor :request_options
|
30
|
+
|
31
|
+
# @return [Symbol] The low-level request method that generated
|
32
|
+
# this response
|
33
|
+
attr_accessor :request_type
|
34
|
+
|
35
|
+
# @return [Http::Request] the HTTP request object
|
36
|
+
attr_accessor :http_request
|
37
|
+
|
38
|
+
# @return [Http::Response] the HTTP response object
|
39
|
+
attr_accessor :http_response
|
40
|
+
|
41
|
+
# @return [Boolean] true if the response is cached
|
42
|
+
attr_accessor :cached
|
43
|
+
|
44
|
+
# @param [Http::Request] http_request
|
45
|
+
# @param [Http::Response] http_request
|
46
|
+
def initialize http_request = nil, http_response = nil, &block
|
47
|
+
@http_request = http_request
|
48
|
+
@http_response = http_response
|
49
|
+
@request_builder = block
|
50
|
+
rebuild_request if @request_builder && !http_request
|
51
|
+
end
|
52
|
+
|
53
|
+
# Rebuilds the HTTP request using the block passed to the initializer
|
54
|
+
def rebuild_request
|
55
|
+
@http_request = @request_builder.call
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Boolean] Returns true unless there is a response error.
|
59
|
+
def successful?
|
60
|
+
error.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Boolean] Returns true if the http request was throttled
|
64
|
+
# by AWS.
|
65
|
+
def throttled?
|
66
|
+
!successful? and
|
67
|
+
http_response.body and
|
68
|
+
parsed_body = XmlGrammar.parse(http_response.body) and
|
69
|
+
parsed_body.respond_to?(:code) and
|
70
|
+
parsed_body.code == "Throttling"
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Boolean] Returns true if the http request timed out.
|
74
|
+
def timeout?
|
75
|
+
http_response.timeout?
|
76
|
+
end
|
77
|
+
|
78
|
+
# @private
|
79
|
+
def inspect
|
80
|
+
if request_type
|
81
|
+
"<#{self.class}:#{request_type}>"
|
82
|
+
else
|
83
|
+
"<#{self.class}>"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def cache_key
|
88
|
+
[http_request.access_key_id,
|
89
|
+
http_request.host,
|
90
|
+
request_type,
|
91
|
+
serialized_options].join(":")
|
92
|
+
end
|
93
|
+
|
94
|
+
def serialized_options
|
95
|
+
serialize_options_hash(request_options)
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
def serialize_options_hash(hash)
|
100
|
+
"(" + hash.keys.sort_by(&:to_s).map do |key|
|
101
|
+
"#{key}=#{serialize_options_value(hash[key])}"
|
102
|
+
end.join(" ") + ")"
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
def serialize_options_value(value)
|
107
|
+
case value
|
108
|
+
when Hash
|
109
|
+
serialize_options_hash(value)
|
110
|
+
when Array
|
111
|
+
serialize_options_array(value)
|
112
|
+
else
|
113
|
+
value.inspect
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
def serialize_options_array(ary)
|
119
|
+
"[" + ary.map { |v| serialize_options_value(v) }.join(" ") +
|
120
|
+
"]"
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|