aws-sdk 1.0.4 → 1.1.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.
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
@@ -0,0 +1,48 @@
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/policy'
15
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # @private
20
+ class Policy < AWS::Policy
21
+
22
+ def to_h
23
+ hash = super
24
+ hash.delete('Id')
25
+ hash['Statement'].each do |statement|
26
+ statement.delete('Sid')
27
+ statement.delete('Principal')
28
+ end
29
+ hash
30
+ end
31
+
32
+ class Statement < AWS::Policy::Statement
33
+
34
+ ACTION_MAPPING = { }
35
+
36
+ protected
37
+ def resource_arn resource
38
+ case resource
39
+ when User then resource.arn
40
+ else super(resource)
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,191 @@
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/iam/collection'
15
+ require 'aws/iam/policy'
16
+ require 'aws/iam/errors'
17
+ require 'uri'
18
+
19
+ module AWS
20
+ class IAM
21
+
22
+ # Shared methods exposing a collection of policy documents
23
+ # associated with an IAM resource (a {User} or a {Group}). Policy
24
+ # collections can be constructed using {Group#policies} and
25
+ # {User#policies}.
26
+ module PolicyCollection
27
+
28
+ include Collection
29
+
30
+ # Retrieves a policy document by name.
31
+ #
32
+ # @param [String] name The name of the policy to retrieve.
33
+ #
34
+ # @return [Policy] The policy with the given name. If no such
35
+ # policy exists, this method returns +nil+.
36
+ def [] name
37
+ resp = get_policy(:policy_name => name)
38
+ Policy.from_json(URI.unescape(resp.policy_document))
39
+ rescue Errors::NoSuchEntity => e
40
+ nil
41
+ end
42
+
43
+ # Adds or replaces a policy document.
44
+ #
45
+ # @param [String] name The name of the policy document.
46
+ #
47
+ # @param [Policy,String] document The policy document. This can
48
+ # be a JSON string, or any object that responds to +to_json+.
49
+ # The {Policy} class provides a convenient way to construct
50
+ # policy documents that you can use with AWS IAM.
51
+ def []= name, document
52
+ document = document.to_json if document.respond_to?(:to_json) and
53
+ !document.kind_of?(String)
54
+ put_policy(:policy_name => name,
55
+ :policy_document => document)
56
+ end
57
+
58
+ # Deletes a policy by name. This method is idempotent; if no
59
+ # policy exists with the given name, the method does nothing.
60
+ #
61
+ # @param [String] name The name of the policy document.
62
+ def delete(name)
63
+ delete_policy(:policy_name => name)
64
+ nil
65
+ rescue Errors::NoSuchEntity => e
66
+ nil
67
+ end
68
+
69
+ # Retrieves multiple policy documents by name. This method
70
+ # makes one request to AWS IAM per argument.
71
+ #
72
+ # @param names Each argument is the name of a policy to retrieve.
73
+ #
74
+ # @return [Array<Policy>] An array containing the requested
75
+ # policy documents, in the same order as the argument list.
76
+ # If a requested policy does not exist, the array member
77
+ # corresponding to that argument will be +nil+.
78
+ def values_at(*names)
79
+ names.map { |n| self[n] }
80
+ end
81
+
82
+ # @return [Enumerator<String>] An enumerator for retrieving all
83
+ # the policy names that are currently associated with the
84
+ # resource.
85
+ def keys
86
+ enumerator(:names_only => true)
87
+ end
88
+ alias_method :names, :keys
89
+
90
+ # @return [Enumerator<Policy>] An enumerator for retrieving all
91
+ # the policy documents that are currently associated with the
92
+ # resource.
93
+ def values
94
+ enumerator(:values_only => true)
95
+ end
96
+
97
+ # Removes all policies from the collection.
98
+ def clear
99
+ keys.each { |k| delete(k) }
100
+ end
101
+
102
+ # @param [String] name The name of the policy to check.
103
+ #
104
+ # @return [Boolean] True if there is a policy with the given name.
105
+ def has_key? name
106
+ get_policy(:policy_name => name)
107
+ true
108
+ rescue Errors::NoSuchEntity => e
109
+ false
110
+ end
111
+ alias_method :include?, :has_key?
112
+ alias_method :key?, :has_key?
113
+ alias_method :member?, :has_key?
114
+
115
+ # @yield [name, policy] The name and document for each policy
116
+ # that is associated with the resource. Like +Hash#each+,
117
+ # this method is sensitive to the arity of the provided block;
118
+ # if the block takes two arguments, they will be the name and
119
+ # document. If it accepts only one argument, it will be an
120
+ # array containing the name and document.
121
+ def each opts = {}, &block
122
+ opts = opts.dup
123
+ names_only = opts.delete(:names_only)
124
+ values_only = opts.delete(:values_only)
125
+ super(client_opts(opts)) do |pn|
126
+ case
127
+ when names_only
128
+ yield pn
129
+ when values_only
130
+ yield self[pn]
131
+ when block.arity == 2
132
+ yield pn, self[pn]
133
+ else
134
+ yield [pn, self[pn]]
135
+ end
136
+ end
137
+ end
138
+
139
+ # @return [Hash] The contents of the collection as a hash.
140
+ def to_h
141
+ inject({}) do |hash, (name, policy)|
142
+ hash[name] = policy
143
+ hash
144
+ end
145
+ end
146
+
147
+ protected
148
+ def get_policy(opts = {})
149
+ client.send("get_#{resource_name}_policy",
150
+ client_opts(opts))
151
+ end
152
+
153
+ protected
154
+ def put_policy(opts = {})
155
+ client.send("put_#{resource_name}_policy",
156
+ client_opts(opts))
157
+ end
158
+
159
+ protected
160
+ def request_method
161
+ :"list_#{resource_name}_policies"
162
+ end
163
+
164
+ protected
165
+ def delete_policy(opts = {})
166
+ client.send("delete_#{resource_name}_policy",
167
+ client_opts(opts))
168
+ end
169
+
170
+ protected
171
+ def client_opts(opts = {})
172
+ Hash[[[:"#{resource_name}_name",
173
+ send(resource_name).name]]].merge(opts)
174
+ end
175
+
176
+ protected
177
+ def resource_name
178
+ raise NotImplementedError unless
179
+ self.class.name =~ /AWS::IAM::(.*)PolicyCollection$/
180
+ $1.downcase
181
+ end
182
+
183
+ protected
184
+ def each_item(response, &block)
185
+ response.policy_names.each(&block)
186
+ end
187
+
188
+ end
189
+
190
+ end
191
+ end
@@ -0,0 +1,27 @@
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/http/request'
15
+ require 'aws/authorize_v2'
16
+
17
+ module AWS
18
+ class IAM
19
+
20
+ # @private
21
+ class Request < AWS::Http::Request
22
+
23
+ include AuthorizeV2
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
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/resource'
15
+ require 'aws/inflection'
16
+
17
+ module AWS
18
+ class IAM
19
+
20
+ # @private
21
+ class Resource < AWS::Resource
22
+
23
+ # @return [Boolean] True if the resource exists.
24
+ def exists?
25
+ get_resource
26
+ rescue Errors::NoSuchEntity => e
27
+ false
28
+ else
29
+ true
30
+ end
31
+
32
+ # @private
33
+ protected
34
+ def update_resource attr, value
35
+ options = { :"#{self.class.update_prefix}#{attr.set_as}" => value }
36
+ client_method = update_resource_client_method
37
+ client.send(client_method, options.merge(resource_options))
38
+ end
39
+
40
+ # @private
41
+ protected
42
+ def get_resource attribute = nil
43
+ client.send(get_resource_client_method, resource_options)
44
+ end
45
+
46
+ # @private
47
+ protected
48
+ def get_resource_client_method
49
+ "get_#{ruby_name}"
50
+ end
51
+
52
+ # @private
53
+ protected
54
+ def update_resource_client_method
55
+ "update_#{ruby_name}"
56
+ end
57
+
58
+ class << self
59
+
60
+ # @private
61
+ def prefix_update_attributes prefix = 'new_'
62
+ @update_prefix = prefix
63
+ end
64
+
65
+ # @private
66
+ def update_prefix
67
+ @update_prefix
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,143 @@
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/iam/resource'
15
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # Respresents a server certificate.
20
+ #
21
+ # certificate = iam.server_certificates["MyCert"]
22
+ #
23
+ # You can use this class to get information about a certificate
24
+ # and to delete it.
25
+ class ServerCertificate < Resource
26
+
27
+ prefix_update_attributes
28
+
29
+ # @private
30
+ def initialize(name, opts={})
31
+ opts[:name] = name
32
+ super(opts)
33
+ end
34
+
35
+ # @attr [String] The name that identifies the server
36
+ # certificate.
37
+ mutable_attribute :name, :static => true, :as => :server_certificate_name
38
+
39
+ # @attr_reader [String] The stable and unique string identifying
40
+ # the server certificate.
41
+ attribute :id, :static => true, :as => :server_certificate_id
42
+
43
+ # @attr_reader [Time] The date when the server certificate was
44
+ # uploaded.
45
+ attribute :upload_date, :static => true
46
+
47
+ # @attr_reader [String] The Amazon Resource Name (ARN)
48
+ # specifying the server certificate. For more information
49
+ # about ARNs and how to use them in policies, see
50
+ # {http://docs.amazonwebservices.com/IAM/latest/UserGuide/index.html?Using_Identifiers.html
51
+ # Identifiers for IAM Entities} in <i>Using AWS Identity and
52
+ # Access Management</i>.
53
+ attribute :arn
54
+
55
+ # @attr [String] Path to the server certificate.
56
+ mutable_attribute :path do
57
+ translates_input do |path|
58
+ path = "/#{path}" unless path[0] == ?/
59
+ path = "#{path}/" unless path[-1] == ?/
60
+ path
61
+ end
62
+ end
63
+
64
+ # @attr_reader [String] The contents of the public key
65
+ # certificate.
66
+ attribute :certificate_body
67
+
68
+ # @attr_reader [String] The contents of the public key
69
+ # certificate chain.
70
+ attribute :certificate_chain
71
+
72
+ provider(:get_server_certificate) do |provider|
73
+ # for metadata attributes
74
+ provider.find do |resp|
75
+ cert, meta = response_objects(resp)
76
+ meta
77
+ end
78
+ provider.provides :name, :id, :upload_date, :arn, :path
79
+ end
80
+
81
+ provider(:get_server_certificate) do |provider|
82
+ # for data attributes
83
+ provider.find do |resp|
84
+ cert, meta = response_objects(resp)
85
+ cert
86
+ end
87
+ provider.provides :certificate_body, :certificate_chain
88
+ end
89
+
90
+ populates_from(:upload_server_certificate) do |resp|
91
+ resp.server_certificate_metadata if
92
+ resp.server_certificate_metadata.server_certificate_name == name
93
+ end
94
+
95
+ populates_from(:list_server_certificates) do |resp|
96
+ resp.server_certificate_metadata_list.find do |sc|
97
+ sc.server_certificate_name == name
98
+ end
99
+ end
100
+
101
+ # Deletes the specified server certificate.
102
+ #
103
+ # @note If you are using a server certificate with Elastic Load
104
+ # Balancing, deleting the certificate could have implications
105
+ # for your application. If Elastic Load Balancing doesn't
106
+ # detect the deletion of bound certificates, it may continue
107
+ # to use the certificates. This could cause Elastic Load
108
+ # Balancing to stop accepting traffic. We recommend that you
109
+ # remove the reference to the certificate from Elastic Load
110
+ # Balancing before using this command to delete the
111
+ # certificate. For more information, go to
112
+ # {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DeleteLoadBalancerListeners.html
113
+ # DeleteLoadBalancerListeners} in the _Elastic Load Balancing
114
+ # API Reference_.
115
+ #
116
+ # @return [nil]
117
+ def delete
118
+ client.delete_server_certificate(resource_options)
119
+ nil
120
+ end
121
+
122
+ # @private
123
+ protected
124
+ def resource_identifiers
125
+ [[:server_certificate_name, name]]
126
+ end
127
+
128
+ # extract response objects from get_server_certificate
129
+ private
130
+ def response_objects(resp)
131
+ if cert = resp.server_certificate and
132
+ meta = cert.server_certificate_metadata and
133
+ meta.server_certificate_name == name
134
+ [cert, meta]
135
+ else
136
+ [nil, nil]
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+ end