aws-sdk 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/lib/aws.rb +10 -9
  2. data/lib/aws/api_config/IAM-2010-07-15.yml +632 -0
  3. data/lib/aws/base_client.rb +1 -1
  4. data/lib/aws/cacheable.rb +34 -46
  5. data/lib/aws/client_logging.rb +19 -14
  6. data/lib/aws/collections.rb +230 -0
  7. data/lib/aws/common.rb +4 -0
  8. data/lib/aws/configuration.rb +7 -0
  9. data/lib/aws/ec2.rb +2 -2
  10. data/lib/aws/ec2/attachment.rb +64 -71
  11. data/lib/aws/ec2/attachment_collection.rb +11 -9
  12. data/lib/aws/ec2/availability_zone.rb +40 -31
  13. data/lib/aws/ec2/availability_zone_collection.rb +2 -3
  14. data/lib/aws/ec2/elastic_ip.rb +25 -22
  15. data/lib/aws/ec2/elastic_ip_collection.rb +5 -2
  16. data/lib/aws/ec2/image.rb +113 -129
  17. data/lib/aws/ec2/image_collection.rb +5 -6
  18. data/lib/aws/ec2/instance.rb +290 -233
  19. data/lib/aws/ec2/instance_collection.rb +72 -67
  20. data/lib/aws/ec2/key_pair.rb +16 -18
  21. data/lib/aws/ec2/region.rb +25 -17
  22. data/lib/aws/ec2/reserved_instances.rb +7 -1
  23. data/lib/aws/ec2/reserved_instances_collection.rb +3 -3
  24. data/lib/aws/ec2/reserved_instances_offering.rb +7 -1
  25. data/lib/aws/ec2/reserved_instances_offering_collection.rb +3 -3
  26. data/lib/aws/ec2/resource.rb +41 -222
  27. data/lib/aws/ec2/security_group.rb +22 -18
  28. data/lib/aws/ec2/security_group_collection.rb +2 -5
  29. data/lib/aws/ec2/snapshot.rb +44 -35
  30. data/lib/aws/ec2/snapshot_collection.rb +43 -1
  31. data/lib/aws/ec2/tag.rb +14 -18
  32. data/lib/aws/ec2/volume.rb +59 -72
  33. data/lib/aws/ec2/volume_collection.rb +16 -12
  34. data/lib/aws/errors.rb +14 -5
  35. data/lib/aws/http/httparty_handler.rb +2 -2
  36. data/lib/aws/iam.rb +306 -0
  37. data/lib/aws/iam/access_key.rb +183 -0
  38. data/lib/aws/iam/access_key_collection.rb +131 -0
  39. data/lib/aws/iam/account_alias_collection.rb +81 -0
  40. data/lib/aws/iam/client.rb +44 -0
  41. data/lib/aws/iam/client/xml.rb +38 -0
  42. data/lib/aws/iam/collection.rb +87 -0
  43. data/lib/aws/iam/errors.rb +29 -0
  44. data/lib/aws/iam/group.rb +117 -0
  45. data/lib/aws/iam/group_collection.rb +135 -0
  46. data/lib/aws/iam/group_policy_collection.rb +49 -0
  47. data/lib/aws/iam/group_user_collection.rb +94 -0
  48. data/lib/aws/iam/login_profile.rb +97 -0
  49. data/lib/aws/iam/mfa_device.rb +52 -0
  50. data/lib/aws/iam/mfa_device_collection.rb +119 -0
  51. data/lib/aws/iam/policy.rb +48 -0
  52. data/lib/aws/iam/policy_collection.rb +191 -0
  53. data/lib/aws/iam/request.rb +27 -0
  54. data/lib/aws/iam/resource.rb +74 -0
  55. data/lib/aws/iam/server_certificate.rb +143 -0
  56. data/lib/aws/iam/server_certificate_collection.rb +174 -0
  57. data/lib/aws/iam/signing_certificate.rb +171 -0
  58. data/lib/aws/iam/signing_certificate_collection.rb +134 -0
  59. data/lib/aws/iam/user.rb +196 -0
  60. data/lib/aws/iam/user_collection.rb +136 -0
  61. data/lib/aws/iam/user_group_collection.rb +101 -0
  62. data/lib/aws/iam/user_policy.rb +90 -0
  63. data/lib/aws/iam/user_policy_collection.rb +48 -0
  64. data/lib/aws/resource.rb +381 -0
  65. data/lib/aws/resource_cache.rb +1 -2
  66. data/lib/aws/response.rb +5 -1
  67. data/lib/aws/response_cache.rb +1 -1
  68. data/lib/aws/s3/client.rb +3 -1
  69. data/lib/aws/s3/presigned_post.rb +1 -1
  70. data/lib/aws/simple_db.rb +1 -1
  71. metadata +113 -50
