aws-sdk 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws.rb +10 -9
- data/lib/aws/api_config/IAM-2010-07-15.yml +632 -0
- data/lib/aws/base_client.rb +1 -1
- data/lib/aws/cacheable.rb +34 -46
- data/lib/aws/client_logging.rb +19 -14
- data/lib/aws/collections.rb +230 -0
- data/lib/aws/common.rb +4 -0
- data/lib/aws/configuration.rb +7 -0
- data/lib/aws/ec2.rb +2 -2
- data/lib/aws/ec2/attachment.rb +64 -71
- data/lib/aws/ec2/attachment_collection.rb +11 -9
- data/lib/aws/ec2/availability_zone.rb +40 -31
- data/lib/aws/ec2/availability_zone_collection.rb +2 -3
- data/lib/aws/ec2/elastic_ip.rb +25 -22
- data/lib/aws/ec2/elastic_ip_collection.rb +5 -2
- data/lib/aws/ec2/image.rb +113 -129
- data/lib/aws/ec2/image_collection.rb +5 -6
- data/lib/aws/ec2/instance.rb +290 -233
- data/lib/aws/ec2/instance_collection.rb +72 -67
- data/lib/aws/ec2/key_pair.rb +16 -18
- data/lib/aws/ec2/region.rb +25 -17
- data/lib/aws/ec2/reserved_instances.rb +7 -1
- data/lib/aws/ec2/reserved_instances_collection.rb +3 -3
- data/lib/aws/ec2/reserved_instances_offering.rb +7 -1
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +3 -3
- data/lib/aws/ec2/resource.rb +41 -222
- data/lib/aws/ec2/security_group.rb +22 -18
- data/lib/aws/ec2/security_group_collection.rb +2 -5
- data/lib/aws/ec2/snapshot.rb +44 -35
- data/lib/aws/ec2/snapshot_collection.rb +43 -1
- data/lib/aws/ec2/tag.rb +14 -18
- data/lib/aws/ec2/volume.rb +59 -72
- data/lib/aws/ec2/volume_collection.rb +16 -12
- data/lib/aws/errors.rb +14 -5
- data/lib/aws/http/httparty_handler.rb +2 -2
- data/lib/aws/iam.rb +306 -0
- data/lib/aws/iam/access_key.rb +183 -0
- data/lib/aws/iam/access_key_collection.rb +131 -0
- data/lib/aws/iam/account_alias_collection.rb +81 -0
- data/lib/aws/iam/client.rb +44 -0
- data/lib/aws/iam/client/xml.rb +38 -0
- data/lib/aws/iam/collection.rb +87 -0
- data/lib/aws/iam/errors.rb +29 -0
- data/lib/aws/iam/group.rb +117 -0
- data/lib/aws/iam/group_collection.rb +135 -0
- data/lib/aws/iam/group_policy_collection.rb +49 -0
- data/lib/aws/iam/group_user_collection.rb +94 -0
- data/lib/aws/iam/login_profile.rb +97 -0
- data/lib/aws/iam/mfa_device.rb +52 -0
- data/lib/aws/iam/mfa_device_collection.rb +119 -0
- data/lib/aws/iam/policy.rb +48 -0
- data/lib/aws/iam/policy_collection.rb +191 -0
- data/lib/aws/iam/request.rb +27 -0
- data/lib/aws/iam/resource.rb +74 -0
- data/lib/aws/iam/server_certificate.rb +143 -0
- data/lib/aws/iam/server_certificate_collection.rb +174 -0
- data/lib/aws/iam/signing_certificate.rb +171 -0
- data/lib/aws/iam/signing_certificate_collection.rb +134 -0
- data/lib/aws/iam/user.rb +196 -0
- data/lib/aws/iam/user_collection.rb +136 -0
- data/lib/aws/iam/user_group_collection.rb +101 -0
- data/lib/aws/iam/user_policy.rb +90 -0
- data/lib/aws/iam/user_policy_collection.rb +48 -0
- data/lib/aws/resource.rb +381 -0
- data/lib/aws/resource_cache.rb +1 -2
- data/lib/aws/response.rb +5 -1
- data/lib/aws/response_cache.rb +1 -1
- data/lib/aws/s3/client.rb +3 -1
- data/lib/aws/s3/presigned_post.rb +1 -1
- data/lib/aws/simple_db.rb +1 -1
- metadata +113 -50
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
3
|
+
# may not use this file except in compliance with the License. A copy of
|
4
|
+
# the License is located at
|
5
|
+
#
|
6
|
+
# http://aws.amazon.com/apache2.0/
|
7
|
+
#
|
8
|
+
# or in the "license" file accompanying this file. This file is
|
9
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
10
|
+
# ANY KIND, either express or implied. See the License for the specific
|
11
|
+
# language governing permissions and limitations under the License.
|
12
|
+
|
13
|
+
require 'aws/iam/policy_collection'
|
14
|
+
require 'aws/iam/user_policy'
|
15
|
+
|
16
|
+
module AWS
|
17
|
+
class IAM
|
18
|
+
|
19
|
+
# A collection that provides access to the policies associated
|
20
|
+
# with an IAM user. The interface mimics a hash containing
|
21
|
+
# string keys and values that are instances of {Policy}. For
|
22
|
+
# example:
|
23
|
+
#
|
24
|
+
# # add or replace a policy named "ReadOnly"
|
25
|
+
# policy = AWS::IAM::Policy.new do |p|
|
26
|
+
# # ...
|
27
|
+
# end
|
28
|
+
# user.policies["ReadOnly"] = policy
|
29
|
+
# user.policies.has_key?("ReadOnly") # => true
|
30
|
+
#
|
31
|
+
# All of the methods for this class are defined in the
|
32
|
+
# {PolicyCollection} module.
|
33
|
+
class UserPolicyCollection
|
34
|
+
|
35
|
+
include PolicyCollection
|
36
|
+
|
37
|
+
# @param [User] user The user that owns this collection.
|
38
|
+
def initialize user, options = {}
|
39
|
+
@user = user
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [User] Returns the user that this collection belongs to.
|
44
|
+
attr_reader :user
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/aws/resource.rb
ADDED
@@ -0,0 +1,381 @@
|
|
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
|
+
require 'aws/model'
|
16
|
+
require 'aws/cacheable'
|
17
|
+
|
18
|
+
module AWS
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Resource
|
22
|
+
|
23
|
+
include Model
|
24
|
+
include Cacheable
|
25
|
+
|
26
|
+
# @private
|
27
|
+
class NotFound < StandardError; end
|
28
|
+
|
29
|
+
def initialize *args
|
30
|
+
|
31
|
+
super
|
32
|
+
|
33
|
+
# cache static attributes passed into options
|
34
|
+
|
35
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
36
|
+
options.each_pair do |opt_name,opt_value|
|
37
|
+
if
|
38
|
+
self.class.attributes.has_key?(opt_name) and
|
39
|
+
self.class.attributes[opt_name].static?
|
40
|
+
then
|
41
|
+
static_attributes[opt_name] = opt_value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [String] Returns a simple string representation of this resource.
|
48
|
+
def inspect
|
49
|
+
|
50
|
+
identifiers = []
|
51
|
+
resource_identifiers.each do |key, value|
|
52
|
+
if attr = self.class.attributes.values.find{|a| a.get_as == key }
|
53
|
+
identifiers << "#{attr.name}:#{value}"
|
54
|
+
else
|
55
|
+
identifiers << "#{key}:#{value}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
"<#{self::class} #{identifiers.join(' ')}>"
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Boolean] Returns true if the objects references the same
|
64
|
+
# AWS resource.
|
65
|
+
def == other
|
66
|
+
other.kind_of?(self.class) and
|
67
|
+
resource_identifiers == other.resource_identifiers
|
68
|
+
end
|
69
|
+
|
70
|
+
alias_method :eql?, :==
|
71
|
+
|
72
|
+
# @private
|
73
|
+
protected
|
74
|
+
def get_resource attr_name
|
75
|
+
raise NotImplementedError
|
76
|
+
end
|
77
|
+
|
78
|
+
# @private
|
79
|
+
protected
|
80
|
+
def update_resource attr, value
|
81
|
+
raise NotImplementedError
|
82
|
+
end
|
83
|
+
|
84
|
+
# Overide this method is subclasses of Resource. This method should
|
85
|
+
# return an array of identifying key/value pairs.
|
86
|
+
#
|
87
|
+
# # @private
|
88
|
+
# protected
|
89
|
+
# def resource_identifiers
|
90
|
+
# [[:user_name, name]]
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# @private
|
94
|
+
protected
|
95
|
+
def resource_identifiers
|
96
|
+
raise NotImplementedError
|
97
|
+
end
|
98
|
+
|
99
|
+
# @protected
|
100
|
+
protected
|
101
|
+
def resource_options(additional = {})
|
102
|
+
Hash[resource_identifiers].merge(additional)
|
103
|
+
end
|
104
|
+
|
105
|
+
# @private
|
106
|
+
protected
|
107
|
+
def local_cache_key
|
108
|
+
resource_identifiers.collect{|name,value| value.to_s }.join(":")
|
109
|
+
end
|
110
|
+
|
111
|
+
# @private
|
112
|
+
protected
|
113
|
+
def static_attributes
|
114
|
+
@static_attributes ||= {}
|
115
|
+
end
|
116
|
+
|
117
|
+
# @private
|
118
|
+
protected
|
119
|
+
def ruby_name
|
120
|
+
@ruby_name ||= Inflection.ruby_name(self.class.name)
|
121
|
+
end
|
122
|
+
|
123
|
+
# @private
|
124
|
+
public
|
125
|
+
def attributes_from_response resp
|
126
|
+
|
127
|
+
attributes = {}
|
128
|
+
|
129
|
+
self.class.attribute_providers_for(resp.request_type).each do |provider|
|
130
|
+
attributes.merge!(provider.attributes_from_response(self, resp))
|
131
|
+
end
|
132
|
+
|
133
|
+
# cache static attributes
|
134
|
+
attributes.each do |attr_name,value|
|
135
|
+
if self.class.attributes[attr_name].static?
|
136
|
+
static_attributes[attr_name] = value
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
attributes.empty? ? nil : attributes
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# @private
|
145
|
+
protected
|
146
|
+
def cache_static_attributes request_type, resp_obj
|
147
|
+
self.class.attribute_providers_for(request_type).each do |provider|
|
148
|
+
attributes = provider.attributes_from_response_object(resp_obj)
|
149
|
+
attributes.each_pair do |attr_name,value|
|
150
|
+
if self.class.attributes[attr_name].static?
|
151
|
+
static_attributes[attr_name] = value
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
class << self
|
159
|
+
|
160
|
+
# @private
|
161
|
+
def new_from request_type, resp_obj, *args
|
162
|
+
resource = new(*args)
|
163
|
+
resource.send(:cache_static_attributes, request_type, resp_obj)
|
164
|
+
resource
|
165
|
+
end
|
166
|
+
|
167
|
+
# @private
|
168
|
+
def attributes
|
169
|
+
@attributes ||= Hash.new do |hash,attr_name|
|
170
|
+
raise "uknown attribute #{attr_name}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# @private
|
175
|
+
def attribute_providers
|
176
|
+
@attribute_providers ||= []
|
177
|
+
end
|
178
|
+
|
179
|
+
# @private
|
180
|
+
def attribute_providers_for request_type
|
181
|
+
attribute_providers.select do |provider|
|
182
|
+
provider.request_types.include?(request_type)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# @private
|
187
|
+
protected
|
188
|
+
def attribute name, options = {}, &block
|
189
|
+
attr = Attribute.new(name, options)
|
190
|
+
attr.instance_eval(&block) if block_given?
|
191
|
+
define_attribute_getter(attr)
|
192
|
+
define_attribute_setter(attr) if attr.mutable?
|
193
|
+
attributes[attr.name] = attr
|
194
|
+
end
|
195
|
+
|
196
|
+
# @private
|
197
|
+
protected
|
198
|
+
def mutable_attribute name, options = {}, &block
|
199
|
+
attribute(name, options.merge(:mutable => true), &block)
|
200
|
+
end
|
201
|
+
|
202
|
+
# @private
|
203
|
+
protected
|
204
|
+
def define_attribute_getter attribute
|
205
|
+
define_method(attribute.name) do
|
206
|
+
|
207
|
+
return static_attributes[attribute.name] if
|
208
|
+
static_attributes.has_key?(attribute.name)
|
209
|
+
|
210
|
+
begin
|
211
|
+
retrieve_attribute(attribute) { get_resource(attribute) }
|
212
|
+
rescue Cacheable::NoData => e
|
213
|
+
name = ruby_name.tr("_", " ")
|
214
|
+
raise NotFound, "unable to find the #{name}"
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# @private
|
221
|
+
protected
|
222
|
+
def define_attribute_setter attribute
|
223
|
+
setter = attribute.name.to_s.sub(/\?/, '') + '='
|
224
|
+
define_method(setter) do |value|
|
225
|
+
translated_value = attribute.translate_input_value(value)
|
226
|
+
update_resource(attribute, translated_value)
|
227
|
+
if attribute.static?
|
228
|
+
static_attributes[attribute.name] = translated_value
|
229
|
+
end
|
230
|
+
value
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# @private
|
235
|
+
protected
|
236
|
+
def populates_from *request_types, &block
|
237
|
+
provider = provider(*request_types)
|
238
|
+
provider.find(&block)
|
239
|
+
provider.provides(*attributes.keys)
|
240
|
+
provider
|
241
|
+
end
|
242
|
+
|
243
|
+
# @private
|
244
|
+
protected
|
245
|
+
def provider *request_types, &block
|
246
|
+
provider = AttributeProvider.new(self, request_types)
|
247
|
+
if block_given?
|
248
|
+
yield(provider)
|
249
|
+
end
|
250
|
+
attribute_providers << provider
|
251
|
+
provider
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
# @private
|
257
|
+
class Attribute
|
258
|
+
|
259
|
+
def initialize name, options = {}
|
260
|
+
@name = name
|
261
|
+
@options = options
|
262
|
+
@request_types = []
|
263
|
+
end
|
264
|
+
|
265
|
+
attr_reader :name
|
266
|
+
|
267
|
+
attr_reader :request_types
|
268
|
+
|
269
|
+
def get_as
|
270
|
+
@get_as ||= (@options[:get_as] || @options[:as] || name)
|
271
|
+
end
|
272
|
+
|
273
|
+
def set_as
|
274
|
+
@set_as ||= (@options[:set_as] || @options[:as] || name)
|
275
|
+
end
|
276
|
+
|
277
|
+
def mutable?
|
278
|
+
@options[:mutable] == true
|
279
|
+
end
|
280
|
+
|
281
|
+
def static?
|
282
|
+
@options[:static] == true
|
283
|
+
end
|
284
|
+
|
285
|
+
def translates_input &block
|
286
|
+
@input_translator = block
|
287
|
+
end
|
288
|
+
|
289
|
+
def translates_output options = {}, &block
|
290
|
+
@translates_nil = options[:nil]
|
291
|
+
@output_translator = block
|
292
|
+
end
|
293
|
+
|
294
|
+
def translate_input_value value
|
295
|
+
@input_translator ? @input_translator.call(value) : value
|
296
|
+
end
|
297
|
+
|
298
|
+
def translate_output_value value
|
299
|
+
|
300
|
+
# by default nil values are not translated
|
301
|
+
return nil if value.nil? and @translates_nil != true
|
302
|
+
|
303
|
+
case
|
304
|
+
when @options[:to_sym] then value.tr('-','_').downcase.to_sym
|
305
|
+
when @output_translator then @output_translator.call(value)
|
306
|
+
else value
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
|
313
|
+
# @private
|
314
|
+
class AttributeProvider
|
315
|
+
|
316
|
+
def initialize klass, request_types
|
317
|
+
@klass = klass
|
318
|
+
@id = klass.attribute_providers.length
|
319
|
+
@request_types = request_types
|
320
|
+
@provides = {}
|
321
|
+
end
|
322
|
+
|
323
|
+
attr_reader :request_types
|
324
|
+
|
325
|
+
def find &block
|
326
|
+
@klass.send(:define_method, finder_method, &block)
|
327
|
+
end
|
328
|
+
|
329
|
+
def finder_method
|
330
|
+
"find_in_response_#{@id}"
|
331
|
+
end
|
332
|
+
|
333
|
+
# Indicates that all of the the named attributes can be retrieved
|
334
|
+
# from an appropriate response object.
|
335
|
+
#
|
336
|
+
# @param [Symbol] attr_names A list of attributes provided
|
337
|
+
# @param [Hash] options
|
338
|
+
# @option options [Boolean] :value_wrapped (false) If true, then
|
339
|
+
# the value returned by the response object will also receive
|
340
|
+
# the message :value before it is translated and returned.
|
341
|
+
# @option options [Symbol] :get_as Defaults to the method named
|
342
|
+
# by the attribute. This is useful when you have two providers
|
343
|
+
# for the same attribute but their response object name
|
344
|
+
# them differently.
|
345
|
+
def provides *attr_names
|
346
|
+
options = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
|
347
|
+
attr_names.each do |attr_name|
|
348
|
+
attr = @klass.attributes[attr_name]
|
349
|
+
attr.request_types.push(*request_types)
|
350
|
+
@provides[attr_name] = options
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def attributes_from_response resource, response
|
355
|
+
if response_object = resource.send(finder_method, response)
|
356
|
+
attributes_from_response_object(response_object)
|
357
|
+
else
|
358
|
+
{}
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def attributes_from_response_object resp_obj
|
363
|
+
attributes = {}
|
364
|
+
@provides.each do |attr_name, options|
|
365
|
+
|
366
|
+
attr = @klass.attributes[attr_name]
|
367
|
+
method = options[:get_as] || attr.get_as
|
368
|
+
|
369
|
+
v = resp_obj.respond_to?(method) ? resp_obj.send(method) : nil
|
370
|
+
v = v.value if v and options[:value_wrapped]
|
371
|
+
v = attr.translate_output_value(v)
|
372
|
+
|
373
|
+
attributes[attr_name] = v
|
374
|
+
|
375
|
+
end
|
376
|
+
attributes
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
data/lib/aws/resource_cache.rb
CHANGED