aws-sdk 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/ELB-2011-08-15.yml +380 -0
  3. data/lib/aws/api_config/SNS-2010-03-31.yml +2 -2
  4. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +5 -5
  5. data/lib/aws/core.rb +18 -3
  6. data/lib/aws/core/client_logging.rb +5 -6
  7. data/lib/aws/core/collection.rb +241 -0
  8. data/lib/aws/core/collection/batchable.rb +133 -0
  9. data/lib/aws/core/collection/limitable.rb +92 -0
  10. data/lib/aws/core/collection/simple.rb +89 -0
  11. data/lib/aws/core/configuration.rb +23 -0
  12. data/lib/aws/core/option_grammar.rb +2 -0
  13. data/lib/aws/core/page_result.rb +73 -0
  14. data/lib/aws/ec2/security_group.rb +154 -89
  15. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +1 -2
  16. data/lib/aws/ec2/security_group/{ip_permission_collection.rb → ingress_ip_permission_collection.rb} +4 -1
  17. data/lib/aws/ec2/security_group/ip_permission.rb +23 -45
  18. data/lib/aws/elb.rb +65 -0
  19. data/lib/aws/elb/availability_zone_collection.rb +138 -0
  20. data/lib/aws/elb/backend_server_policy_collection.rb +150 -0
  21. data/lib/aws/elb/client.rb +35 -0
  22. data/lib/aws/elb/client/xml.rb +33 -0
  23. data/lib/aws/elb/config.rb +18 -0
  24. data/lib/aws/elb/errors.rb +30 -0
  25. data/lib/aws/elb/instance_collection.rb +174 -0
  26. data/lib/aws/elb/listener.rb +189 -0
  27. data/lib/aws/elb/listener_collection.rb +119 -0
  28. data/lib/aws/elb/listener_opts.rb +45 -0
  29. data/lib/aws/elb/listener_spec.rb +14 -0
  30. data/lib/aws/elb/load_balancer.rb +255 -0
  31. data/lib/aws/elb/load_balancer_collection.rb +113 -0
  32. data/lib/aws/elb/load_balancer_policy.rb +93 -0
  33. data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
  34. data/lib/aws/elb/request.rb +23 -0
  35. data/lib/aws/iam/collection.rb +24 -26
  36. data/lib/aws/iam/group_user_collection.rb +21 -28
  37. data/lib/aws/iam/server_certificate_collection.rb +1 -37
  38. data/lib/aws/record.rb +1 -1
  39. data/lib/aws/record/base.rb +14 -1
  40. data/lib/aws/record/finder_methods.rb +4 -1
  41. data/lib/aws/record/validations.rb +73 -32
  42. data/lib/aws/{core/api_config_transform.rb → record/validators/method.rb} +9 -12
  43. data/lib/aws/s3/bucket_collection.rb +6 -4
  44. data/lib/aws/s3/client.rb +37 -6
  45. data/lib/aws/s3/config.rb +3 -1
  46. data/lib/aws/s3/prefixed_collection.rb +1 -2
  47. data/lib/aws/s3/presigned_post.rb +37 -4
  48. data/lib/aws/s3/s3_object.rb +93 -1
  49. data/lib/aws/simple_db/domain.rb +8 -0
  50. data/lib/aws/simple_db/item.rb +15 -0
  51. data/lib/aws/simple_db/item_collection.rb +255 -201
  52. data/lib/aws/simple_db/item_data.rb +1 -1
  53. data/lib/aws/simple_email_service/client.rb +0 -1
  54. data/lib/aws/sns/client.rb +0 -1
  55. metadata +107 -55
  56. data/lib/aws/core/collections.rb +0 -229
  57. data/lib/aws/simple_email_service/client/options.rb +0 -21
  58. data/lib/aws/sns/client/options.rb +0 -21
@@ -30,9 +30,8 @@ module AWS
30
30
 
31
31
  groups = p.groups.collect do |group|
32
32
  SecurityGroup.new(group.group_id,
33
- :name => group.group_name,
34
33
  :owner_id => group.user_id,
35
- :vpc_id => group.vpc_id,
34
+ :vpc_id => security_group.vpc_id,
36
35
  :config => config)