@@ -396,7 +396,7 @@ module AWS
396
396
  private
397
397
  def user_agent_string
398
398
  engine = (RUBY_ENGINE rescue nil or "ruby")
399
- user_agent = "%s aws-sdk-ruby/1.0 %s/%s %s" %
399
+ user_agent = "%s aws-sdk-ruby/#{VERSION} %s/%s %s" %
400
400
  [config.user_agent_prefix, engine, RUBY_VERSION, RUBY_PLATFORM]
401
401
  user_agent.strip!
402
402
  if AWS.memoizing?
@@ -12,78 +12,66 @@
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
14
  require 'aws/naming'
15
- require 'aws/meta_utils'
16
15
 
17
16
  module AWS
18
17
 
19
18
  # @private
20
19
  module Cacheable
21
20
 
21
+ # @private
22
+ class NoData < StandardError; end
23
+
24
+ def self.included base
25
+ base.extend Naming unless base.respond_to?(:service_ruby_name)
26
+ end
27
+
28
+ # @private
29
+ protected
22
30
  def local_cache_key
23
31
  raise NotImplementedError
24
32
  end
25
33
 
34
+ # @private
35
+ protected
26
36
  def cache_key
27
- endpoint_method = self.class.service_ruby_name + "_endpoint"
28
- config.signer.access_key_id + ":" +
29
- config.send(endpoint_method) + ":" +
30
- local_cache_key
31
- end
32
-
33
- def attributes_from_response(response)
34
- method = "populate_from_#{response.request_type}"
35
- if respond_to?(method)
36
- send(method, response)
37
+ @cache_key ||= begin
38
+ endpoint_method = self.class.service_ruby_name + "_endpoint"
39
+ config.signer.access_key_id + ":" +
40
+ config.send(endpoint_method) + ":" +
41
+ self.class.name + ":" +
42
+ local_cache_key
37
43
  end
38
44
  end
39
45
 
40
- def request_types
41
- self.class.request_types
42
- end
43
-
44
- class NoData < StandardError; end
46
+ # @private
47
+ public
48
+ def retrieve_attribute attr, &block
45
49
 
46
- def retrieve_attribute(attribute)
47
50
  if cache = AWS.response_cache
48
- if cache.resource_cache.cached?(cache_key, attribute)
49
- return cache.resource_cache.get(cache_key, attribute)
51
+
52
+ if cache.resource_cache.cached?(cache_key, attr.name)
53
+ return cache.resource_cache.get(cache_key, attr.name)
50
54
  end
51
- cache.select(*request_types).each do |resp|
52
- if attributes = attributes_from_response(resp)
55
+
56
+ cache.select(*attr.request_types).each do |response|
57
+ if attributes = attributes_from_response(response)
53
58
  cache.resource_cache.store(cache_key, attributes)
54
- return attributes[attribute] if attributes.key?(attribute)
59
+ return attributes[attr.name] if attributes.key?(attr.name)
55
60
  end
56
61
  end
62
+
57
63
  end
58
- resp = yield
59
- if attributes = attributes_from_response(resp)
64
+
65
+ response = yield
66
+
67
+ if attributes = attributes_from_response(response)
60
68
  if cache = AWS.response_cache
61
69
  cache.resource_cache.store(cache_key, attributes)
62
70
  end
63
- attributes[attribute] if attributes.key?(attribute)
71
+ attributes[attr.name] if attributes.key?(attr.name)
64
72
  else
65
- raise NoData.new("no data for #{self} in response to #{resp.request_type}")
66
- end
67
- end
68
-
69
- module ClassMethods
70
-
71
- def request_types
72
- []
73
+ raise NoData.new("no data in #{response.request_type} response")
73
74
  end
74
-
75
- def populate_from(type, &block)
76
- define_method("populate_from_#{type}", &block)
77
- new_request_types = request_types + [type]
78
- new_request_types.uniq!
79
- MetaUtils.extend_method(self, :request_types) { new_request_types }
80
- end
81
-
82
- end
83
-
84
- def self.included mod
85
- mod.extend ClassMethods
86
- mod.extend Naming unless mod.respond_to?(:service_ruby_name)
87
75
  end
88
76
 
89
77
  end
@@ -50,7 +50,7 @@ module AWS
50
50
  status = response.http_response.status
51
51
  service = self.class.service_name
52
52
 
