aws-sdk 1.1.4 → 1.2.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 +2 -0
- data/lib/aws/api_config/ELB-2011-08-15.yml +380 -0
- data/lib/aws/api_config/SNS-2010-03-31.yml +2 -2
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +5 -5
- data/lib/aws/core.rb +18 -3
- data/lib/aws/core/client_logging.rb +5 -6
- data/lib/aws/core/collection.rb +241 -0
- data/lib/aws/core/collection/batchable.rb +133 -0
- data/lib/aws/core/collection/limitable.rb +92 -0
- data/lib/aws/core/collection/simple.rb +89 -0
- data/lib/aws/core/configuration.rb +23 -0
- data/lib/aws/core/option_grammar.rb +2 -0
- data/lib/aws/core/page_result.rb +73 -0
- data/lib/aws/ec2/security_group.rb +154 -89
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +1 -2
- data/lib/aws/ec2/security_group/{ip_permission_collection.rb → ingress_ip_permission_collection.rb} +4 -1
- data/lib/aws/ec2/security_group/ip_permission.rb +23 -45
- data/lib/aws/elb.rb +65 -0
- data/lib/aws/elb/availability_zone_collection.rb +138 -0
- data/lib/aws/elb/backend_server_policy_collection.rb +150 -0
- data/lib/aws/elb/client.rb +35 -0
- data/lib/aws/elb/client/xml.rb +33 -0
- data/lib/aws/elb/config.rb +18 -0
- data/lib/aws/elb/errors.rb +30 -0
- data/lib/aws/elb/instance_collection.rb +174 -0
- data/lib/aws/elb/listener.rb +189 -0
- data/lib/aws/elb/listener_collection.rb +119 -0
- data/lib/aws/elb/listener_opts.rb +45 -0
- data/lib/aws/elb/listener_spec.rb +14 -0
- data/lib/aws/elb/load_balancer.rb +255 -0
- data/lib/aws/elb/load_balancer_collection.rb +113 -0
- data/lib/aws/elb/load_balancer_policy.rb +93 -0
- data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
- data/lib/aws/elb/request.rb +23 -0
- data/lib/aws/iam/collection.rb +24 -26
- data/lib/aws/iam/group_user_collection.rb +21 -28
- data/lib/aws/iam/server_certificate_collection.rb +1 -37
- data/lib/aws/record.rb +1 -1
- data/lib/aws/record/base.rb +14 -1
- data/lib/aws/record/finder_methods.rb +4 -1
- data/lib/aws/record/validations.rb +73 -32
- data/lib/aws/{core/api_config_transform.rb → record/validators/method.rb} +9 -12
- data/lib/aws/s3/bucket_collection.rb +6 -4
- data/lib/aws/s3/client.rb +37 -6
- data/lib/aws/s3/config.rb +3 -1
- data/lib/aws/s3/prefixed_collection.rb +1 -2
- data/lib/aws/s3/presigned_post.rb +37 -4
- data/lib/aws/s3/s3_object.rb +93 -1
- data/lib/aws/simple_db/domain.rb +8 -0
- data/lib/aws/simple_db/item.rb +15 -0
- data/lib/aws/simple_db/item_collection.rb +255 -201
- data/lib/aws/simple_db/item_data.rb +1 -1
- data/lib/aws/simple_email_service/client.rb +0 -1
- data/lib/aws/sns/client.rb +0 -1
- metadata +107 -55
- data/lib/aws/core/collections.rb +0 -229
- data/lib/aws/simple_email_service/client/options.rb +0 -21
- data/lib/aws/sns/client/options.rb +0 -21
@@ -19,8 +19,6 @@ module AWS
|
|
19
19
|
# @private
|
20
20
|
module ClientLogging
|
21
21
|
|
22
|
-
MAX_STRING_LENGTH = 50
|
23
|
-
|
24
22
|
def log_client_request(name, options)
|
25
23
|
response = nil
|
26
24
|
time = Benchmark.measure do
|
@@ -89,10 +87,9 @@ module AWS
|
|
89
87
|
|
90
88
|
protected
|
91
89
|
def sanitize_string str
|
92
|
-
summary = summarize_string(str)
|
93
90
|
inspected = str.inspect
|
94
|
-
if inspected.size >
|
95
|
-
|
91
|
+
if inspected.size > config.logger_truncate_strings_at
|
92
|
+
summarize_string(str)
|
96
93
|
else
|
97
94
|
inspected
|
98
95
|
end
|
@@ -100,7 +97,9 @@ module AWS
|
|
100
97
|
|
101
98
|
protected
|
102
99
|
def summarize_string str
|
103
|
-
|
100
|
+
# skip the openning "
|
101
|
+
string_start = str.inspect[1,config.logger_truncate_strings_at]
|
102
|
+
"#<String \"#{string_start}\" ... (#{str.size} characters)>"
|
104
103
|
end
|
105
104
|
|
106
105
|
protected
|
@@ -0,0 +1,241 @@
|
|
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
|
+
module AWS
|
14
|
+
module Core
|
15
|
+
|
16
|
+
# = Different Collection Types in AWS
|
17
|
+
#
|
18
|
+
# The Collection module acts as a namespace and base implementation for
|
19
|
+
# the primary collection types in AWS:
|
20
|
+
#
|
21
|
+
# * {AWS::Core::Collection::Simple}
|
22
|
+
# * {AWS::Core::Collection::Limitable}
|
23
|
+
#
|
24
|
+
# Each AWS service allows provides a method to enumerate resources.
|
25
|
+
#
|
26
|
+
# * Services that return all results in a single response use
|
27
|
+
# {AWS::Core::Collection::Simple}.
|
28
|
+
#
|
29
|
+
# * Services that truncate large results sets *AND* allow you to provide
|
30
|
+
# a perfered maximum number of results use
|
31
|
+
# {AWS::Core::Collection::Limitable}.
|
32
|
+
#
|
33
|
+
module Collection
|
34
|
+
|
35
|
+
AWS.register_autoloads(self) do
|
36
|
+
autoload :Simple, 'simple'
|
37
|
+
autoload :Limitable, 'limitable'
|
38
|
+
end
|
39
|
+
|
40
|
+
include Enumerable
|
41
|
+
|
42
|
+
# Yields once for every item in this collection.
|
43
|
+
#
|
44
|
+
# collection.each {|item| ... }
|
45
|
+
#
|
46
|
+
# @note If you want fewer than all items, it is generally better
|
47
|
+
# to call #{page} than {#each} with a +:limit+.
|
48
|
+
#
|
49
|
+
# @param [Hash] options
|
50
|
+
#
|
51
|
+
# @option options [Integer] :limit (nil) The maximum number of
|
52
|
+
# items to enumerate from this collection.
|
53
|
+
#
|
54
|
+
# @option options [next_token] :next_token (nil) Next tokens
|
55
|
+
# act as offsets into the collection. Next tokens vary in
|
56
|
+
# format from one service to the next, (e.g. may be a number,
|
57
|
+
# an opaque string, a hash of values, etc).
|
58
|
+
#
|
59
|
+
# {#each} and {#each_batch} return a +:next_token+ when called
|
60
|
+
# with +:limit+ and there were more items matching the request.
|
61
|
+
#
|
62
|
+
# *NOTE* It is generally better to call {#page} if you only
|
63
|
+
# want a few items with the ability to request more later.
|
64
|
+
#
|
65
|
+
# @return [nil_or_next_token] Returns nil if all items were enumerated.
|
66
|
+
# If some items were excluded because of a +:limit+ option then
|
67
|
+
# a +next_token+ is returned. Calling an enumerable method on
|
68
|
+
# the same collection with the +next_token+ acts like an offset.
|
69
|
+
#
|
70
|
+
def each options = {}, &block
|
71
|
+
each_batch(options) do |batch|
|
72
|
+
batch.each(&block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Yields items from this collection in batches.
|
77
|
+
#
|
78
|
+
# collection.each_batch do |batch|
|
79
|
+
# batch.each do |item|
|
80
|
+
# # ...
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# == Variable Batch Sizes
|
85
|
+
#
|
86
|
+
# Each AWS service has its own rules on how it returns results.
|
87
|
+
# Because of this batch size may very based on:
|
88
|
+
#
|
89
|
+
# * Service limits (e.g. S3 limits keys to 1000 per response)
|
90
|
+
#
|
91
|
+
# * The size of response objects (SimpleDB limits responses to 1MB)
|
92
|
+
#
|
93
|
+
# * Time to process the request
|
94
|
+
#
|
95
|
+
# Because of these variables, batch sizes may not be consistent for
|
96
|
+
# a single collection. Each batch represents all of the items returned
|
97
|
+
# in a single resopnse.
|
98
|
+
#
|
99
|
+
# @note If you require fixed size batches, see {#in_groups_of}.
|
100
|
+
#
|
101
|
+
# @param (see #each)
|
102
|
+
#
|
103
|
+
# @option (see #each)
|
104
|
+
#
|
105
|
+
# @return (see #each)
|
106
|
+
#
|
107
|
+
def each_batch options = {}, &block
|
108
|
+
raise NotImplementedError
|
109
|
+
end
|
110
|
+
|
111
|
+
# Use this method when you want to call a method provided by
|
112
|
+
# Enumerable, but you need to pass options:
|
113
|
+
#
|
114
|
+
# # raises an error because collect does not accept arguments
|
115
|
+
# collection.collect(:limit => 10) {|i| i.name }
|
116
|
+
#
|
117
|
+
# # not an issue with the enum method
|
118
|
+
# collection.enum(:limit => 10).collect(&:name)
|
119
|
+
#
|
120
|
+
# @param (see #each)
|
121
|
+
#
|
122
|
+
# @option (see #each)
|
123
|
+
#
|
124
|
+
# @return [Enumerable::Enumerator] Returns an enumerator for this
|
125
|
+
# collection.
|
126
|
+
#
|
127
|
+
def enum options = {}
|
128
|
+
Enumerator.new(self, :each, options)
|
129
|
+
end
|
130
|
+
alias_method :enumerator, :enum
|
131
|
+
|
132
|
+
# Returns the first item from this collection.
|
133
|
+
#
|
134
|
+
# @return [item_or_nil] Returns the first item from this collection or
|
135
|
+
# nil if the collection is empty.
|
136
|
+
#
|
137
|
+
def first options = {}
|
138
|
+
enum(options.merge(:limit => 1)).first
|
139
|
+
end
|
140
|
+
|
141
|
+
# Yields items from this collection in groups of an exact
|
142
|
+
# size (except for perhaps the last group).
|
143
|
+
#
|
144
|
+
# collection.in_groups_of (10, :limit => 30) do |group|
|
145
|
+
#
|
146
|
+
# # each group should be exactly 10 items unless
|
147
|
+
# # fewer than 30 items are returned by the service
|
148
|
+
# group.each do |item|
|
149
|
+
# #...
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# @param [Integer] size Size each each group of objects
|
155
|
+
# should be yielded in.
|
156
|
+
# @param [Hash] options
|
157
|
+
# @option (see #each)
|
158
|
+
# @return (see #each)
|
159
|
+
def in_groups_of size, options = {}, &block
|
160
|
+
|
161
|
+
group = []
|
162
|
+
|
163
|
+
nil_or_next_token = each_batch(options) do |batch|
|
164
|
+
batch.each do |item|
|
165
|
+
group << item
|
166
|
+
if group.size == size
|
167
|
+
yield(group)
|
168
|
+
group = []
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
yield(group) unless group.empty?
|
174
|
+
|
175
|
+
nil_or_next_token
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
# Returns a single page of results in a kind-of array ({PageResult}).
|
180
|
+
#
|
181
|
+
# items = collection.page(:per_page => 10) # defaults to 10 items
|
182
|
+
# items.is_a?(Array) # => true
|
183
|
+
# items.size # => 8
|
184
|
+
# items.per_page # => 10
|
185
|
+
# items.last_page? # => true
|
186
|
+
#
|
187
|
+
# If you need to display a "next page" link in a web view you can
|
188
|
+
# use the #more? method. Just make sure the generated link
|
189
|
+
# contains the +next_token+.
|
190
|
+
#
|
191
|
+
# <% if items.more? %>
|
192
|
+
# <%= link_to('Next Page', params.merge(:next_token => items.next_token) %>
|
193
|
+
# <% end %>
|
194
|
+
#
|
195
|
+
# Then in your controller you can find the next page of results:
|
196
|
+
#
|
197
|
+
# items = collection.page(:next_token => params[:next_token])
|
198
|
+
#
|
199
|
+
# Given a {PageResult} you can also get more results directly:
|
200
|
+
#
|
201
|
+
# more_items = items.next_page
|
202
|
+
#
|
203
|
+
# @note This method does not accept a +:page+ option, which means you
|
204
|
+
# can only start at the begining of the collection and request
|
205
|
+
# the next page of results. You can not choose an offset
|
206
|
+
# or know how many pages of results there will be.
|
207
|
+
#
|
208
|
+
# @params [Hash] options A hash of options that modifies the
|
209
|
+
# items returned in the page of results.
|
210
|
+
#
|
211
|
+
# @option options [Integer] :per_page (10) The number of results
|
212
|
+
# to return for each page.
|
213
|
+
#
|
214
|
+
# @option options [String] :next_token (nil) A token that indicates
|
215
|
+
# an offset to use when paging items. Next tokens are returned
|
216
|
+
# by {PageResult#next_token}.
|
217
|
+
#
|
218
|
+
# Next tokens should only be consumed by the same collection that
|
219
|
+
# created them.
|
220
|
+
#
|
221
|
+
def page options = {}
|
222
|
+
|
223
|
+
each_opts = options.dup
|
224
|
+
|
225
|
+
per_page = each_opts.delete(:per_page)
|
226
|
+
per_page = [nil,''].include?(per_page) ? 10 : per_page.to_i
|
227
|
+
|
228
|
+
each_opts[:limit] = per_page
|
229
|
+
|
230
|
+
items = []
|
231
|
+
next_token = each(each_opts) do |item|
|
232
|
+
items << item
|
233
|
+
end
|
234
|
+
|
235
|
+
Core::PageResult.new(self, items, per_page, next_token)
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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
|
+
module Collection
|
17
|
+
|
18
|
+
module Batchable
|
19
|
+
|
20
|
+
include Collection
|
21
|
+
|
22
|
+
def each_batch options = {}, &block
|
23
|
+
|
24
|
+
raise NotImplementedError
|
25
|
+
|
26
|
+
each_opts = options.dup
|
27
|
+
|
28
|
+
limit = each_opts.delete(:limit)
|
29
|
+
|
30
|
+
next_token, skip = each_opts.delete(:next_token)
|
31
|
+
|
32
|
+
total = 0 # count of items yeileded across all batches
|
33
|
+
|
34
|
+
begin
|
35
|
+
|
36
|
+
batch = []
|
37
|
+
|
38
|
+
next_token = _each_item(next_token, each_opts.dup) do |item|
|
39
|
+
total += 1
|
40
|
+
batch << item
|
41
|
+
|
42
|
+
if limit and total == limit
|
43
|
+
yield(batch)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end until next_token.nil? or (limit and limit = total)
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
options = options.dup
|
59
|
+
|
60
|
+
limit = options.delete(:limit)
|
61
|
+
batch_size = options.delete(:batch_size)
|
62
|
+
options.delete(:next_token) if [nil, ''].include?(options[:next_token])
|
63
|
+
|
64
|
+
total = 0 # count of items yeileded across all batches
|
65
|
+
|
66
|
+
_each_response(options, limit, batch_size) do |response|
|
67
|
+
|
68
|
+
batch = []
|
69
|
+
each_item(response) do |item|
|
70
|
+
batch << item
|
71
|
+
if limit and (total += 1) == limit
|
72
|
+
yield(batch)
|
73
|
+
return
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
yield(batch)
|
78
|
+
|
79
|
+
batch.size
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
# @note +limit+ is ignored because Batchable colections do not
|
86
|
+
# accept a +:limit+ option at the service level.
|
87
|
+
# @note +batch_size+ is ignored because Batchable collections do not
|
88
|
+
# accept a +:batch_size+ option at the service level.
|
89
|
+
protected
|
90
|
+
def _each_response options, limit, batch_size, &block
|
91
|
+
|
92
|
+
next_token = nil
|
93
|
+
|
94
|
+
begin
|
95
|
+
|
96
|
+
page_opts = {}
|
97
|
+
page_opts[next_token_key] = next_token if next_token
|
98
|
+
|
99
|
+
response = client.send(request_method, options.merge(page_opts))
|
100
|
+
|
101
|
+
yield(response)
|
102
|
+
|
103
|
+
next_token = _next_token_for(response)
|
104
|
+
|
105
|
+
end until next_token.nil?
|
106
|
+
|
107
|
+
nil
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# Override this method in collections that have an alternate method
|
112
|
+
# for finding the next token.
|
113
|
+
protected
|
114
|
+
def _next_token_for response
|
115
|
+
method = _next_token_key
|
116
|
+
response.respond_to?(method) ? response.send(method) : nil
|
117
|
+
end
|
118
|
+
|
119
|
+
protected
|
120
|
+
def _next_token_key
|
121
|
+
:next_token
|
122
|
+
end
|
123
|
+
|
124
|
+
protected
|
125
|
+
def _each_item next_token, options = {}, &block
|
126
|
+
raise NotImplementedError
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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
|
+
module Collection
|
17
|
+
|
18
|
+
# AWS::Core::Collection::Limitable is used by collections that
|
19
|
+
# may truncate responses but that also accept a upper limit of
|
20
|
+
# results to return in a single request.
|
21
|
+
#
|
22
|
+
# See {AWS::Core::Collection} for documentation on the available
|
23
|
+
# methods.
|
24
|
+
module Limitable
|
25
|
+
|
26
|
+
include Model
|
27
|
+
include Collection
|
28
|
+
include Enumerable
|
29
|
+
|
30
|
+
def each_batch options = {}, &block
|
31
|
+
|
32
|
+
each_opts = options.dup
|
33
|
+
limit = each_opts.delete(:limit) || _limit
|
34
|
+
next_token = each_opts.delete(:next_token)
|
35
|
+
batch_size = each_opts.delete(:batch_size)
|
36
|
+
|
37
|
+
total = 0 # count of items yeileded across all batches
|
38
|
+
|
39
|
+
begin
|
40
|
+
|
41
|
+
max = nil
|
42
|
+
if limit or batch_size
|
43
|
+
max = []
|
44
|
+
max << (limit - total) if limit
|
45
|
+
max << batch_size if batch_size
|
46
|
+
max = max.min
|
47
|
+
end
|
48
|
+
|
49
|
+
batch = []
|
50
|
+
next_token = _each_item(next_token, max, each_opts.dup) do |item|
|
51
|
+
|
52
|
+
total += 1
|
53
|
+
batch << item
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
yield(batch)
|
58
|
+
|
59
|
+
end until next_token.nil? or (limit and limit == total)
|
60
|
+
|
61
|
+
next_token
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
def _each_item next_token, limit, options = {}, &block
|
67
|
+
raise NotImplementedError
|
68
|
+
end
|
69
|
+
|
70
|
+
# This method should be overriden in collection classes
|
71
|
+
# when there is another method to provide a "limit" besides
|
72
|
+
# as an option to the enumerable methods.
|
73
|
+
#
|
74
|
+
# SimpleDB::ItemCollection (for example) allows setting the limit
|
75
|
+
# in a method chain, e.g.
|
76
|
+
#
|
77
|
+
# collection.limit(10).each {|item| ... }
|
78
|
+
#
|
79
|
+
# These collection classes can simply override #_limit and return
|
80
|
+
# their prefered limit. This is only called in the abscense of
|
81
|
+
# the +:limit+ option.
|
82
|
+
#
|
83
|
+
# @private
|
84
|
+
protected
|
85
|
+
def _limit
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|