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
@@ -0,0 +1,89 @@
|
|
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::Simple is used by collections that always
|
19
|
+
# recieve every matching items in a single response.
|
20
|
+
#
|
21
|
+
# This means:
|
22
|
+
#
|
23
|
+
# * Paging methods are simulated
|
24
|
+
#
|
25
|
+
# * Next tokens are artificial (guessable numeric offsets)
|
26
|
+
#
|
27
|
+
# AWS services generally return all items only for requests with a
|
28
|
+
# small maximum number of results.
|
29
|
+
#
|
30
|
+
# See {AWS::Core::Collection} for documentation on the available
|
31
|
+
# collection methods.
|
32
|
+
module Simple
|
33
|
+
|
34
|
+
include Model
|
35
|
+
include Enumerable
|
36
|
+
include Collection
|
37
|
+
|
38
|
+
# (see AWS::Core::Collection#each_batch)
|
39
|
+
def each_batch options = {}, &block
|
40
|
+
|
41
|
+
each_opts = options.dup
|
42
|
+
limit = each_opts.delete(:limit)
|
43
|
+
next_token = each_opts.delete(:next_token)
|
44
|
+
offset = next_token ? next_token.to_i - 1 : 0
|
45
|
+
total = 0
|
46
|
+
|
47
|
+
nil_or_next_token = nil
|
48
|
+
|
49
|
+
batch = []
|
50
|
+
_each_item(each_opts.dup) do |item|
|
51
|
+
|
52
|
+
total += 1
|
53
|
+
|
54
|
+
# skip until we reach our offset (derived from the "next token")
|
55
|
+
next if total <= offset
|
56
|
+
|
57
|
+
if limit
|
58
|
+
|
59
|
+
if batch.size < limit
|
60
|
+
batch << item
|
61
|
+
else
|
62
|
+
# allow _each_item to yield one more item than needed
|
63
|
+
# so we can determine if we should return a "next token"
|
64
|
+
nil_or_next_token = total
|
65
|
+
break
|
66
|
+
end
|
67
|
+
|
68
|
+
else
|
69
|
+
batch << item
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
yield(batch)
|
75
|
+
|
76
|
+
nil_or_next_token
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
def _each_item options = {}, &block
|
82
|
+
raise NotImplementedError
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -102,6 +102,26 @@ module AWS
|
|
102
102
|
# size (in bytes) each S3 multipart segment should be.
|
103
103
|
# Defaults to 5242880 (5MB).
|
104
104
|
#
|
105
|
+
# @attr_reader [Symbol] s3_server_side_encryption The algorithm to
|
106
|
+
# use when encrypting object data on the server side. The only
|
107
|
+
# valid value is +:aes256+, which specifies that the object
|
108
|
+
# should be stored using the AES encryption algorithm with 256
|
109
|
+
# bit keys. Defaults to +nil+, meaning server side encryption
|
110
|
+
# is not used unless specified on each individual call to upload
|
111
|
+
# an object. This option controls the default behavior for the
|
112
|
+
# following method:
|
113
|
+
#
|
114
|
+
# * {S3::S3Object#write}
|
115
|
+
# * {S3::S3Object#multipart_upload}
|
116
|
+
# * {S3::S3Object#copy_from} and {S3::S3Object#copy_to}
|
117
|
+
# * {S3::S3Object#presigned_post}
|
118
|
+
# * {S3::Bucket#presigned_post}
|
119
|
+
#
|
120
|
+
# You can construct an interface to Amazon S3 which always
|
121
|
+
# stores data using server side encryption as follows:
|
122
|
+
#
|
123
|
+
# s3 = AWS::S3.new(:s3_server_side_encryption => :aes256)
|
124
|
+
#
|
105
125
|
# @attr_reader [String,nil] secret_access_key AWS secret access key
|
106
126
|
# credential. Defaults to +nil+.
|
107
127
|
#
|
@@ -306,6 +326,7 @@ module AWS
|
|
306
326
|
:ssl_ca_file,
|
307
327
|
:user_agent_prefix,
|
308
328
|
:logger,
|
329
|
+
:logger_truncate_strings_at,
|
309
330
|
]
|
310
331
|
|
311
332
|
add_option :"#{ruby_name}_endpoint", default_endpoint
|
@@ -322,6 +343,8 @@ module AWS
|
|
322
343
|
add_option :http_handler, Core::Http::NetHttpHandler.new
|
323
344
|
|
324
345
|
add_option :logger
|
346
|
+
|
347
|
+
add_option :logger_truncate_strings_at, 1000
|
325
348
|
|
326
349
|
add_option :max_retries, 3
|
327
350
|
|
@@ -0,0 +1,73 @@
|
|
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
|
+
class PageResult < Array
|
18
|
+
|
19
|
+
# @return [Collection] Returns the collection that was used to
|
20
|
+
# populated this page of results.
|
21
|
+
attr_reader :collection
|
22
|
+
|
23
|
+
# @return [Integer] Returns the maximum number of results per page.
|
24
|
+
# The final page in a collection may return fewer than +:per_page+
|
25
|
+
# items (e.g. +:per_page+ is 10 and there are only 7 items).
|
26
|
+
attr_reader :per_page
|
27
|
+
|
28
|
+
# @return [String] An opaque token that can be passed the #page method
|
29
|
+
# of the collection that returned this page of results. This next
|
30
|
+
# token behaves as a pseudo offset. If +next_token+ is +nil+ then
|
31
|
+
# there are no more results for the collection.
|
32
|
+
attr_reader :next_token
|
33
|
+
|
34
|
+
# @param [Collection] collection The collection that was used to
|
35
|
+
# request this page of results. The collection should respond to
|
36
|
+
# #page and accept a :next_token option.
|
37
|
+
#
|
38
|
+
# @param [Array] items An array of result items that represent a
|
39
|
+
# page of results.
|
40
|
+
#
|
41
|
+
# @param [Integer] per_page The number of requested items for this
|
42
|
+
# page of results. If the count of items is smaller than +per_page+
|
43
|
+
# then this is the last page of results.
|
44
|
+
#
|
45
|
+
# @param [String] next_token (nil) A token that can be passed to the
|
46
|
+
#
|
47
|
+
def initialize collection, items, per_page, next_token
|
48
|
+
@collection = collection
|
49
|
+
@per_page = per_page
|
50
|
+
@next_token = next_token
|
51
|
+
super(items)
|
52
|
+
end
|
53
|
+
|
54
|
+
def next_page
|
55
|
+
if last_page?
|
56
|
+
raise 'unable to get the next page, already at the last page'
|
57
|
+
end
|
58
|
+
collection.page(:per_page => per_page, :next_token => next_token)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Boolean] Returns true if this is the last page of results.
|
62
|
+
def last_page?
|
63
|
+
next_token.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Boolean] Returns true if there are more pages of results.
|
67
|
+
def more?
|
68
|
+
!!next_token
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -30,9 +30,10 @@ module AWS
|
|
30
30
|
class SecurityGroup < Resource
|
31
31
|
|
32
32
|
AWS.register_autoloads(self, 'aws/ec2/security_group') do
|
33
|
-
autoload :IpPermission,
|
34
|
-
autoload :IpPermissionCollection,
|
35
|
-
autoload :
|
33
|
+
autoload :IpPermission, 'ip_permission'
|
34
|
+
autoload :IpPermissionCollection, 'ingress_ip_permission_collection'
|
35
|
+
autoload :IngressIpPermissionCollection, 'ingress_ip_permission_collection'
|
36
|
+
autoload :EgressIpPermissionCollection, 'egress_ip_permission_collection'
|
36
37
|
end
|
37
38
|
|
38
39
|
include TaggedItem
|
@@ -79,12 +80,12 @@ module AWS
|
|
79
80
|
vpc_id ? true : false
|
80
81
|
end
|
81
82
|
|
82
|
-
# @return [SecurityGroup::
|
83
|
+
# @return [SecurityGroup::IngressIpPermissionCollection] Returns a
|
83
84
|
# collection of {IpPermission} objects that represents all of
|
84
85
|
# the (ingress) permissions this security group has
|
85
86
|
# authorizations for.
|
86
87
|
def ingress_ip_permissions
|
87
|
-
|
88
|
+
IngressIpPermissionCollection.new(self, :config => config)
|
88
89
|
end
|
89
90
|
alias_method :ip_permissions, :ingress_ip_permissions
|
90
91
|
|
@@ -105,8 +106,9 @@ module AWS
|
|
105
106
|
#
|
106
107
|
# @param [String] ip_ranges One or more IP ranges to allow ping from.
|
107
108
|
# Defaults to 0.0.0.0/0
|
108
|
-
#
|
109
|
-
#
|
109
|
+
#
|
110
|
+
# @return [nil]
|
111
|
+
#
|
110
112
|
def allow_ping *sources
|
111
113
|
sources << '0.0.0.0/0' if sources.empty?
|
112
114
|
authorize_ingress('icmp', -1, *sources)
|
@@ -117,8 +119,9 @@ module AWS
|
|
117
119
|
#
|
118
120
|
# @param [String] ip_ranges One or more IP ranges to allow ping from.
|
119
121
|
# Defaults to 0.0.0.0/0
|
120
|
-
#
|
121
|
-
#
|
122
|
+
#
|
123
|
+
# @return [nil]
|
124
|
+
#
|
122
125
|
def disallow_ping *sources
|
123
126
|
sources << '0.0.0.0/0' if sources.empty?
|
124
127
|
revoke_ingress('icmp', -1, *sources)
|
@@ -138,25 +141,67 @@ module AWS
|
|
138
141
|
# # ftp
|
139
142
|
# security_group.authorize_ingress(:tcp, 20..21)
|
140
143
|
#
|
144
|
+
# == Sources
|
145
|
+
#
|
146
|
+
# Security groups accept ingress trafic from:
|
147
|
+
#
|
148
|
+
# * CIDR IP addresses
|
149
|
+
# * security groups
|
150
|
+
# * load balancers
|
151
|
+
#
|
152
|
+
# === Ip Addresses
|
153
|
+
#
|
141
154
|
# In the following example allow incoming SSH from a list of
|
142
|
-
# IP address.
|
155
|
+
# IP address ranges.
|
143
156
|
#
|
144
157
|
# security_group.authorize_ingress(:tcp, 22,
|
145
158
|
# '111.111.111.111/0', '222.222.222.222/0')
|
146
159
|
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
160
|
+
# === Security Groups
|
161
|
+
#
|
162
|
+
# To autohrize ingress traffic from all EC2 instance in another
|
163
|
+
# security group, just pass the security group:
|
150
164
|
#
|
151
165
|
# web = security_groups.create('webservers')
|
152
166
|
# db = security_groups.create('database')
|
153
|
-
#
|
154
|
-
# # allows ec2 instances in the webservers security group to make
|
155
|
-
# # tcp requests via port 3306 to instances in the database
|
156
|
-
# # security group
|
157
167
|
# db.authorize_ingress(:tcp, 3306, web)
|
158
168
|
#
|
159
|
-
# You can
|
169
|
+
# You can also pass a hash of security group details instead of
|
170
|
+
# a {SecurityGroup} object.
|
171
|
+
#
|
172
|
+
# # by security group name
|
173
|
+
# sg.authorize_ingress(:tcp, 80, { :group_name => 'other-group' })
|
174
|
+
#
|
175
|
+
# # by security group id
|
176
|
+
# sg.authorize_ingress(:tcp, 80, { :group_id => 'sg-1234567' })
|
177
|
+
#
|
178
|
+
# If the security group belongs to a different account, just make
|
179
|
+
# sure it has the correct owner ID populated:
|
180
|
+
#
|
181
|
+
# not_my_sg = SecurityGroup.new('sg-1234567', :owner_id => 'abcxyz123')
|
182
|
+
# my_sg.authorize_ingress(:tcp, 80, not_my_sg)
|
183
|
+
#
|
184
|
+
# You can do the same with a hash as well (with either +:group_id+
|
185
|
+
# or +:group_name+):
|
186
|
+
#
|
187
|
+
# sg.authorize_ingress(:tcp, 21..22, { :group_id => 'sg-id', :user_id => 'abcxyz123' })
|
188
|
+
#
|
189
|
+
# === Load Balancers
|
190
|
+
#
|
191
|
+
# If you use ELB to manage load balancers, then you need to add
|
192
|
+
# ingress permissions to the security groups they route traffic into.
|
193
|
+
# You can do this by passing the {LoadBalancer} into authorize_ingress:
|
194
|
+
#
|
195
|
+
# load_balancer = AWS::ELB.new.load_balancers['web-load-balancer']
|
196
|
+
#
|
197
|
+
# sg.authorize_ingress(:tcp, 80, load_balancer)
|
198
|
+
#
|
199
|
+
# === Multiple Sources
|
200
|
+
#
|
201
|
+
# You can provide multiple sources each time you call authorize
|
202
|
+
# ingress, and you can mix and match the source types:
|
203
|
+
#
|
204
|
+
# sg.authorize_ingress(:tcp, 80, other_sg, '1.2.3.4/0', load_balancer)
|
160
205
|
#
|
161
206
|
# @param [String, Symbol] protocol Should be :tcp, :udp or :icmp
|
162
207
|
# or the string equivalent.
|
@@ -166,35 +211,38 @@ module AWS
|
|
166
211
|
# or a range (like 20..21).
|
167
212
|
#
|
168
213
|
# @param [Mixed] sources One or more CIDR IP addresses,
|
169
|
-
# security groups, or
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
# group.
|
214
|
+
# security groups, or load balancers. Security groups
|
215
|
+
# can be specified as hashes.
|
216
|
+
#
|
217
|
+
# A security group hash must provide either +:group_id+ or
|
218
|
+
# +:group_name+ for the security group. If the security group
|
219
|
+
# does not belong to you aws account then you must also
|
220
|
+
# provide +:user_id+ (which can be an AWS account ID or alias).
|
174
221
|
#
|
175
|
-
# @return [
|
176
|
-
# to this security group.
|
222
|
+
# @return [nil]
|
177
223
|
#
|
178
224
|
def authorize_ingress protocol, ports, *sources
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
225
|
+
client.authorize_security_group_ingress(
|
226
|
+
:group_id => id,
|
227
|
+
:ip_permissions => [ingress_opts(protocol, ports, sources)]
|
228
|
+
)
|
229
|
+
nil
|
184
230
|
end
|
185
231
|
|
186
232
|
# Revokes an ingress (inbound) ip permission. This is the inverse
|
187
233
|
# operation to {#authorize_ingress}. See {#authorize_ingress}
|
188
234
|
# for param and option documentation.
|
235
|
+
#
|
189
236
|
# @see #authorize_ingress
|
190
|
-
#
|
191
|
-
#
|
237
|
+
#
|
238
|
+
# @return [nil]
|
239
|
+
#
|
192
240
|
def revoke_ingress protocol, ports, *sources
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
241
|
+
client.revoke_security_group_ingress(
|
242
|
+
:group_id => id,
|
243
|
+
:ip_permissions => [ingress_opts(protocol, ports, sources)]
|
244
|
+
)
|
245
|
+
nil
|
198
246
|
end
|
199
247
|
|
200
248
|
# Authorize egress (outbound) traffic for a VPC security group.
|
@@ -209,44 +257,43 @@ module AWS
|
|
209
257
|
# @note Calling this method on a non-VPC security group raises an error.
|
210
258
|
#
|
211
259
|
# @overload authorize_egress(*sources, options = {})
|
260
|
+
#
|
212
261
|
# @param [Mixed] sources One or more CIDR IP addresses,
|
213
|
-
# security groups
|
214
|
-
#
|
215
|
-
#
|
216
|
-
# user id should be the owner_id (account id) of the security
|
217
|
-
# group.
|
262
|
+
# security groups or load balancers. See {#authorize_ingress}
|
263
|
+
# for more information on accepted formats for sources.
|
264
|
+
#
|
218
265
|
# @param [Hash] options
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
266
|
+
#
|
267
|
+
# @option options [Symbol] :protocol (:any) The protocol name or number
|
268
|
+
# to authorize egress traffic for. For a complete list of protocols
|
269
|
+
# see: {http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml}
|
270
|
+
#
|
223
271
|
# @option options [Range<Integer>,Integer] :ports (nil) An optional
|
224
272
|
# port or range of ports. This option is required depending on
|
225
|
-
# the
|
226
|
-
#
|
227
|
-
# @
|
228
|
-
#
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
permission
|
235
|
-
end
|
273
|
+
# the protocol.
|
274
|
+
#
|
275
|
+
# @return [nil]
|
276
|
+
#
|
277
|
+
def authorize_egress *sources
|
278
|
+
client.authorize_security_group_egress(
|
279
|
+
:group_id => id,
|
280
|
+
:ip_permissions => [egress_opts(sources)])
|
281
|
+
nil
|
236
282
|
end
|
237
283
|
|
238
284
|
# Revokes an egress (outound) ip permission. This is the inverse
|
239
285
|
# operation to {#authorize_egress}. See {#authorize_egress}
|
240
286
|
# for param and option documentation.
|
287
|
+
#
|
241
288
|
# @see #authorize_egress
|
242
|
-
#
|
243
|
-
#
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
289
|
+
#
|
290
|
+
# @return [nil]
|
291
|
+
#
|
292
|
+
def revoke_egress *sources
|
293
|
+
client.revoke_security_group_egress(
|
294
|
+
:group_id => id,
|
295
|
+
:ip_permissions => [egress_opts(sources)])
|
296
|
+
nil
|
250
297
|
end
|
251
298
|
|
252
299
|
# Deletes this security group.
|
@@ -281,22 +328,25 @@ module AWS
|
|
281
328
|
|
282
329
|
# @private
|
283
330
|
protected
|
284
|
-
def
|
331
|
+
def ingress_opts protocol, ports, sources
|
332
|
+
|
333
|
+
opts = {}
|
334
|
+
opts[:ip_protocol] = protocol.to_s.downcase
|
335
|
+
opts[:from_port] = Array(ports).first.to_i
|
336
|
+
opts[:to_port] = Array(ports).last.to_i
|
285
337
|
|
286
338
|
ips, groups = parse_sources(sources)
|
287
339
|
|
288
|
-
|
289
|
-
|
290
|
-
options[:groups] = groups unless groups.empty?
|
291
|
-
options[:egress] = false
|
340
|
+
opts[:ip_ranges] = ips unless ips.empty?
|
341
|
+
opts[:user_id_group_pairs] = groups unless groups.empty?
|
292
342
|
|
293
|
-
|
343
|
+
opts
|
294
344
|
|
295
345
|
end
|
296
346
|
|
297
347
|
# @private
|
298
348
|
protected
|
299
|
-
def
|
349
|
+
def egress_opts args
|
300
350
|
ensure_vpc do
|
301
351
|
|
302
352
|
last = args.last
|
@@ -312,17 +362,22 @@ module AWS
|
|
312
362
|
options = {}
|
313
363
|
end
|
314
364
|
|
315
|
-
|
365
|
+
opts = {}
|
366
|
+
|
367
|
+
opts[:ip_protocol] = [nil,:any, '-1'].include?(options[:protocol]) ?
|
368
|
+
'-1' : options[:protocol].to_s.downcase
|
316
369
|
|
317
|
-
|
370
|
+
if options[:ports]
|
371
|
+
opts[:from_port] = Array(options[:ports]).first.to_i
|
372
|
+
opts[:to_port] = Array(options[:ports]).last.to_i
|
373
|
+
end
|
318
374
|
|
319
375
|
ips, groups = parse_sources(args)
|
320
376
|
|
321
|
-
|
322
|
-
|
323
|
-
options[:egress] = true
|
377
|
+
opts[:ip_ranges] = ips unless ips.empty?
|
378
|
+
opts[:user_id_group_pairs] = groups unless groups.empty?
|
324
379
|
|
325
|
-
|
380
|
+
opts
|
326
381
|
|
327
382
|
end
|
328
383
|
end
|
@@ -336,29 +391,39 @@ module AWS
|
|
336
391
|
|
337
392
|
sources.each do |source|
|
338
393
|
case source
|
339
|
-
when String then ips << source
|
340
|
-
when SecurityGroup then groups << source
|
341
|
-
when Hash
|
342
|
-
if source.has_key?(:group_id) and source.has_key?(:user_id)
|
343
394
|
|
344
|
-
|
345
|
-
|
346
|
-
|
395
|
+
when String
|
396
|
+
ips << { :cidr_ip => source }
|
397
|
+
|
398
|
+
when SecurityGroup
|
399
|
+
groups << { :group_id => source.id, :user_id => source.owner_id }
|
347
400
|
|
348
|
-
|
401
|
+
when ELB::LoadBalancer
|
402
|
+
groups << source.source_security_group
|
349
403
|
|
350
|
-
|
404
|
+
when Hash
|
405
|
+
|
406
|
+
# group name or id required
|
407
|
+
unless source.has_key?(:group_id) or source.has_key?(:group_name)
|
351
408
|
raise ArgumentError, 'invalid ip permission hash, ' +
|
352
|
-
'must provide :group_id
|
409
|
+
'must provide :group_id or :group_name'
|
353
410
|
end
|
354
411
|
|
412
|
+
# prevent typos
|
413
|
+
unless source.keys - [:group_id, :group_name, :user_id] == []
|
414
|
+
raise ArgumentError, 'invalid ip permission hash, ' +
|
415
|
+
'only accepts the following keys, :group_id, :group_name, :user_id'
|
416
|
+
end
|
417
|
+
|
418
|
+
groups << source
|
419
|
+
|
355
420
|
else
|
356
421
|
raise ArgumentError, 'invalid ingress ip permission, ' +
|
357
422
|
'expected CIDR IP addres or SecurityGroup'
|
358
423
|
end
|
359
424
|
end
|
360
425
|
|
361
|
-
ips << '0.0.0.0/0' if ips.empty? and groups.empty?
|
426
|
+
ips << { :cidr_ip => '0.0.0.0/0' } if ips.empty? and groups.empty?
|
362
427
|
|
363
428
|
[ips, groups]
|
364
429
|
|