53
- pattern = "[AWS %s %s %.06f] %s %s"
53
+ pattern = "[AWS %s %s %.06f] %s(%s)"
54
54
  parts = [service, status, time.real, method_name, sanitize_options(options)]
55
55
  severity = :info
56
56
 
@@ -72,7 +72,7 @@ module AWS
72
72
  def sanitize_value(value)
73
73
  case value
74
74
  when Hash
75
- sanitize_hash(value)
75
+ '{' + sanitize_hash(value) + '}'
76
76
  when Array
77
77
  sanitize_array(value)
78
78
  when File
@@ -85,31 +85,36 @@ module AWS
85
85
  end
86
86
 
87
87
  protected
88
- def sanitize_string(str)
89
- if str.size > MAX_STRING_LENGTH
90
- "#<String \"#{str[0,6]}\" ... \"#{str[-6,6]}\" (#{str.size} characters)>"
88
+ def sanitize_string str
89
+ summary = summarize_string(str)
90
+ inspected = str.inspect
91
+ if inspected.size > summary.size
92
+ summary
91
93
  else
92
- str.inspect
94
+ inspected
93
95
  end
94
96
  end
95
97
 
96
98
  protected
97
- def sanitize_file(file)
99
+ def summarize_string str
100
+ "#<String #{str[0,6].inspect} ... #{str[-6,6].inspect} (#{str.size} characters)>"
101
+ end
102
+
103
+ protected
104
+ def sanitize_file file
98
105
  "#<File:#{file.path} (#{File.size(file.path)} bytes)>"
99
106
  end
100
107
 
101
108
  protected
102
- def sanitize_array(ary)
103
- "[" +
104
- ary.map { |v| sanitize_value(v) }.join(",") +
105
- "]"
109
+ def sanitize_array array
110
+ "[" + array.map { |v| sanitize_value(v) }.join(",") + "]"
106
111
  end
107
112
 
108
113
  protected
109
- def sanitize_hash(hash)
110
- "{" + hash.map do |k,v|
114
+ def sanitize_hash hash
115
+ hash.map do |k,v|
111
116
  "#{sanitize_value(k)}=>#{sanitize_value(v)}"
112
- end.sort.join(",") + "}"
117
+ end.sort.join(",")
113
118
  end
114
119
 
115
120
  end