37
36
  end
38
37
 
@@ -15,7 +15,7 @@ module AWS
15
15
  class EC2
16
16
  class SecurityGroup < Resource
17
17
 
18
- class IpPermissionCollection
18
+ class IngressIpPermissionCollection
19
19
 
20
20
  include Core::Model
21
21
  include Enumerable
@@ -53,6 +53,9 @@ module AWS
53
53
 
54
54
  end
55
55
 
56
+ # alias for ingress permissions
57
+ IpPermissionCollection = IngressIpPermissionCollection
58
+
56
59
  end
57
60
  end
58
61
  end
@@ -19,15 +19,21 @@ module AWS
19
19
  include Core::Model
20
20
 
21
21
  # @param protocol [:tcp, :udp, :icmp]
22
+ #
22
23
  # @param port [Range,Integer] An integer or a range of integers
23
24
  # to open ports for.
25
+ #
24
26
  # @param [Hash] options
27
+ #
25
28
  # @option options [Array] :ip_ranges An array of CIDR ip address
26
29
  # to grant permission to.
30
+ #
27
31
  # @option options [Array] :groups An array of SecurityGroup objects to
28
32
  # grant permission to.
33
+ #
29
34
  # @option options [Boolean] :egress (false) When true this IpPermission
30
35
  # is assumed to be an egree permission.
36
+ #
31
37
  def initialize security_group, protocol, ports, options = {}
32
38
 
33
39
  @security_group = security_group
@@ -75,33 +81,13 @@ module AWS
75
81
  # Authorizes this permission from its security group.
76
82
  # @return [IpPermission] Returns self
77
83
  def authorize
78
-
79
- method = egress? ?
80
- :authorize_security_group_egress :
81
- :authorize_security_group_ingress
82
-
83
- client.send(method,
84
- :group_id => security_group.id,
85
- :ip_permissions => [format_permission])
86
-
87
- self
88
-
84
+ update_sg(egress? ? :authorize_egress : :authorize_ingress)
89
85
  end
90
86
 
91
87
  # Revokes this permission from its security group.
92
88
  # @return [IpPermission] Returns self
93
89
  def revoke
94
-
95
- method = egress? ?
96
- :revoke_security_group_egress :
97
- :revoke_security_group_ingress
98
-
99
- client.send(method,
100
- :group_id => security_group.id,
101
- :ip_permissions => [format_permission])
102
-
103
- self
104
-
90
+ update_sg(egress? ? :revoke_egress : :revoke_ingress)
105
91
  end
106
92
 
107
93
  # @return [Boolean] Returns true if the other IpPermission matches
@@ -118,32 +104,24 @@ module AWS
118
104
 
119
105
  alias_method :eql?, :==
120
106
 
121
- # @private
122
107
  protected
123
- def format_permission
124
-
125
- permission = {}
126
-
127
- permission[:ip_protocol] = protocol == :any ? '-1' : protocol.to_s
128
-
129
- if port_range
130
- permission[:from_port] = port_range.first
131
- permission[:to_port] = port_range.last
132
- end
133
-
134
- unless ip_ranges.empty?
135
- permission[:ip_ranges] = ip_ranges.collect{|ip| { :cidr_ip => ip } }
108
+ def update_sg method
109
+
110
+ sources = []
111
+ sources += ip_ranges
112
+ sources += groups
113
+
114
+ if egress?
115
+ opts = {}
116
+ opts[:protocol] = protocol
117
+ opts[:ports] = port_range if port_range
118
+ sources << opts
119
+ security_group.send(method, *sources)
120
+ else
121
+ security_group.send(method, protocol, port_range, *sources)
136
122
  end
137
123
 
138
- unless groups.empty?
139
- permission[:user_id_group_pairs] = groups.inject([]) do |list,group|
140
- list << { :group_id => group.id, :user_id => group.owner_id }
141
- list
142
- end
143
- end
144
-
145
- permission
146
-
124
+ self
147
125
  end
148
126
 
149
127
  end
