aws-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.yardopts +6 -0
  2. data/LICENSE.txt +171 -0
  3. data/NOTICE.txt +2 -0
  4. data/README.rdoc +189 -0
  5. data/lib/aws-sdk.rb +14 -0
  6. data/lib/aws.rb +63 -0
  7. data/lib/aws/api_config.rb +45 -0
  8. data/lib/aws/api_config/.document +0 -0
  9. data/lib/aws/api_config/EC2-2011-02-28.yml +2314 -0
  10. data/lib/aws/api_config/SNS-2010-03-31.yml +171 -0
  11. data/lib/aws/api_config/SQS-2009-02-01.yml +161 -0
  12. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +278 -0
  13. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +147 -0
  14. data/lib/aws/api_config_transform.rb +32 -0
  15. data/lib/aws/async_handle.rb +90 -0
  16. data/lib/aws/authorize_v2.rb +37 -0
  17. data/lib/aws/authorize_v3.rb +37 -0
  18. data/lib/aws/base_client.rb +524 -0
  19. data/lib/aws/cacheable.rb +92 -0
  20. data/lib/aws/common.rb +228 -0
  21. data/lib/aws/configurable.rb +36 -0
  22. data/lib/aws/configuration.rb +272 -0
  23. data/lib/aws/configured_client_methods.rb +81 -0
  24. data/lib/aws/configured_grammars.rb +65 -0
  25. data/lib/aws/configured_option_grammars.rb +46 -0
  26. data/lib/aws/configured_xml_grammars.rb +47 -0
  27. data/lib/aws/default_signer.rb +38 -0
  28. data/lib/aws/ec2.rb +321 -0
  29. data/lib/aws/ec2/attachment.rb +149 -0
  30. data/lib/aws/ec2/attachment_collection.rb +57 -0
  31. data/lib/aws/ec2/availability_zone.rb +80 -0
  32. data/lib/aws/ec2/availability_zone_collection.rb +47 -0
  33. data/lib/aws/ec2/block_device_mappings.rb +53 -0
  34. data/lib/aws/ec2/client.rb +54 -0
  35. data/lib/aws/ec2/client/xml.rb +127 -0
  36. data/lib/aws/ec2/collection.rb +39 -0
  37. data/lib/aws/ec2/config_transform.rb +63 -0
  38. data/lib/aws/ec2/elastic_ip.rb +107 -0
  39. data/lib/aws/ec2/elastic_ip_collection.rb +85 -0
  40. data/lib/aws/ec2/errors.rb +29 -0
  41. data/lib/aws/ec2/filtered_collection.rb +65 -0
  42. data/lib/aws/ec2/has_permissions.rb +46 -0
  43. data/lib/aws/ec2/image.rb +245 -0
  44. data/lib/aws/ec2/image_collection.rb +235 -0
  45. data/lib/aws/ec2/instance.rb +515 -0
  46. data/lib/aws/ec2/instance_collection.rb +276 -0
  47. data/lib/aws/ec2/key_pair.rb +86 -0
  48. data/lib/aws/ec2/key_pair_collection.rb +102 -0
  49. data/lib/aws/ec2/permission_collection.rb +177 -0
  50. data/lib/aws/ec2/region.rb +81 -0
  51. data/lib/aws/ec2/region_collection.rb +55 -0
  52. data/lib/aws/ec2/request.rb +27 -0
  53. data/lib/aws/ec2/reserved_instances.rb +50 -0
  54. data/lib/aws/ec2/reserved_instances_collection.rb +44 -0
  55. data/lib/aws/ec2/reserved_instances_offering.rb +55 -0
  56. data/lib/aws/ec2/reserved_instances_offering_collection.rb +43 -0
  57. data/lib/aws/ec2/resource.rb +340 -0
  58. data/lib/aws/ec2/resource_tag_collection.rb +218 -0
  59. data/lib/aws/ec2/security_group.rb +246 -0
  60. data/lib/aws/ec2/security_group/ip_permission.rb +70 -0
  61. data/lib/aws/ec2/security_group/ip_permission_collection.rb +59 -0
  62. data/lib/aws/ec2/security_group_collection.rb +132 -0
  63. data/lib/aws/ec2/snapshot.rb +138 -0
  64. data/lib/aws/ec2/snapshot_collection.rb +90 -0
  65. data/lib/aws/ec2/tag.rb +88 -0
  66. data/lib/aws/ec2/tag_collection.rb +114 -0
  67. data/lib/aws/ec2/tagged_collection.rb +48 -0
  68. data/lib/aws/ec2/tagged_item.rb +87 -0
  69. data/lib/aws/ec2/volume.rb +190 -0
  70. data/lib/aws/ec2/volume_collection.rb +95 -0
  71. data/lib/aws/errors.rb +129 -0
  72. data/lib/aws/http/builtin_handler.rb +69 -0
  73. data/lib/aws/http/curb_handler.rb +123 -0
  74. data/lib/aws/http/handler.rb +77 -0
  75. data/lib/aws/http/httparty_handler.rb +61 -0
  76. data/lib/aws/http/request.rb +136 -0
  77. data/lib/aws/http/request_param.rb +63 -0
  78. data/lib/aws/http/response.rb +75 -0
  79. data/lib/aws/ignore_result_element.rb +38 -0
  80. data/lib/aws/indifferent_hash.rb +86 -0
  81. data/lib/aws/inflection.rb +46 -0
  82. data/lib/aws/lazy_error_classes.rb +64 -0
  83. data/lib/aws/meta_utils.rb +43 -0
  84. data/lib/aws/model.rb +57 -0
  85. data/lib/aws/naming.rb +32 -0
  86. data/lib/aws/option_grammar.rb +544 -0
  87. data/lib/aws/policy.rb +912 -0
  88. data/lib/aws/rails.rb +209 -0
  89. data/lib/aws/record.rb +79 -0
  90. data/lib/aws/record/attribute.rb +94 -0
  91. data/lib/aws/record/attribute_macros.rb +288 -0
  92. data/lib/aws/record/attributes/boolean.rb +49 -0
  93. data/lib/aws/record/attributes/datetime.rb +86 -0
  94. data/lib/aws/record/attributes/float.rb +48 -0
  95. data/lib/aws/record/attributes/integer.rb +68 -0
  96. data/lib/aws/record/attributes/sortable_float.rb +60 -0
  97. data/lib/aws/record/attributes/sortable_integer.rb +95 -0
  98. data/lib/aws/record/attributes/string.rb +69 -0
  99. data/lib/aws/record/base.rb +728 -0
  100. data/lib/aws/record/conversion.rb +38 -0
  101. data/lib/aws/record/dirty_tracking.rb +286 -0
  102. data/lib/aws/record/errors.rb +153 -0
  103. data/lib/aws/record/exceptions.rb +48 -0
  104. data/lib/aws/record/finder_methods.rb +262 -0
  105. data/lib/aws/record/naming.rb +31 -0
  106. data/lib/aws/record/scope.rb +157 -0
  107. data/lib/aws/record/validations.rb +653 -0
  108. data/lib/aws/record/validator.rb +237 -0
  109. data/lib/aws/record/validators/acceptance.rb +51 -0
  110. data/lib/aws/record/validators/block.rb +38 -0
  111. data/lib/aws/record/validators/confirmation.rb +43 -0
  112. data/lib/aws/record/validators/count.rb +108 -0
  113. data/lib/aws/record/validators/exclusion.rb +43 -0
  114. data/lib/aws/record/validators/format.rb +57 -0
  115. data/lib/aws/record/validators/inclusion.rb +56 -0
  116. data/lib/aws/record/validators/length.rb +107 -0
  117. data/lib/aws/record/validators/numericality.rb +138 -0
  118. data/lib/aws/record/validators/presence.rb +45 -0
  119. data/lib/aws/resource_cache.rb +39 -0
  120. data/lib/aws/response.rb +113 -0
  121. data/lib/aws/response_cache.rb +50 -0
  122. data/lib/aws/s3.rb +109 -0
  123. data/lib/aws/s3/access_control_list.rb +252 -0
  124. data/lib/aws/s3/acl_object.rb +266 -0
  125. data/lib/aws/s3/bucket.rb +320 -0
  126. data/lib/aws/s3/bucket_collection.rb +122 -0
  127. data/lib/aws/s3/bucket_version_collection.rb +85 -0
  128. data/lib/aws/s3/client.rb +999 -0
  129. data/lib/aws/s3/client/xml.rb +190 -0
  130. data/lib/aws/s3/data_options.rb +99 -0
  131. data/lib/aws/s3/errors.rb +43 -0
  132. data/lib/aws/s3/multipart_upload.rb +318 -0
  133. data/lib/aws/s3/multipart_upload_collection.rb +78 -0
  134. data/lib/aws/s3/object_collection.rb +159 -0
  135. data/lib/aws/s3/object_metadata.rb +67 -0
  136. data/lib/aws/s3/object_upload_collection.rb +83 -0
  137. data/lib/aws/s3/object_version.rb +141 -0
  138. data/lib/aws/s3/object_version_collection.rb +78 -0
  139. data/lib/aws/s3/paginated_collection.rb +94 -0
  140. data/lib/aws/s3/policy.rb +76 -0
  141. data/lib/aws/s3/prefix_and_delimiter_collection.rb +56 -0
  142. data/lib/aws/s3/prefixed_collection.rb +84 -0
  143. data/lib/aws/s3/presigned_post.rb +504 -0
  144. data/lib/aws/s3/request.rb +198 -0
  145. data/lib/aws/s3/s3_object.rb +794 -0
  146. data/lib/aws/s3/tree.rb +116 -0
  147. data/lib/aws/s3/tree/branch_node.rb +71 -0
  148. data/lib/aws/s3/tree/child_collection.rb +108 -0
  149. data/lib/aws/s3/tree/leaf_node.rb +99 -0
  150. data/lib/aws/s3/tree/node.rb +22 -0
  151. data/lib/aws/s3/tree/parent.rb +90 -0
  152. data/lib/aws/s3/uploaded_part.rb +82 -0
  153. data/lib/aws/s3/uploaded_part_collection.rb +86 -0
  154. data/lib/aws/service_interface.rb +60 -0
  155. data/lib/aws/simple_db.rb +202 -0
  156. data/lib/aws/simple_db/attribute.rb +159 -0
  157. data/lib/aws/simple_db/attribute_collection.rb +227 -0
  158. data/lib/aws/simple_db/client.rb +52 -0
  159. data/lib/aws/simple_db/client/options.rb +34 -0
  160. data/lib/aws/simple_db/client/xml.rb +68 -0
  161. data/lib/aws/simple_db/consistent_read_option.rb +42 -0
  162. data/lib/aws/simple_db/delete_attributes.rb +64 -0
  163. data/lib/aws/simple_db/domain.rb +118 -0
  164. data/lib/aws/simple_db/domain_collection.rb +116 -0
  165. data/lib/aws/simple_db/domain_metadata.rb +112 -0
  166. data/lib/aws/simple_db/errors.rb +46 -0
  167. data/lib/aws/simple_db/expect_condition_option.rb +45 -0
  168. data/lib/aws/simple_db/item.rb +84 -0
  169. data/lib/aws/simple_db/item_collection.rb +594 -0
  170. data/lib/aws/simple_db/item_data.rb +70 -0
  171. data/lib/aws/simple_db/put_attributes.rb +62 -0
  172. data/lib/aws/simple_db/request.rb +27 -0
  173. data/lib/aws/simple_email_service.rb +373 -0
  174. data/lib/aws/simple_email_service/client.rb +39 -0
  175. data/lib/aws/simple_email_service/client/options.rb +24 -0
  176. data/lib/aws/simple_email_service/client/xml.rb +38 -0
  177. data/lib/aws/simple_email_service/email_address_collection.rb +66 -0
  178. data/lib/aws/simple_email_service/errors.rb +29 -0
  179. data/lib/aws/simple_email_service/quotas.rb +64 -0
  180. data/lib/aws/simple_email_service/request.rb +27 -0
  181. data/lib/aws/sns.rb +69 -0
  182. data/lib/aws/sns/client.rb +37 -0
  183. data/lib/aws/sns/client/options.rb +24 -0
  184. data/lib/aws/sns/client/xml.rb +38 -0
  185. data/lib/aws/sns/errors.rb +29 -0
  186. data/lib/aws/sns/policy.rb +49 -0
  187. data/lib/aws/sns/request.rb +27 -0
  188. data/lib/aws/sns/subscription.rb +100 -0
  189. data/lib/aws/sns/subscription_collection.rb +84 -0
  190. data/lib/aws/sns/topic.rb +384 -0
  191. data/lib/aws/sns/topic_collection.rb +70 -0
  192. data/lib/aws/sns/topic_subscription_collection.rb +58 -0
  193. data/lib/aws/sqs.rb +70 -0
  194. data/lib/aws/sqs/client.rb +38 -0
  195. data/lib/aws/sqs/client/xml.rb +36 -0
  196. data/lib/aws/sqs/errors.rb +33 -0
  197. data/lib/aws/sqs/policy.rb +50 -0
  198. data/lib/aws/sqs/queue.rb +507 -0
  199. data/lib/aws/sqs/queue_collection.rb +105 -0
  200. data/lib/aws/sqs/received_message.rb +184 -0
  201. data/lib/aws/sqs/received_sns_message.rb +112 -0
  202. data/lib/aws/sqs/request.rb +44 -0
  203. data/lib/aws/xml_grammar.rb +923 -0
  204. data/rails/init.rb +15 -0
  205. metadata +298 -0