@@ -0,0 +1,230 @@
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/model'
14
+
15
+ module AWS
16
+
17
+
18
+ # There are 3 collection modules:
19
+ #
20
+ # AWS::Collections::Basic
21
+ # - single request returns all items
22
+ # - (sqs, ec2, ses)
23
+ #
24
+ # AWS::Collections::Paged
25
+ # - responses may be truncated
26
+ # - truncated responses return a "next token"
27
+ # - (sns, sdb)
28
+ #
29
+ # AWS::Collections::PagedWithLimits
30
+ # - requests accept a "max items"
31
+ # - responses may be "truncated"
32
+ # - truncated responses return a "next token"
33
+ # - (s3, iam)
34
+ #
35
+ # @private
36
+ module Collections
37
+
38
+ # @private
39
+ module Basic
40
+
41
+ include Model
42
+ include Enumerable
43
+
44
+ def enumerator options = {}
45
+ Enumerator.new(self, :each, options)
46
+ end
47
+
48
+ def each options = {}, &block
49
+ each_batch(options) do |batch|
50
+ batch.each(&block)
51
+ end
52
+ nil
53
+ end
54
+
55
+ def each_batch options = {}, &block
56
+
57
+ options = options.dup
58
+
59
+ limit = options.delete(:limit)
60
+ batch_size = options.delete(:batch_size)
61
+
62
+ total = 0 # count of items yeileded across all batches
63
+
64
+ each_response(options, limit, batch_size) do |response|
65
+
66
+ batch = []
67
+ each_item(response) do |item|
68
+ batch << item
69
+ if limit and (total += 1) == limit
70
+ yield(batch)
71
+ return
72
+ end
73
+ end
74
+
75
+ yield(batch)
76
+
77
+ batch.size
78
+
79
+ end
80
+
81
+ nil
82
+
83
+ end
84
+
85
+ def in_groups_of size, options = {}, &block
86
+
87
+ group = []
88
+
89
+ each_batch(options) do |batch|
90
+ batch.each do |item|
91
+ group << item
92
+ if group.size == size
93
+ yield(group)
94
+ group = []
95
+ end
96
+ end
97
+ end
98
+
99
+ yield(group) unless group.empty?
100
+
101
+ nil
102
+
103
+ end
104
+
105
+ # @note +limit+ has no effect, simply ignored
106
+ # @note +batch_size+ has no effect, simply ignored
107
+ # @private
108
+ protected
109
+ def each_response options, limit, batch_size, &block
110
+ response = client.send(request_method, options)
111
+ yield(response)
112
+ end
113
+
114
+ # @note Define this method in classes including this module.
115
+ # @private
116
+ protected
117
+ def request_method
118
+ raise NotImplementedError
119
+ end
120
+
121
+ # @note Define this method in classes including this module.
122
+ # @private
123
+ protected
124
+ def each_item response
125
+ raise NotImplementedError
126
+ end
127
+
128
+ end
129
+
130
+ # @private
131
+ module Paged
132
+
133
+ include Basic
134
+
135
+ # @note +limit+ has no effect, simply ignored
136
+ # @note +batch_size+ has no effect, simply ignored
137
+ protected
138
+ def each_response options, limit, batch_size, &block
139
+
140
+ next_token = nil
141
+
142
+ begin
143
+
144
+ page_opts = {}
145
+ page_opts[next_token_key] = next_token if next_token
146
+
147
+ response = client.send(request_method, options.merge(page_opts))
148
+
149
+ yield(response)
150
+
151
+ next_token = next_token_for(response)
152
+
153
+ end until next_token.nil?
154
+
155
+ end
156
+
157
+ # Override this methid in collections that use a different name
158
+ # for the param that offsets the find (e.g. :marker, :next_key, etc).
159
+ # @private
160
+ protected
161
+ def next_token_key
162
+ raise NotImplementedError
163
+ end
164
+
165
+ # Override this method in collections that have an alternate method
166
+ # for finding the next token.
167
+ # @private
168
+ protected
169
+ def next_token_for response
170
+ method = next_token_key
171
+ response.respond_to?(method) ? response.send(method) : nil
172
+ end
173
+
174
+ end
175
+
176
+ # @private
177
+ module PagedWithLimits
178
+
179
+ include Paged
180
+
181
+ # A custom first method makes getting exactly one item much more
182
+ # efficient. Without the :limit => 1, an entire page of items
183
+ # is received and then only one is grabbed.
184
+ # @private
185
+ def first
186
+ enumerator(:limit => 1).first
187
+ end
188
+
189
+ # @private
190
+ protected
191
+ def each_response options, limit, batch_size, &block
192
+
193
+ total = 0
194
+ next_token = nil
195
+
196
+ begin
197
+
198
+ page_opts = {}
199
+
200
+ page_opts[next_token_key] = next_token if next_token
201
+
202
+ if limit or batch_size
203
+ max_items = []
204
+ max_items << (limit - total) if limit
205
+ max_items << batch_size if batch_size
206
+ page_opts[limit_key] = max_items.min
207
+ end
208
+
209
+ response = client.send(request_method, options.merge(page_opts))
210
+
211
+ total += yield(response)
212
+
213
+ next_token = next_token_for(response)
214
+
215
+ end until next_token.nil? or (limit and limit == total)
216
+
217
+ end
218
+
219
+ # Override this methid in collections that use a different name
220
+ # for the param that offsets the find (e.g. :marker, :next_key, etc).
221
+ # @private
222
+ protected
223
+ def limit_key
224
+ raise NotImplementedError
225
+ end
226
+
227
+ end
228
+
229
+ end
230
+ end
@@ -17,6 +17,10 @@ require 'aws/response_cache'
17
17
 
18
18
  # Root namespace for the AWS SDK for Ruby.
19
19
  module AWS
20
+
21
+ # Current version of the AWS SDK for Ruby
22
+ VERSION = "1.1.0"
23
+
20
24
  class << self
21
25
 
22
26
  # @private
@@ -72,6 +72,7 @@ module AWS
72
72
  :ec2_endpoint => 'ec2.amazonaws.com',
73
73
  :http_handler => Http::HTTPartyHandler.new,
74
74
  :max_retries => 3,
75
+ :iam_endpoint => 'iam.amazonaws.com',
75
76
  :s3_endpoint => 's3.amazonaws.com',
76
77
  :s3_multipart_threshold => 16 * 1024 * 1024,
77
78
  :s3_multipart_min_part_size => 5 * 1024 * 1024,
@@ -163,6 +164,12 @@ module AWS
163
164
  @options[:max_retries]
164
165
  end
165
166
 
167
+ # @return [String] The service endpoint for AWS Idenity Access
168
+ # Management (IAM).
169
+ def iam_endpoint
170
+ @options[:iam_endpoint]
171
+ end
172
+
166
173
  # @return [String] The service endpoint for Amazon S3.
167
174
  def s3_endpoint
168
175
  @options[:s3_endpoint]