@@ -0,0 +1,65 @@
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/core'
15
+ require 'aws/elb/config'
16
+
17
+ module AWS
18
+
19
+ # Provides an expressive, object-oriented interface to Elastic Load
20
+ # Balancing (ELB).
21
+ #
22
+ # == Credentials
23
+ #
24
+ # You can setup default credentials for all AWS services via
25
+ # AWS.config:
26
+ #
27
+ # AWS.config(
28
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
29
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
30
+ #
31
+ # Or you can set them directly on the ELB interface:
32
+ #
33
+ # elb = AWS::ELB.new(
34
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
35
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
36
+ #
37
+ class ELB
38
+
39
+ AWS.register_autoloads(self) do
40
+ autoload :AvailabilityZoneCollection, 'availability_zone_collection'
41
+ autoload :BackendServerPolicyCollection, 'backend_server_policy_collection'
42
+ autoload :Client, 'client'
43
+ autoload :Errors, 'errors'
44
+ autoload :InstanceCollection, 'instance_collection'
45
+ autoload :ListenerOpts, 'listener_opts'
46
+ autoload :Listener, 'listener'
47
+ autoload :ListenerCollection, 'listener_collection'
48
+ autoload :LoadBalancer, 'load_balancer'
49
+ autoload :LoadBalancerCollection, 'load_balancer_collection'
50
+ autoload :LoadBalancerPolicy, 'load_balancer_policy'
51
+ autoload :LoadBalancerPolicyCollection, 'load_balancer_policy_collection'
52
+ autoload :Request, 'request'
53
+ end
54
+
55
+ include Core::ServiceInterface
56
+
57
+ # @return [LoadBalancerCollection] Returns a collection that represents
58
+ # all of your load balancers.
59
+ def load_balancers
60
+ LoadBalancerCollection.new(:config => config)
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,138 @@
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
+ class ELB
16
+
17
+ # A collection that help maanage the availability zones for
18
+ # a load balancer.
19
+ #
20
+ # load_balancer = AWS::ELB.new.load_balancers['my-load-balancer']
21
+ #
22
+ # zones = load_balancer.availability_zones
23
+ #
24
+ # # adding zones
25
+ # zones.enable('us-east-1b', 'us-east-1c')
26
+ #
27
+ # # removing zones
28
+ # zones.disable('us-east-1b')
29
+ #
30
+ # # enumerating enabled zones
31
+ # zones.each do |zone|
32
+ # puts zone.name
33
+ # end
34
+ #
35
+ class AvailabilityZoneCollection
36
+
37
+ include Core::Collection::Simple
38
+
39
+ # @param [LoadBalancer] The load balancer this list of availability
40
+ # zones belongs to.
41
+ def initialize load_balancer, options = {}
42
+ @load_balancer = load_balancer
43
+ super
44
+ end
45
+
46
+ # @return [LoadBalancer] Returns the load balancer this list describes.
47
+ attr_reader :load_balancer
48
+
49
+ # Adds one or more EC2 Availability Zones to the load balancer.
50
+ #
51
+ # load_balancer.availability_zones.enable("us-east-1a", "us-east-1b")
52
+ #
53
+ # You can also pass {EC2::AvailabilityZone} objects:
54
+ #
55
+ # # enable all availabilty zones for this region
56
+ # zones = AWS::EC2.new.availability_zones.to_a
57
+ # load_balancer.availability_zones.enable(zones)
58
+ #
59
+ # The load balancer evenly distributes requests across all its
60
+ # registered availability zones that contain instances. As a result,
61
+ # the client must ensure that its load balancer is appropriately
62
+ # scaled for each registered Availability Zone.
63
+ #
64
+ # @param [String,EC2::AvailabilityZone] availability_zones One or more
65
+ # availability zone names (strings) or objects {EC2::AvailabilityZone}.
66
+ #
67
+ # @return [nil]
68
+ #
69
+ def enable *availability_zones
70
+
71
+ names = availability_zones.flatten.collect do |av|
72
+ av.is_a?(EC2::AvailabilityZone) ? av.name : av.to_s
73
+ end
74
+
75
+ client.enable_availability_zones_for_load_balancer(
76
+ :load_balancer_name => load_balancer.name,
77
+ :availability_zones => names)
78
+
79
+ nil
80
+
81
+ end
82
+
83
+ # Removes the specified EC2 availability zones from the set of
84
+ # configured availability zones for the load balancer.
85
+ #
86
+ # load_balancer.availability_zones.disable("us-east-1a", "us-east-1b")
87
+ #
88
+ # You can also pass {EC2::AvailabilityZone} objects:
89
+ #
90
+ # # disable all availabilty zones
91
+ # zones = AWS::EC2.new.availability_zones.to_a
92
+ # load_balancer.availability_zones.disable(zones)
93
+ #
94
+ # There must be at least one availability zone registered with a
95
+ # load balancer at all times. A client cannot remove all the availability
96
+ # zones from a load balancer. Once an availability zone is removed,
97
+ # all the instances registered with the load balancer that are in the
98
+ # removed availability zone go into the out of service state.
99
+ #
100
+ # Upon availability zone removal, the load balancer attempts to
101
+ # equally balance the traffic among its remaining usable availability
102
+ # zones. Trying to remove an availability zone that was not
103
+ # associated with the load balancer does nothing.
104
+ #
105
+ # @param [String,EC2::AvailabilityZone] availability_zones One or more
106
+ # availability zone names (strings) or objects {EC2::AvailabilityZone}.
107
+ #
108
+ # @return [nil]
109
+ #
110
+ def disable *availability_zones
111
+
112
+ names = availability_zones.flatten.collect do |av|
113
+ av.is_a?(EC2::AvailabilityZone) ? av.name : av.to_s
114
+ end
115
+
116
+ client.disable_availability_zones_for_load_balancer(
117
+ :load_balancer_name => load_balancer.name,
118
+ :availability_zones => names)
119
+
120
+ nil
121
+
122
+ end
123
+
124
+ protected
125
+ def _each_item options = {}, &block
126
+ load_balancer.availability_zone_names.each do |az_name|
127
+
128
+ availability_zone = EC2::AvailabilityZone.new(
129
+ az_name, :config => config)
130
+
131
+ yield(availability_zone)
132
+
133
+ end
134
+ end
135
+
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,150 @@
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
+ class ELB
16
+
17
+ # Helps manage policies assigned to backend server instnace ports.
18
+ #
19
+ # == Creating a Backend Server Policy
20
+ #
21
+ # Creating a backend server policy can be a bit tricky. A
22
+ # BackendServerAuthenticationPolicyType policy only has one
23
+ # attribute, a list of public key policies.
24
+ #
25
+ # Before you can assign a policy to a backend server instance port you
26
+ # must create on of the appropriate type:
27
+ #
28
+ # # step 1, create one (or more) PublicKeyPolicyType policies
29
+ #
30
+ # public_key1 = <<-KEY
31
+ # -----BEGIN CERTIFICATE-----
32
+ # MIICaTCCAdICCQDuvCF4erLGSjANBgkqhkiG9w0BAQUFADB5MQswCQYDVQQGEwJa
33
+ # WjENMAsGA1UECBMERkFLRTENMAsGA1UEBxMERkFLRTENMAsGA1UEChMERkFLRTEN
34
+ # MAsGA1UECxMERkFLRTENMAsGA1UEAxMERkFLRTEfMB0GCSqGSIb3DQEJARYQZmFr
35
+ # ZUBleGFtcGxlLmNvbTAeFw0xMTA4MTAyMjE0NDVaFw0xMjA4MDkyMjE0NDVaMHkx
36
+ # CzAJBgNVBAYTAlpaMQ0wCwYDVQQIEwRGQUtFMQ0wCwYDVQQHEwRGQUtFMQ0wCwYD
37
+ # VQQKEwRGQUtFMQ0wCwYDVQQLEwRGQUtFMQ0wCwYDVQQDEwRGQUtFMR8wHQYJKoZI
38
+ # hvcNAQkBFhBmYWtlQGV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
39
+ # iQKBgQC4vy7K2LCgYJs7AbxdanPEwL4KLC9gi1LqzkRWShEaz8COUZswcOkevLQy
40
+ # SMFTXAvmH1FVqNO97wVG6ydxi+LNE7Jub62QQnsK420y+nXRTytxrboH1eAiAIEt
41
+ # ZoUKaOymfAN8l/MJbcPH0rTYNdni99B+UMPWmFeRg/BeWiy2hwIDAQABMA0GCSqG
42
+ # SIb3DQEBBQUAA4GBAD+VNA6ia8TXa2lJgvmoGYCLGcCaccz7Nv/u4/oqv8qMPvdZ
43
+ # 5DZxDLIExOSHiFGwWg5m8NgcirH2diveyRBgNhgC6S6DntkEMvAV0yvaQgHtUO53
44
+ # o50MymfqtoVcebZcXbiDVAXW1cPEHKLBXecX6/LZ+GOzEsUOxgt7Xs9uabqp
45
+ # -----END CERTIFICATE-----
46
+ # KEY
47
+ #
48
+ # public_key_policy = load_balancer.policies.create("pkp",
49
+ # 'PublicKeyPolicyType', 'PublicKey' => public_key.strip)
50
+ #
51
+ # # step 2, create the backend server policy, passing the public key policy
52
+ #
53
+ # name = 'backend-policy'
54
+ # type = 'BackendServerAuthenticationPolicyType'
55
+ # attributes = {
56
+ # # note: you can pass more than one public key policy here
57
+ # 'PublicKeyPolicyName' => [public_key_policy]
58
+ # }
59
+ #
60
+ # backend_policy = @load_balancer.policies.create(name, type, attributes)
61
+ # 'BackendServerAuthenticationPolicyType', attributes)
62
+ #
63
+ # Once you have created a backend server authentication policy, you
64
+ # can assign it to a backend instance port:
65
+ #
66
+ # load_balancer.backend_server_policies[80] = backend_policy
67
+ #
68
+ # If you want to remove the policy you can pass nil instead.
69
+ #
70
+ # # removes the policy from instance port 80
71
+ # load_balancer.backend_server_policies[80] = nil
72
+ #
73
+ # You can also get the current policy:
74
+ #
75
+ # load_balancer.backend_server_policies[80] # returns a policy or nil
76
+ #
77
+ class BackendServerPolicyCollection
78
+
79
+ include Core::Collection::Simple
80
+
81
+ def initialize load_balancer, options = {}
82
+ @load_balancer = load_balancer
83
+ super
84
+ end
85
+
86
+ # @return [LoadBalancer]
87
+ attr_reader :load_balancer
88
+
89
+ # Returns the policy currently assigned to the given instance port.
90
+ #
91
+ # @param [Integer] instance_port The backend server port to
92
+ # get the currently policy of.
93
+ #
94
+ # @return [LoadBalancerPolicy,nil] Returns the load balancer policy
95
+ # currently assigned to the given instance port. Returns nil if
96
+ # no policy has been assigned.
97
+ #
98
+ def [] instance_port
99
+ enum(:instance_port => instance_port).first
100
+ end
101
+
102
+ # Sets the policy for the given backend server instance port.
103
+ #
104
+ # @param [Integer] instance_port The instance port you want to set
105
+ # backend server policies for.
106
+ #
107
+ # @param [String,LoadBalancerPolicy,nil] policies Load balancer policy
108
+ # name or object. Passing nil removes the current policy.
109
+ #
110
+ # @return [nil]
111
+ #
112
+ def []= instance_port, policy
113
+
114
+ client.set_load_balancer_policies_for_backend_server(
115
+ :load_balancer_name => load_balancer.name,
116
+ :instance_port => instance_port.to_i,
117
+ :policy_names => [policy_name(policy)].compact)
118
+
119
+ nil
120
+
121
+ end
122
+
123
+ protected
124
+ def policy_name policy
125
+ case policy
126
+ when nil then nil
127
+ when LoadBalancerPolicy then policy.name
128
+ else policy.to_s
129
+ end
130
+ end
131
+
132
+ protected
133
+ def _each_item options = {}
134
+
135
+ instance_port = options[:instance_port]
136
+
137
+ load_balancer.backend_server_descriptions.each do |desc|
138
+ if instance_port.nil? or desc.instance_port == instance_port
139
+ desc.policy_names.collect do |policy_name|
140
+ policy = load_balancer.policies[policy_name]
141
+ yield(policy)
142
+ end
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+ end
150
+ end