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,174 @@
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/server_certificate'
16
+
17
+ module AWS
18
+ class IAM
19
+
20
+ # A collection that provides access to IAM server certificates
21
+ # belonging to this account.
22
+ #
23
+ # iam = AWS::IAM.new
24
+ # certificates = iam.server_certificates
25
+ #
26
+ # == Uploading A Server Certificate
27
+ #
28
+ # You can upload any valid, signed certificate using {#upload}.
29
+ #
30
+ # certificates.upload(:name => "MyCert",
31
+ # :certificate_body => my_certificate_body,
32
+ # :private_key => my_private_key)
33
+ #
34
+ # For information about generating a server certificate for use
35
+ # with IAM, see
36
+ # {http://docs.amazonwebservices.com/IAM/latest/UserGuide/InstallCert.html
37
+ # Creating and Uploading Server Certificates} in <i>Using AWS
38
+ # Identity and Access Management</i>.
39
+ #
40
+ # == Getting a Server Certificate by Name
41
+ #
42
+ # You can get a reference to a server certificate using array notation:
43
+ #
44
+ # certificate = certificates['MyCert']
45
+ #
46
+ # == Enumerating Server Certificates
47
+ #
48
+ # Server certificate collections can also be used to enumerate
49
+ # certificates:
50
+ #
51
+ # certificates.each do |cert|
52
+ # puts cert.name
53
+ # end
54
+ #
55
+ # You can limit the certificates returned by passing a +:prefix+
56
+ # option to any of the enumerator methods. When you pass a
57
+ # prefix, only the certificates whose paths start with the given
58
+ # string will be returned.
59
+ class ServerCertificateCollection
60
+
61
+ include Collection::WithPrefix
62
+
63
+ # Uploads a server certificate entity for the AWS account. The
64
+ # server certificate entity includes a public key certificate, a
65
+ # private key, and an optional certificate chain, which should
66
+ # all be PEM-encoded.
67
+ #
68
+ # @param [Hash] options Options for uploading the certificate.
69
+ # +:name+, +:certificate_body+, and +:private_key+ are
70
+ # required.
71
+ #
72
+ # @option options [String] :certificate_body The contents of the
73
+ # public key certificate in PEM-encoded format.
74
+ #
75
+ # @option options [String] :name The name for the server
76
+ # certificate. Do not include the path in this value.
77
+ #
78
+ # @option options [String] :path The path for the server
79
+ # certificate. For more information about paths, see
80
+ # {http://docs.amazonwebservices.com/IAM/latest/UserGuide/index.html?Using_Identifiers.html
81
+ # Identifiers for IAM Entities} in <i>Using AWS Identity and
82
+ # Access Management</i>.
83
+ #
84
+ # @option options [String] :private_key The contents of the
85
+ # private key in PEM-encoded format.
86
+ #
87
+ # @option options [String] :certificate_chain The contents of
88
+ # the certificate chain. This is typically a concatenation of
89
+ # the PEM-encoded public key certificates of the chain.
90
+ #
91
+ # @return [ServerCertificate] The newly created server
92
+ # certificate.
93
+ def upload(options = {})
94
+ client_opts = options.dup
95
+ client_opts[:server_certificate_name] = client_opts.delete(:name)
96
+
97
+ if path = client_opts[:path]
98
+ client_opts[:path] = "/#{path}/".
99
+ sub(%r{^//}, "/").
100
+ sub(%r{//$}, "/")
101
+ end
102
+
103
+ resp = client.upload_server_certificate(client_opts)
104
+ ServerCertificate.new(resp.server_certificate_metadata.
105
+ server_certificate_name,
106
+ :config => config)
107
+ end
108
+ alias_method :create, :upload
109
+
110
+ # Returns a reference to the server certificate with the given
111
+ # name:
112
+ #
113
+ # certificate = iam.server_certificates['MyCert']
114
+ #
115
+ # @param [String] name Name of the server certificate.
116
+ #
117
+ # @return [ServerCertificate] Returns a reference to the named
118
+ # server certificate.
119
+ def [] name
120
+ ServerCertificate.new(name, :config => config)
121
+ end
122
+
123
+ # Yields once for each server certificate
124
+ #
125
+ # You can limit the number of certificates yielded using
126
+ # +:limit+ and +:path_prefix+.
127
+ #
128
+ # @param [Hash] options
129
+ #
130
+ # @option options [String] :path_prefix ('/') A path prefix that
131
+ # filters according to the path of the certificate.
132
+ #
133
+ # @option options [Integer] :limit The maximum number of
134
+ # certificates to yield.
135
+ #
136
+ # @option options [Integer] :batch_size The maximum number of
137
+ # certificates to retrieve in each service request.
138
+ #
139
+ # @yieldparam [ServerCertificate] certificate
140
+ # @return [nil]
141
+ def each options = {}, &block
142
+ super(options, &block)
143
+ end
144
+
145
+ # Returns an enumerable object for this collection. This can be
146
+ # useful if you want to call an enumerable method that does
147
+ # not accept options (e.g. +collect+, +first+, etc).
148
+ #
149
+ # certificates.enumerator(:path_prefix => '/production').
150
+ # collect(&:name)
151
+ #
152
+ # @param (see #each)
153
+ # @option (see #each)
154
+ # @return [Enumerator]
155
+ def enumerator options = {}
156
+ super(options)
157
+ end
158
+
159
+ # @private
160
+ protected
161
+ def each_item(response, &block)
162
+ response.server_certificate_metadata_list.each do |sc|
163
+ certificate = ServerCertificate.new_from(:list_server_certificates,
164
+ sc,
165
+ sc.server_certificate_name,
166
+ :config => config)
167
+ yield(certificate)
168
+ end
169
+ end
170
+
171
+ end
172
+
173
+ end
174
+ end
@@ -0,0 +1,171 @@
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
+ require 'aws/iam/resource'
14
+
15
+ module AWS
16
+ class IAM
17
+
18
+ # Signing certificates can be activated and deactivated.
19
+ # By default, newly-uploaded certifictes are active.
20
+ #
21
+ # certificate = iam.signing_certificates.upload(cert_body)
22
+ # certificate.status
23
+ # #=> :active
24
+ #
25
+ # certificate.deactivate!
26
+ # certificate.active?
27
+ # #=> false
28
+ #
29
+ # == Contents
30
+ #
31
+ # You can access the certificate contents you uploaded:
32
+ #
33
+ # > puts certificate.contents
34
+ # -----BEGIN CERTIFICATE-----
35
+ # MIICdzCCAeCgAwIBAgIFGS4fY6owDQYJKoZIhvcNAQEFBQAwUzELMAkGA1UEBhMC
36
+ # ......
37
+ # Glli79yh87PRi0vNDlFEoHXNynkvC/c4TiWruZ4haM9BR9EdWr1DBNNu73ui093K
38
+ # F9TbdXSWdgMl7E0=
39
+ # -----END CERTIFICATE-----
40
+ #
41
+ # == User
42
+ #
43
+ # A certificate can also return the user it belongs to. If the certificate
44
+ # belongs to the AWS account, then {#user} will return +nil+.
45
+ #
46
+ # user = iam.users['someuser'].signing_certificates.first
47
+ # user.name
48
+ # #=> 'someuser'
49
+ #
50
+ # @attr_reader [String] contents Returns the contents of this
51
+ # signing certificate.
52
+ #
53
+ # @attr_reader [Symbol] status The status of this signing
54
+ # certificate. Status may be +:active+ or +:inactive+.
55
+ #
56
+ class SigningCertificate < Resource
57
+
58
+ # @param [String] certificate_id The id of the signing certificate.
59
+ # @param [Hash] options
60
+ # @param [User] :user The user this signing certificate belongs to.
61
+ def initialize certificate_id, options = {}
62
+ @id = certificate_id
63
+ @user = options[:user]
64
+ @user ? super(@user, options) : super(options)
65
+ end
66
+
67
+ # @return [String] Returns the signing certificate's ID.
68
+ attr_reader :id
69
+
70
+ # @return [User,nil] Returns the user this cerficiate belongs to.
71
+ # Returns +nil+ if the cerficiate is a root credential for the
72
+ # account. If the configured credentials belong to an IAM user,
73
+ # then that user is the implied owner.
74
+ attr_reader :user
75
+
76
+ attribute :contents, :as => :certificate_body, :static => true
77
+
78
+ mutable_attribute :status, :to_sym => true
79
+
80
+ protected :status=
81
+
82
+ populates_from(
83
+ :upload_signing_certificate,
84
+ :update_signing_certificate
85
+ ) do |resp|
86
+ resp.certificate if matches_response_object?(resp.certificate)
87
+ end
88
+
89
+ populates_from(:list_signing_certificates) do |resp|
90
+ resp.certificates.find {|c| matches_response_object?(c) }
91
+ end
92
+
93
+ # @return [String,nil] Returns the name of the user this certificate
94
+ # belogns to. If the certificate belongs to the account, +nil+ is
95
+ # returned.
96
+ def user_name
97
+ @user ? @user.name : nil
98
+ end
99
+
100
+ # @return [Boolean] Returns true if this signing certificate is active.
101
+ def active?
102
+ status == :active
103
+ end
104
+
105
+ # @return [Boolean] Returns true if this signing certificate is inactive.
106
+ def inactive?
107
+ status == :inactive
108
+ end
109
+
110
+ # Activates this signing cerificate.
111
+ #
112
+ # @example
113
+ # signing_certificate.activate!
114
+ # signing_certificate.status
115
+ # # => :active
116
+ #
117
+ # @return [nil]
118
+ def activate!
119
+ self.status = 'Active'
120
+ nil
121
+ end
122
+
123
+ # Deactivates this signing cerificate.
124
+ #
125
+ # @example
126
+ # signing_certificate.deactivate!
127
+ # signing_certificate.status
128
+ # # => :inactive
129
+ #
130
+ # @return [nil]
131
+ def deactivate!
132
+ self.status = 'Inactive'
133
+ nil
134
+ end
135
+
136
+ # Deletes the signing certificate.
137
+ def delete
138
+ client.delete_signing_certificate(resource_options)
139
+ nil
140
+ end
141
+
142
+ # @private
143
+ protected
144
+ def resource_identifiers
145
+ identifiers = []
146
+ identifiers << [:certificate_id, id]
147
+ identifiers << [:user_name, user.name] if user
148
+ identifiers
149
+ end
150
+
151
+ # IAM does not provide a request for "get signing certificate".
152
+ # Also note, we do not page the response. This is because
153
+ # restrictions on how many certificates an account / user may
154
+ # have is fewer than one page of results.
155
+ # @private
156
+ protected
157
+ def get_resource attribute
158
+ options = user ? { :user_name => user.name } : {}
159
+ client.list_signing_certificates(options)
160
+ end
161
+
162
+ # @private
163
+ protected
164
+ def matches_response_object? obj
165
+ user_name = obj.respond_to?(:user_name) ? obj.user_name : nil
166
+ obj.certificate_id == self.id and user_name == self.user_name
167
+ end
168
+
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,134 @@
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
+ require 'aws/iam/collection'
14
+ require 'aws/iam/signing_certificate'
15
+
16
+ module AWS
17
+ class IAM
18
+
19
+ # This is the primary interface for uploading X.509 signing certificates
20
+ # to an AWS account or an IAM user.
21
+ #
22
+ # iam = AWS::IAM.new
23
+ #
24
+ # # upload a certificate for the AWS account:
25
+ # iam.signing_certificates.upload(<<-CERT)
26
+ # -----BEGIN CERTIFICATE-----
27
+ # MIICdzCCAeCgAwIBAgIFGS4fY6owDQYJKoZIhvcNAQEFBQAwUzELMAkGA1UEBhMC
28
+ # ......
29
+ # Glli79yh87PRi0vNDlFEoHXNynkvC/c4TiWruZ4haM9BR9EdWr1DBNNu73ui093K
30
+ # F9TbdXSWdgMl7E0=
31
+ # -----END CERTIFICATE-----
32
+ # CERT
33
+ #
34
+ # If you want to work with an IAM user's certificates just use the
35
+ # signing certificate interface on a user:
36
+ #
37
+ # user = iam.users['someuser']
38
+ # user.signing_certificates.upload(cert_body)
39
+ #
40
+ class SigningCertificateCollection
41
+
42
+ include Collection
43
+
44
+ # @param [Hash] options
45
+ # @option options [User] :user (nil) When +:user+ is provided the
46
+ # collection will represents the signing certificates belonging only
47
+ # to that user. When +:user+ is omitted the collection will manage
48
+ # root credentials on the AWS account (instead those belonging to a
49
+ # particular user).
50
+ def initialize options = {}
51
+ @user = options[:user]
52
+ @user ? super(@user, options) : super(options)
53
+ end
54
+
55
+ # @return [User,nil] Returns the user this collection belongs to.
56
+ # Returns +nil+ if the collection represents the root credentials
57
+ # for the account. If the configured credentials belong to an
58
+ # IAM user, then that user is the implied owner.
59
+ attr_reader :user
60
+
61
+ # @param [String] certificate_body The contents of the signing
62
+ # certificate.
63
+ # @return [SigningCertificate] Returns the newly created signing
64
+ # certificate.
65
+ def upload certificate_body
66
+
67
+ options = {}
68
+ options[:certificate_body] = certificate_body
69
+ options[:user_name] = user.name if user
70
+
71
+ resp = client.upload_signing_certificate(options)
72
+
73
+ SigningCertificate.new_from(:upload_signing_certificate,
74
+ resp.certificate, resp.certificate.certificate_id, new_options)
75
+
76
+ end
77
+
78
+ alias_method :create, :upload
79
+
80
+ # @param [String] certificate_id The ID of the signing certificate.
81
+ # @return [SigningCertificate] Returns a reference to the signing
82
+ # certificate with the given certificate ID.
83
+ def [] certificate_id
84
+ SigningCertificate.new(certificate_id.to_s, new_options)
85
+ end
86
+
87
+ # Deletes all of the signing certificates from this collection.
88
+ # @return [nil]
89
+ def clear
90
+ each do |certificate|
91
+ certificate.delete
92
+ end
93
+ nil
94
+ end
95
+
96
+ # Yields once for each signing certificate.
97
+ #
98
+ # You can limit the number of certificates yielded using +:limit+.
99
+ #
100
+ # @param [Hash] options
101
+ # @option options [Integer] :limit The maximum number of certificates
102
+ # to yield.
103
+ # @option options [Integer] :batch_size The maximum number of
104
+ # certificates received each service reqeust.
105
+ # @yieldparam [SigningCertificate] signing_certificate
106
+ # @return [nil]
107
+ def each options = {}, &block
108
+ each_options = options.dup
109
+ each_options[:user_name] = user.name if user
110
+ super(each_options, &block)
111
+ end
112
+
113
+ # @private
114
+ protected
115
+ def each_item response, &block
116
+ response.certificates.each do |item|
117
+
118
+ cert = SigningCertificate.new_from(:list_signing_certificates,
119
+ item, item.certificate_id, new_options)
120
+
121
+ yield(cert)
122
+
123
+ end
124
+ end
125
+
126
+ # @private
127
+ protected
128
+ def new_options
129
+ user ? { :user => user } : { :config => config }
130
+ end
131
+
132
+ end
133
+ end
134
+ end