@@ -0,0 +1,246 @@
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
+ require 'aws/ec2/resource'
15
+ require 'aws/ec2/tagged_item'
16
+ require 'aws/ec2/security_group/ip_permission'
17
+ require 'aws/ec2/security_group/ip_permission_collection'
18
+
19
+ module AWS
20
+ class EC2
21
+
22
+ # Represents a security group in EC2.
23
+ class SecurityGroup < Resource
24
+
25
+ include TaggedItem
26
+
27
+ def initialize id, options = {}
28
+ @id = id
29
+ @name = options[:name]
30
+ @description = options[:description]
31
+ @owner_id = options[:owner_id]
32
+ super
33
+ end
34
+
35
+ # @return [String] The id of the security group.
36
+ attr_reader :id
37
+
38
+ alias_method :group_id, :id
39
+
40
+ # @return [Boolean] True if the security group exists.
41
+ def exists?
42
+ client.describe_security_groups(:filters =>
43
+ [{ :name => "group-id",
44
+ :values => [id] }]).
45
+ security_group_index.key?(id)
46
+ end
47
+
48
+ # @return [String] The name of the security group.
49
+ def name; end
50
+ describe_call_attribute :group_name, :getter => :name, :memoize => true
51
+
52
+ # @return [String] The id of the owner for this security group.
53
+ def owner_id; end
54
+ describe_call_attribute :owner_id, :memoize => true
55
+
56
+ # @return [String] The short informal description given when the
57
+ # group was created.
58
+ def description; end
59
+ describe_call_attribute :group_description, :getter => :description, :memoize => true
60
+
61
+ describe_call_attribute :ip_permissions, :getter => :ip_permissions_list
62
+
63
+ # @return [SecurityGroup::IpPermissionCollection] Returns a
64
+ # collection of {IpPermission} objects that represents all of
65
+ # the permissions this security group has authorizations for.
66
+ def ip_permissions
67
+ IpPermissionCollection.new(self, :config => config)
68
+ end
69
+
70
+ # Adds ingress rules for ICMP pings. Defaults to 0.0.0.0/0 for
71
+ # the list of allowed IP ranges the ping can come from.
72
+ #
73
+ # security_group.allow_ping # anyone can ping servers in this group
74
+ #
75
+ # # only allow ping from a particular address
76
+ # security_group.allow_ping('123.123.123.123/0')
77
+ #
78
+ # @param [String] ip_ranges One or more IP ranges to allow ping from.
79
+ # Defaults to 0.0.0.0/0
80
+ def allow_ping *sources
81
+ sources << '0.0.0.0/0' if sources.empty?
82
+ authorize_ingress('icmp', -1, *sources)
83
+ end
84
+
85
+ # Removes ingress rules for ICMP pings. Defaults to 0.0.0.0/0 for
86
+ # the list of IP ranges to revoke.
87
+ #
88
+ # @param [String] ip_ranges One or more IP ranges to allow ping from.
89
+ # Defaults to 0.0.0.0/0
90
+ def disallow_ping *sources
91
+ sources << '0.0.0.0/0' if sources.empty?
92
+ revoke_ingress('icmp', -1, *sources)
93
+ end
94
+
95
+ # Adds an ingress rules to a security group.
96
+ #
97
+ # Each ingress exception is comprised of a protocol a port range
98
+ # and a list of sources.
99
+ #
100
+ #
101
+ # This example grants the whole internet (0.0.0.0/0) access to port 80
102
+ # over TCP (HTTP web traffic).
103
+ #
104
+ # security_groups['websrv'].authorize_ingress(:tcp, 80)
105
+ #
106
+ # In the following example we grant SSH access from a list of
107
+ # IP address.
108
+ #
109
+ # security_groups['appsrv'].authorize_ingress(:tcp, 22,
110
+ # '111.111.111.111/0', '222.222.222.222/0')
111
+ #
112
+ # You can also grant privileges to other security groups. This
113
+ # is a convenient shortcut for granting permissions to all EC2
114
+ # servers in a particular security group access.
115
+ #
116
+ # web = security_groups['httpservers']
117
+ # db = security_groups['dbservers']
118
+ #
119
+ # db.authorize_ingress(:tcp, 3306, web)
120
+ #
121
+ # You can specify port ranges as well:
122
+ #
123
+ # security_groups['ftpsvr'].authorize_ingress(:tcp, 20..21)
124
+ #
125
+ # You can even mix and match IP address and security groups.
126
+ #
127
+ # @param [String, Symbol] protocol Should be :tcp, :udp or :icmp
128
+ # or the string equivalent.
129
+ #
130
+ # @param [Integer, Range] ports The port (or port range) to allow
131
+ # ingress traffic over. You can pass a single integer (like 80)
132
+ # or a range (like 20..21).
133
+ #
134
+ # @param [Mixed] sources One or more CIDR IP addresses,
135
+ # security groups, or hashes. Hash values should
136
+ # have :group_id and :user_id keys/values. This is useful
137
+ # for when the security group belongs to another account. The
138
+ # user id should be the owner_id (account id) of the security
139
+ # group.
140
+ #
141
+ # @return [nil]
142
+ def authorize_ingress protocol, ports, *sources
143
+ permissions = format_permission(protocol, ports, sources)
144
+ client.authorize_security_group_ingress(
145
+ :group_id => id,
146
+ :ip_permissions => permissions)
147
+ nil
148
+ end
149
+
150
+ # @param see #authorize_ingress
151
+ # @return [nil]
152
+ def revoke_ingress protocol, ports, *sources
153
+ permissions = format_permission(protocol, ports, sources)
154
+ client.revoke_security_group_ingress(
155
+ :group_id => id,
156
+ :ip_permissions => permissions)
157
+ nil
158
+ end
159
+
160
+ # Deletes this security group.
161
+ #
162
+ # If you attempt to delete a security group that contains
163
+ # instances, or attempt to delete a security group that is referenced
164
+ # by another security group, an error is raised. For example, if
165
+ # security group B has a rule that allows access from security
166
+ # group A, security group A cannot be deleted until the rule is
167
+ # removed.
168
+ # @return [nil]
169
+ def delete
170
+ client.delete_security_group(:group_id => id)
171
+ nil
172
+ end
173
+
174
+ # @private
175
+ def resource_type
176
+ 'security-group'
177
+ end
178
+
179
+ # @private
180
+ def inflected_name
181
+ "group"
182
+ end
183
+
184
+ # @private
185
+ def self.describe_call_name
186
+ :describe_security_groups
187
+ end
188
+ def describe_call_name; self.class.describe_call_name; end
189
+
190
+ # @private
191
+ protected
192
+ def find_in_response(resp)
193
+ resp.security_group_index[id]
194
+ end
195
+
196
+ # @private
197
+ protected
198
+ def format_permission protocol, ports, sources
199
+
200
+ permission = {}
201
+ permission[:ip_protocol] = protocol.to_s.downcase
202
+ permission[:from_port] = Array(ports).first.to_i
203
+ permission[:to_port] = Array(ports).last.to_i
204
+
205
+ ip_ranges = []
206
+ groups = []
207
+
208
+ # default to 0.0.0.0/0
209
+ sources << '0.0.0.0/0' if sources.empty?
210
+
211
+ sources.each do |where|
212
+ case where
213
+
214
+ when String
215
+ ip_ranges << where
216
+
217
+ when SecurityGroup
218
+ groups << {:group_id => where.id, :user_id => where.owner_id}
219
+
220
+ when Hash
221
+ if where.has_key?(:group_id) and where.has_key?(:user_id)
222
+ groups << where
223
+ else
224
+ raise ArgumentError, 'invalid ingress ip permission, hashes ' +
225
+ 'must have :group_id and :user_id key/values'
226
+ end
227
+ else
228
+ raise ArgumentError, 'invalid ingress ip permission, ' +
229
+ 'expected CIDR IP addres or SecurityGroup'
230
+ end
231
+ end
232
+
233
+ unless ip_ranges.empty?
234
+ permission[:ip_ranges] = ip_ranges.collect{|ip| { :cidr_ip => ip } }
235
+ end
236
+
237
+ unless groups.empty?
238
+ permission[:user_id_group_pairs] = groups
239
+ end
240
+
241
+ [permission]
242
+
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,70 @@
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
+ require 'aws/model'
15
+
16
+ module AWS
17
+ class EC2
18
+ class SecurityGroup < Resource
19
+ class IpPermission
20
+
21
+ include Model
22
+
23
+ # @param protocol [:tcp, :udp, :icmp]
24
+ # @param port [Range,Integer] An integer or a range of integers
25
+ # to open ports for.
26
+ # @param [Hash] options
27
+ # @option options [Array] :ip_ranges An array of CIDR ip address
28
+ # to grant permission to.
29
+ # @option options [Array] :groups An array of SecurityGroup objects to
30
+ # grant permission to.
31
+ def initialize security_group, protocol, ports, options = {}
32
+ @security_group = security_group
33
+ @protocol = protocol.to_s.downcase.to_sym
34
+ @port_range = (Array(ports).first..Array(ports).last)
35
+ @ip_ranges = Array(options[:ip_ranges])
36
+ @groups = Array(options[:groups])
37
+ super
38
+ end
39
+
40
+ # @return [SecurityGroup] The security group this permission is
41
+ # authorized for.
42
+ attr_reader :security_group
43
+
44
+ # @return [Symbol] The protocol (:tcp, :udp, :icmp)
45
+ attr_reader :protocol
46
+
47
+ # @return [Range] The port range (e.g. 80..80, 4000..4010, etc)
48
+ attr_reader :port_range
49
+
50
+ # @return [Array] An array if string CIDR ip addresses.
51
+ attr_reader :ip_ranges
52
+
53
+ # @return [Array] An array of security groups that have been
54
+ # granted access with this permission.
55
+ attr_reader :groups
56
+
57
+ def authorize
58
+ sources = groups + ip_ranges
59
+ security_group.authorize_ingress(protocol, port_range, *sources)
60
+ end
61
+
62
+ def revoke
63
+ sources = groups + ip_ranges
64
+ security_group.revoke_ingress(protocol, port_range, *sources)
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,59 @@
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
+ require 'aws/model'
15
+
16
+ module AWS
17
+ class EC2
18
+ class SecurityGroup < Resource
19
+
20
+ class IpPermissionCollection
21
+
22
+ include Model
23
+ include Enumerable
24
+
25
+ attr_reader :security_group
26
+
27
+ def initialize(security_group, opts = {})
28
+ super
29
+ @security_group = security_group
30
+ end
31
+
32
+ def each
33
+ security_group.ip_permissions_list.each do |p|
34
+
35
+ groups = p.groups.collect do |group|
36
+ SecurityGroup.new(group.group_id,
37
+ :name => group.group_name,
38
+ :owner_id => group.user_id,
39
+ :config => config)
40
+ end
41
+
42
+ ip_ranges = p.ip_ranges.collect{|ip| ip.cidr_ip }
43
+
44
+ permission =
45
+ IpPermission.new(self, p.ip_protocol, [p.from_port, p.to_port],
46
+ :ip_ranges => ip_ranges,
47
+ :groups => groups,
48
+ :config => config)
49
+
50
+ yield(permission)
51
+
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,132 @@
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
+ require 'aws/model'
15
+ require 'aws/ec2/collection'
16
+ require 'aws/ec2/tagged_collection'
17
+ require 'aws/ec2/security_group'
18
+
19
+ module AWS
20
+ class EC2
21
+
22
+ # Represents all EC2 security groups in an AWS account.
23
+ class SecurityGroupCollection < Collection
24
+
25
+ include TaggedCollection
26
+
27
+ # Creates a new
28
+ # @param [String] name The name of the security group to create.
29
+ # @param [Hash] options
30
+ # @option options [String] :description An informal description
31
+ # of this security group. Accepts alphanumeric characters, spaces,
32
+ # dashes, and underscores. If left blank the description will be set
33
+ # to the name.
34
+ # @return [SecurityGroup]
35
+ def create name, options = {}
36
+
37
+ description = options[:description] || name
38
+
39
+ response = client.create_security_group(
40
+ :group_name => name,
41
+ :description => description)
42
+
43
+ SecurityGroup.new(response.group_id, {
44
+ :name => name,
45
+ :description => description,
46
+ :config => config })
47
+
48
+ end
49
+
50
+ # @param [String] group_id The group id of a security group.
51
+ # @return [SecurityGroup] The group with the given id.
52
+ def [] group_id
53
+ super
54
+ end
55
+
56
+ # Specify one or more criteria to filter security groups by.
57
+ # A subsequent call to #each will limit the security groups returned
58
+ # by the set of filters.
59
+ #
60
+ # If you supply multiple values to #filter then these values are
61
+ # treated as an OR condition. To return security groups named
62
+ # 'test' or 'fake':
63
+ #
64
+ # security_groups.filter('group-name', 'test', 'fake')
65
+ #
66
+ # If you want to and conditions together you need to chain calls to
67
+ # filter. To limit security groups to those with a name like
68
+ # 'test' and like 'ruby':
69
+ #
70
+ # security_groups.
71
+ # filter('group-name', '*test*').
72
+ # filter('group-name', '*ruby*').each do |group|
73
+ # #...
74
+ # end
75
+ #
76
+ # Note that * matches one or more characters and ? matches any one
77
+ # character.
78
+ #
79
+ # === Valid Filters
80
+ #
81
+ # * description - Description of the security group.
82
+ # * group-id - ID of the security group.
83
+ # * group-name - Name of the security group.
84
+ # * ip-permission.cidr - CIDR range that has been granted the
85
+ # permission.
86
+ # * ip-permission.from-port - Start of port range for the TCP and UDP
87
+ # protocols, or an ICMP type number.
88
+ # * ip-permission.group-name - Name of security group that has been
89
+ # granted the permission.
90
+ # * ip-permission.protocol - IP protocol for the permission. Valid
91
+ # values include 'tcp', 'udp', 'icmp' or a protocol number.
92
+ # * ip-permission.to-port - End of port range for the TCP and UDP
93
+ # protocols, or an ICMP code.
94
+ # * ip-permission.user-id - ID of AWS account that has been granted
95
+ # the permission.
96
+ # * owner-id - AWS account ID of the owner of the security group.
97
+ # * tag-key - Key of a tag assigned to the security group.
98
+ # * tag-value - Value of a tag assigned to the security group.
99
+ #
100
+ # @return [SecurityGroupCollection] A new collection that represents
101
+ # a subset of the security groups associated with this account.
102
+
103
+ # Yields once for each security group in this account.
104
+ #
105
+ # @yield [group]
106
+ # @yieldparam [SecurityGroup] group
107
+ # @return [nil]
108
+ def each &block
109
+
110
+ response = filtered_request(:describe_security_groups)
111
+ response.security_group_info.each do |info|
112
+
113
+ group = SecurityGroup.new(info.group_id,
114
+ :name => info.group_name,
115
+ :description => info.group_description,
116
+ :owner_id => info.owner_id,
117
+ :config => config)
118
+
119
+ yield(group)
120
+
121
+ end
122
+ nil
123
+ end
124
+
125
+ protected
126
+ def member_class
127
+ SecurityGroup
128
+ end
129
+
130
+ end
131
+ end
132
+ end