right_aws 2.0.0 → 2.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 (50) hide show
  1. data/History.txt +22 -1
  2. data/Manifest.txt +11 -1
  3. data/README.txt +0 -4
  4. data/Rakefile +19 -25
  5. data/lib/acf/right_acf_interface.rb +199 -135
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +4 -4
  8. data/lib/acf/right_acf_streaming_interface.rb +19 -26
  9. data/lib/acw/right_acw_interface.rb +1 -2
  10. data/lib/as/right_as_interface.rb +6 -7
  11. data/lib/awsbase/right_awsbase.rb +287 -91
  12. data/lib/awsbase/support.rb +2 -82
  13. data/lib/awsbase/version.rb +9 -0
  14. data/lib/ec2/right_ec2.rb +101 -38
  15. data/lib/ec2/right_ec2_ebs.rb +71 -58
  16. data/lib/ec2/right_ec2_images.rb +82 -42
  17. data/lib/ec2/right_ec2_instances.rb +74 -44
  18. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  19. data/lib/ec2/right_ec2_reserved_instances.rb +50 -46
  20. data/lib/ec2/right_ec2_security_groups.rb +148 -32
  21. data/lib/ec2/right_ec2_spot_instances.rb +53 -27
  22. data/lib/ec2/right_ec2_tags.rb +139 -0
  23. data/lib/ec2/right_ec2_vpc.rb +151 -139
  24. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  25. data/lib/elb/right_elb_interface.rb +93 -18
  26. data/lib/iam/right_iam_access_keys.rb +71 -0
  27. data/lib/iam/right_iam_groups.rb +195 -0
  28. data/lib/iam/right_iam_interface.rb +341 -0
  29. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  30. data/lib/iam/right_iam_users.rb +251 -0
  31. data/lib/rds/right_rds_interface.rb +513 -202
  32. data/lib/right_aws.rb +12 -12
  33. data/lib/route_53/right_route_53_interface.rb +630 -0
  34. data/lib/s3/right_s3.rb +9 -12
  35. data/lib/s3/right_s3_interface.rb +10 -11
  36. data/lib/sdb/active_sdb.rb +18 -33
  37. data/lib/sdb/right_sdb_interface.rb +36 -4
  38. data/lib/sqs/right_sqs.rb +1 -2
  39. data/lib/sqs/right_sqs_gen2.rb +0 -1
  40. data/lib/sqs/right_sqs_gen2_interface.rb +4 -5
  41. data/lib/sqs/right_sqs_interface.rb +6 -7
  42. data/right_aws.gemspec +91 -0
  43. data/test/awsbase/test_helper.rb +2 -0
  44. data/test/awsbase/test_right_awsbase.rb +12 -0
  45. data/test/s3/test_right_s3.rb +1 -1
  46. data/test/sdb/test_active_sdb.rb +1 -1
  47. data/test/sdb/test_batch_put_attributes.rb +54 -0
  48. data/test/sqs/test_right_sqs.rb +0 -6
  49. data/test/sqs/test_right_sqs_gen2.rb +1 -1
  50. metadata +109 -58
@@ -0,0 +1,341 @@
1
+ #
2
+ # Copyright (c) 2007-2010 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ module RightAws
25
+
26
+ # = RightAWS::Iam -- RightScale AWS Identity and Access Management (IAM) interface
27
+ #
28
+ # The RightAws::Iam class provides a complete interface to Amazon's Identity and
29
+ # Access Management service.
30
+ #
31
+ # For explanations of the semantics of each call, please refer to Amazon's documentation at
32
+ # http://aws.amazon.com/documentation/iam/
33
+ #
34
+ # Examples:
35
+ #
36
+ # Create an EC2 interface handle:
37
+ #
38
+ # iam = RightAws::IamInterface.new(aws_access_key_id, aws_secret_access_key)
39
+ # iam.list_access_keys
40
+ # iam.list_users
41
+ # iam.list_groups
42
+ #
43
+ class IamInterface < RightAwsBase
44
+ include RightAwsBaseInterface
45
+
46
+ API_VERSION = "2010-05-08"
47
+ DEFAULT_HOST = "iam.amazonaws.com"
48
+ DEFAULT_PATH = '/'
49
+ DEFAULT_PROTOCOL = 'https'
50
+ DEFAULT_PORT = 443
51
+
52
+ @@bench = AwsBenchmarkingBlock.new
53
+ def self.bench_xml
54
+ @@bench.xml
55
+ end
56
+ def self.bench_service
57
+ @@bench.service
58
+ end
59
+
60
+ # Create a new handle to an IAM account. All handles share the same per process or per thread
61
+ # HTTP connection to Amazon IAM. Each handle is for a specific account. The params have the
62
+ # following options:
63
+ # * <tt>:endpoint_url</tt> a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol).
64
+ # * <tt>:server</tt>: IAM service host, default: DEFAULT_HOST
65
+ # * <tt>:port</tt>: IAM service port, default: DEFAULT_PORT
66
+ # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
67
+ # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
68
+ # * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
69
+ # * <tt>:cache</tt>: true/false(default): caching works for: describe_load_balancers
70
+ #
71
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
72
+ init({ :name => 'IAM',
73
+ :default_host => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).host : DEFAULT_HOST,
74
+ :default_port => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).port : DEFAULT_PORT,
75
+ :default_service => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).path : DEFAULT_PATH,
76
+ :default_protocol => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).scheme : DEFAULT_PROTOCOL,
77
+ :default_api_version => ENV['IAM_API_VERSION'] || API_VERSION },
78
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
79
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
80
+ params)
81
+ end
82
+
83
+ def generate_request(action, params={}) #:nodoc:
84
+ generate_request_impl(:get, action, params )
85
+ end
86
+
87
+ # Sends request to Amazon and parses the response
88
+ # Raises AwsError if any banana happened
89
+ def request_info(request, parser) #:nodoc:
90
+ request_info_impl(:iam_connection, @@bench, request, parser)
91
+ end
92
+
93
+ # Options: :parser, :except, :items
94
+ #
95
+ def incrementally_list_iam_resources(api_function, params={}, options={}, &block) #:nodoc:
96
+ items = options[:items] || :items
97
+ result = { items => [] }
98
+ parser = options[:parser] || "RightAws::IamInterface::#{api_function}Parser".right_constantize
99
+ request_hash = {}
100
+ params.each { |key,value| request_hash[key.to_s.right_camelize] = value unless value.right_blank? }
101
+ incrementally_list_items(api_function, parser, request_hash) do |response|
102
+ if result[items].right_blank?
103
+ result = response
104
+ else
105
+ result[items] += response[items]
106
+ end
107
+ block ? block.call(response) : true
108
+ end
109
+ if options[:except]
110
+ Array(options[:except]).each{ |key| result.delete(key)}
111
+ result
112
+ else
113
+ result[items]
114
+ end
115
+ end
116
+
117
+ #-----------------------------------------------------------------
118
+ # Server Certificates
119
+ #-----------------------------------------------------------------
120
+
121
+ # Lists the server certificates that have the specified path prefix. If none exist, the action returns an empty list.
122
+ #
123
+ # Options: :path_prefix, :max_items, :marker
124
+ #
125
+ # iam.list_server_certificates #=>
126
+ # {:server_certificate_id=>"ASCDJN5K5HRGS1N2UJWWU",
127
+ # :server_certificate_name=>"KdCert1",
128
+ # :upload_date=>"2010-12-09T13:21:07.226Z",
129
+ # :path=>"/kdcert/",
130
+ # :arn=>"arn:aws:iam::600000000007:server-certificate/kdcert/KdCert1"}
131
+ #
132
+ def list_server_certificates(options={}, &block)
133
+ incrementally_list_iam_resources('ListServerCertificates', options, &block)
134
+ end
135
+
136
+ # Uploads a server certificate entity for the AWS Account. The server certificate
137
+ # entity includes a public key certificate, a private key, and an optional certificate
138
+ # chain, which should all be PEM-encoded.
139
+ #
140
+ # Options: :certificate_chain, :path
141
+ #
142
+ # certificate_body =<<-EOB
143
+ # -----BEGIN CERTIFICATE-----
144
+ # MIICdzCCAeCgAwIBAgIGANc+Ha2wMA0GCSqGSIb3DQEBBQUAMFMxCzAJBgNVBAYT
145
+ # AlVTMRMwEQYDVQQKEwpBbWF6b24uY29tMQwwCgYDVQQLEwNBV1MxITAfBgNVBAMT
146
+ # GEFXUyBMaW1pdGVkLUFzc3VyYW5jZSBDQTAeFw0wOTAyMDQxNzE5MjdaFw0xMDAy
147
+ # AEaHzTpmEXAMPLE=
148
+ # EOB
149
+ #
150
+ # private_key =<<EOK
151
+ # -----BEGIN DSA PRIVATE KEY-----
152
+ # MIIBugIBTTKBgQD33xToSXPJ6hr37L3+KNi3/7DgywlBcvlFPPSHIw3ORuO/22mT
153
+ # 8Cy5fT89WwNvZ3BPKWU6OZ38TQv3eWjNc/3U3+oqVNG2poX5nCPOtO1b96HYX2mR
154
+ # 62TITdw53KWJEXAMPLE=
155
+ # EOK
156
+ #
157
+ # iam.upload_server_certificate('KdCert1', certificate_body, private_key, :path=>'/kdcert/') #=>
158
+ # {:server_certificate_id=>"ASCDJN5K5HRGS1N2UJWWU",
159
+ # :server_certificate_name=>"KdCert1",
160
+ # :upload_date=>"2010-12-09T13:21:07.226Z",
161
+ # :path=>"/kdcert/",
162
+ # :arn=>"arn:aws:iam::600000000007:server-certificate/kdcert/KdCert1"}
163
+ #
164
+ def upload_server_certificate(server_certificate_name, certificate_body, private_key, options={})
165
+ request_hash = { 'CertificateBody' => certificate_body,
166
+ 'PrivateKey' => private_key,
167
+ 'ServerCertificateName' => server_certificate_name }
168
+ request_hash['CertificateChain'] = options[:certificate_chain] unless options[:certificate_chain].right_blank?
169
+ request_hash['Path'] = options[:path] unless options[:path].right_blank?
170
+ link = generate_request_impl(:post, "UploadServerCertificate", request_hash)
171
+ request_info(link, GetServerCertificateParser.new(:logger => @logger))
172
+ end
173
+
174
+ # Updates the name and/or the path of the specified server certificate.
175
+ #
176
+ # Options: :new_server_certificate_name, :new_path
177
+ #
178
+ # iam.update_server_certificate('ProdServerCert', :new_server_certificate_name => 'OldServerCert') #=> true
179
+ #
180
+ def update_server_certificate(server_certificate_name, options={})
181
+ request_hash = { 'ServerCertificateName' => server_certificate_name}
182
+ request_hash['NewServerCertificateName'] = options[:new_server_certificate_name] unless options[:new_server_certificate_name].right_blank?
183
+ request_hash['NewPath'] = options[:new_path] unless options[:new_path].right_blank?
184
+ link = generate_request("UpdateServerCertificate", request_hash)
185
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
186
+ end
187
+
188
+ # Retrieves information about the specified server certificate.
189
+ #
190
+ # iam.get_server_certificate('KdCert1')
191
+ # {:certificate_body=>
192
+ # "-----BEGIN CERTIFICATE-----\nMIICATC...TiU5TibMpD1g==\n-----END CERTIFICATE-----",
193
+ # :server_certificate_id=>"ASCDJN5K5HRGS1N2UJWWU",
194
+ # :server_certificate_name=>"KdCert1",
195
+ # :upload_date=>"2010-12-09T13:21:07Z",
196
+ # :path=>"/kdcert/",
197
+ # :certificate_chain=>"",
198
+ # :arn=>"arn:aws:iam::600000000007:server-certificate/kdcert/KdCert1"}
199
+ #
200
+ def get_server_certificate(server_certificate_name)
201
+ request_hash = { 'ServerCertificateName' => server_certificate_name}
202
+ link = generate_request("GetServerCertificate", request_hash)
203
+ request_info(link, GetServerCertificateParser.new(:logger => @logger))
204
+ end
205
+
206
+ # Deletes the specified server certificate
207
+ #
208
+ # iam.delete_server_certificate('ProdServerCert') #=> true
209
+ #
210
+ def delete_server_certificate(server_certificate_name)
211
+ request_hash = { 'ServerCertificateName' => server_certificate_name }
212
+ link = generate_request("DeleteServerCertificate", request_hash)
213
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
214
+ end
215
+
216
+ #-----------------------------------------------------------------
217
+ # Signing Certificates
218
+ #-----------------------------------------------------------------
219
+
220
+ # Returns information about the signing certificates associated with the specified User.
221
+ #
222
+ # Options: :user_name, :max_items, :marker
223
+ #
224
+ # iam.list_signing_certificates #=>
225
+ # [{:upload_date => "2007-08-11T06:48:35Z",
226
+ # :status => "Active",
227
+ # :certificate_id => "00000000000000000000000000000000",
228
+ # :certificate_body => "-----BEGIN CERTIFICATE-----\nMIICd...PPHQ=\n-----END CERTIFICATE-----\n"}]
229
+ #
230
+ def list_signing_certificates(options={}, &block)
231
+ incrementally_list_iam_resources('ListSigningCertificates', options, &block)
232
+ end
233
+
234
+ # Uploads an X.509 signing certificate and associates it with the specified User.
235
+ #
236
+ # Options: :user_name
237
+ #
238
+ # certificate_body =<<-EOB
239
+ # -----BEGIN CERTIFICATE-----
240
+ # MIICdzCCAeCgAwIBAgIGANc+Ha2wMA0GCSqGSIb3DQEBBQUAMFMxCzAJBgNVBAYT
241
+ # AlVTMRMwEQYDVQQKEwpBbWF6b24uY29tMQwwCgYDVQQLEwNBV1MxITAfBgNVBAMT
242
+ # GEFXUyBMaW1pdGVkLUFzc3VyYW5jZSBDQTAeFw0wOTAyMDQxNzE5MjdaFw0xMDAy
243
+ # AEaHzTpmEXAMPLE=
244
+ # EOB
245
+ #
246
+ # iam.upload_signing_certificate(certificate_body, :user_name => 'kd1') #=>
247
+ # {:user_name => "kd1",
248
+ # :certificate_id => "OBG00000000000000000000000000DHY",
249
+ # :status => "Active",
250
+ # :certificate_body => "-----BEGIN CERTIFICATE-----\nMII...5GS\n-----END CERTIFICATE-----\n",
251
+ # :upload_date => "2010-10-29T10:02:05.929Z"}
252
+ #
253
+ def upload_signing_certificate(certificate_body, options={})
254
+ request_hash = { 'CertificateBody' => certificate_body }
255
+ request_hash['UserName'] = options[:user_name] unless options[:user_name].right_blank?
256
+ link = generate_request_impl(:post, "UploadSigningCertificate", request_hash)
257
+ request_info(link, GetSigningCertificateParser.new(:logger => @logger))
258
+ end
259
+
260
+ # Deletes the specified signing certificate associated with the specified User.
261
+ #
262
+ # Options: :user_name
263
+ #
264
+ # pp iam.delete_signing_certificate('OB0000000000000000000000000000HY', :user_name => 'kd1')
265
+ #
266
+ def delete_signing_certificate(certificate_id, options={})
267
+ request_hash = { 'CertificateId' => certificate_id }
268
+ request_hash['UserName'] = options[:user_name] unless options[:user_name].right_blank?
269
+ link = generate_request("DeleteSigningCertificate", request_hash)
270
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
271
+ end
272
+
273
+ #-----------------------------------------------------------------
274
+ # PARSERS:
275
+ #-----------------------------------------------------------------
276
+
277
+ class BasicIamParser < RightAWSParser #:nodoc:
278
+ def tagstart(name, attributes)
279
+ @result ||= {}
280
+ end
281
+ def tagend(name)
282
+ if Array(@expected_tags).include?(name)
283
+ @result[name.right_underscore.to_sym] = @text
284
+ end
285
+ end
286
+ end
287
+
288
+ class BasicIamListParser < RightAWSParser #:nodoc:
289
+ def tagstart(name, attributes)
290
+ @result ||= { :items => [] }
291
+ @item = {} if name == (@items_splitter || 'member')
292
+ end
293
+ def tagend(name)
294
+ case name
295
+ when 'Marker' then @result[:marker] = @text
296
+ when 'IsTruncated' then @result[:is_truncated] = @text == 'true'
297
+ when (@items_splitter || 'member')
298
+ @result[:items] << (@item.right_blank? ? @text : @item)
299
+ else
300
+ if Array(@expected_tags).include?(name)
301
+ @item[name.right_underscore.to_sym] = @text
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ #-----------------------------------------------------------------
308
+ # Server Certificates
309
+ #-----------------------------------------------------------------
310
+
311
+ class GetServerCertificateParser < BasicIamParser #:nodoc:
312
+ def reset
313
+ @expected_tags = %w{ Arn Path ServerCertificateId ServerCertificateName UploadDate CertificateBody CertificateChain }
314
+ end
315
+ end
316
+
317
+ class ListServerCertificatesParser < BasicIamListParser #:nodoc:
318
+ def reset
319
+ @expected_tags = %w{ Arn Path ServerCertificateId ServerCertificateName UploadDate }
320
+ end
321
+ end
322
+
323
+ #-----------------------------------------------------------------
324
+ # Signing Certificates
325
+ #-----------------------------------------------------------------
326
+
327
+ class ListSigningCertificatesParser < BasicIamListParser #:nodoc:
328
+ def reset
329
+ @expected_tags = %w{ CertificateBody CertificateId Status UploadDate UserName }
330
+ end
331
+ end
332
+
333
+ class GetSigningCertificateParser < BasicIamParser #:nodoc:
334
+ def reset
335
+ @expected_tags = %w{ CertificateBody CertificateId Status UploadDate UserName }
336
+ end
337
+ end
338
+
339
+ end
340
+
341
+ end
@@ -0,0 +1,67 @@
1
+ module RightAws
2
+
3
+ class IamInterface < RightAwsBase
4
+
5
+ #-----------------------------------------------------------------
6
+ # MFADevices
7
+ #-----------------------------------------------------------------
8
+
9
+ # Lists the MFA devices associated with the specified User name.
10
+ #
11
+ # Options: :user_name, :max_items, :marker
12
+ #
13
+ def list_mfa_devices(options={}, &block)
14
+ incrementally_list_iam_resources('ListMFADevices', options, &block)
15
+ end
16
+
17
+ # Enables the specified MFA device and associates it with the specified User name.
18
+ # Once enabled, the MFA device is required for every subsequent login by the User name associated with the device.
19
+ #
20
+ # iam.enable_mfa_device('kd1', 'x12345', '12345', '67890') #=> true
21
+ #
22
+ def enable_mfa_device(user_name, serial_number, auth_code1, auth_code2)
23
+ request_hash = { 'UserName' => user_name,
24
+ 'SerialNumber' => serial_number,
25
+ 'AuthenticationCode1' => auth_code1,
26
+ 'AuthenticationCode2' => auth_code2 }
27
+ link = generate_request("EnableMFADevice", request_hash)
28
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
29
+ end
30
+
31
+ # Synchronizes the specified MFA device with AWS servers.
32
+ #
33
+ # iam.resync_mfa_device('kd1', 'x12345', '12345', '67890') #=> true
34
+ #
35
+ def resync_mfa_device(user_name, serial_number, auth_code1, auth_code2)
36
+ request_hash = { 'UserName' => user_name,
37
+ 'SerialNumber' => serial_number,
38
+ 'AuthenticationCode1' => auth_code1,
39
+ 'AuthenticationCode2' => auth_code2 }
40
+ link = generate_request("ResyncMFADevice", request_hash)
41
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
42
+ end
43
+
44
+ # Deactivates the specified MFA device and removes it from association with the User name for which it was originally enabled.
45
+ #
46
+ # deactivate_mfa_device('kd1', 'dev1234567890') #=> true
47
+ #
48
+ def deactivate_mfa_device(user_name, serial_number)
49
+ request_hash = { 'UserName' => user_name,
50
+ 'SerialNumber' => serial_number }
51
+ link = generate_request("DeactivateMFADevice", request_hash)
52
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
53
+ end
54
+
55
+ #-----------------------------------------------------------------
56
+ # PARSERS
57
+ #-----------------------------------------------------------------
58
+
59
+ class ListMFADevicesParser < BasicIamListParser #:nodoc:
60
+ def reset
61
+ @expected_tags = %w{ SerialNumber UserName }
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,251 @@
1
+ module RightAws
2
+
3
+ class IamInterface < RightAwsBase
4
+
5
+ #-----------------------------------------------------------------
6
+ # Users
7
+ #-----------------------------------------------------------------
8
+
9
+ # Lists the Users that have the specified path prefix.
10
+ #
11
+ # Options: :path_prefix, :max_items, :marker
12
+ #
13
+ # iam.list_users #=>
14
+ # [{:user_name=>"kd",
15
+ # :user_id=>"AI000000000000000006A",
16
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
17
+ # :path=>"/"}]
18
+ #
19
+ def list_users(options={}, &block)
20
+ incrementally_list_iam_resources('ListUsers', options, &block)
21
+ end
22
+
23
+ # Creates a new User for your AWS Account.
24
+ #
25
+ # Options: :path
26
+ #
27
+ # iam.create_user('kd') #=>
28
+ # {:user_name=>"kd",
29
+ # :user_id=>"AI000000000000000006A",
30
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
31
+ # :path=>"/"}
32
+ #
33
+ def create_user(user_name, options={})
34
+ request_hash = { 'UserName' => user_name }
35
+ request_hash['Path'] = options[:path] unless options[:path]
36
+ link = generate_request("CreateUser", request_hash)
37
+ request_info(link, GetUserParser.new(:logger => @logger))
38
+ end
39
+
40
+ # Updates the name and/or the path of the specified User.
41
+ #
42
+ # iam.update_user('kd1', :new_user_name => 'kd1', :new_path => '/kd1/') #=> true
43
+ #
44
+ def update_user(user_name, options={})
45
+ request_hash = { 'UserName' => user_name}
46
+ request_hash['NewUserName'] = options[:new_user_name] unless options[:new_user_name].right_blank?
47
+ request_hash['NewPath'] = options[:new_path] unless options[:new_path].right_blank?
48
+ link = generate_request("UpdateUser", request_hash)
49
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
50
+ end
51
+
52
+ # Retrieves information about the specified User, including the User's path, GUID, and ARN.
53
+ #
54
+ # iam.get_user('kd') #=>
55
+ # {:user_name=>"kd",
56
+ # :user_id=>"AI000000000000000006A",
57
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
58
+ # :path=>"/"}
59
+ #
60
+ def get_user(user_name)
61
+ request_hash = { 'UserName' => user_name }
62
+ link = generate_request("GetUser", request_hash)
63
+ request_info(link, GetUserParser.new(:logger => @logger))
64
+ end
65
+
66
+ # Deletes the specified User. The User must not belong to any groups, have any keys or signing certificates, or have any attached policies.
67
+ #
68
+ # iam.delete_user('kd') #=> true
69
+ #
70
+ def delete_user(user_name)
71
+ request_hash = { 'UserName' => user_name }
72
+ link = generate_request("DeleteUser", request_hash)
73
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
74
+ end
75
+
76
+ #-----------------------------------------------------------------
77
+ # User Policies
78
+ #-----------------------------------------------------------------
79
+
80
+ # Lists the names of the policies associated with the specified User.
81
+ #
82
+ # Options: :max_items, :marker
83
+ #
84
+ # iam.list_user_policies('kd') #=> ["kd_user_policy_1"]
85
+ #
86
+ def list_user_policies(user_name, options={}, &block)
87
+ options[:user_name] = user_name
88
+ incrementally_list_iam_resources('ListUserPolicies', options, :parser => BasicIamListParser, &block)
89
+ end
90
+
91
+ # Adds (or updates) a policy document associated with the specified User
92
+ #
93
+ # iam.put_user_policy('kd', 'kd_user_policy_1', %Q({"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]})) #=> true
94
+ #
95
+ def put_user_policy(user_name, policy_name, policy_document)
96
+ request_hash = { 'UserName' => user_name,
97
+ 'PolicyDocument' => policy_document,
98
+ 'PolicyName' => policy_name }
99
+ link = generate_request_impl(:post, "PutUserPolicy", request_hash)
100
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
101
+ end
102
+
103
+ # Retrieves the specified policy document for the specified User.
104
+ #
105
+ # iam.get_user_policy('kd','kd_user_policy_1') #=>
106
+ # {:user_name=>"kd",
107
+ # :policy_name=>"kd_user_policy_1",
108
+ # :policy_document=>"{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}"}
109
+ #
110
+ def get_user_policy(user_name, policy_name)
111
+ request_hash = { 'UserName' => user_name,
112
+ 'PolicyName' => policy_name }
113
+ link = generate_request("GetUserPolicy", request_hash)
114
+ result = request_info(link, GetUserPolicyParser.new(:logger => @logger))
115
+ result[:policy_document] = URI::decode(result[:policy_document])
116
+ result
117
+ end
118
+
119
+ # Deletes the specified policy associated with the specified User.
120
+ #
121
+ # iam.delete_user_policy('kd','kd_user_policy_1') #=> true
122
+ #
123
+ def delete_user_policy(user_name, policy_name)
124
+ request_hash = { 'UserName' => user_name,
125
+ 'PolicyName' => policy_name }
126
+ link = generate_request("DeleteUserPolicy", request_hash)
127
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
128
+ end
129
+
130
+ #-----------------------------------------------------------------
131
+ # User Groups
132
+ #-----------------------------------------------------------------
133
+
134
+ # Lists the names of the policies associated with the specified group. If there are none,
135
+ # the action returns an empty list.
136
+ #
137
+ # Options: :max_items, :marker
138
+ #
139
+ # iam.list_groups_for_user('kd') #=>
140
+ # [{:group_name=>"kd_test_1",
141
+ # :group_id=>"AGP000000000000000UTY",
142
+ # :arn=>"arn:aws:iam::640000000037:group/kd1/kd_test_1",
143
+ # :path=>"/kd1/"}]
144
+ #
145
+ def list_groups_for_user(user_name, options={}, &block)
146
+ options[:user_name] = user_name
147
+ incrementally_list_iam_resources('ListGroupsForUser', options, :parser => ListGroupsParser, &block)
148
+ end
149
+
150
+ # Adds the specified User to the specified group.
151
+ #
152
+ # iam.add_user_to_group('kd', 'kd_test_1') #=> true
153
+ #
154
+ def add_user_to_group(user_name, group_name)
155
+ request_hash = { 'UserName' => user_name,
156
+ 'GroupName' => group_name }
157
+ link = generate_request("AddUserToGroup", request_hash)
158
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
159
+ end
160
+
161
+ # Removes the specified User from the specified group.
162
+ #
163
+ # iam.remove_user_from_group('kd', 'kd_test_1') #=> true
164
+ #
165
+ def remove_user_from_group(user_name, group_name)
166
+ request_hash = { 'UserName' => user_name,
167
+ 'GroupName' => group_name }
168
+ link = generate_request("RemoveUserFromGroup", request_hash)
169
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
170
+ end
171
+
172
+ #-----------------------------------------------------------------
173
+ # User Login Profiles
174
+ #-----------------------------------------------------------------
175
+
176
+ # Creates a login profile for the specified User, giving the User the ability to access
177
+ # AWS services such as the AWS Management Console.
178
+ #
179
+ # iam.create_login_profile('kd','q1w2e3r4t5') #=> { :user_name => 'kd' }
180
+ #
181
+ def create_login_profile(user_name, password)
182
+ request_hash = { 'UserName' => user_name,
183
+ 'Password' => password}
184
+ link = generate_request("CreateLoginProfile", request_hash)
185
+ request_info(link, GetLoginProfileParser.new(:logger => @logger))
186
+ end
187
+
188
+ # Updates the login profile for the specified User. Use this API to change the User's password.
189
+ #
190
+ # update_login_profile('kd', '00000000') #=> true
191
+ #
192
+ def update_login_profile(user_name, options={})
193
+ request_hash = { 'UserName' => user_name}
194
+ request_hash['Password'] = options[:password] unless options[:passwrod].right_blank?
195
+ link = generate_request("UpdateLoginProfile", request_hash)
196
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
197
+ end
198
+
199
+ # Retrieves the login profile for the specified User
200
+ #
201
+ # iam.create_login_profile('kd','q1w2e3r4t5') #=> { :user_name => 'kd' }
202
+ #
203
+ def get_login_profile(user_name)
204
+ request_hash = { 'UserName' => user_name }
205
+ link = generate_request("GetLoginProfile", request_hash)
206
+ request_info(link, GetLoginProfileParser.new(:logger => @logger))
207
+ end
208
+
209
+ # Deletes the login profile for the specified User, which terminates the User's ability to access
210
+ # AWS services through the IAM login page.
211
+ #
212
+ # iam.delete_login_profile('kd') #=> true
213
+ #
214
+ def delete_login_profile(user_name)
215
+ request_hash = { 'UserName' => user_name }
216
+ link = generate_request("DeleteLoginProfile", request_hash)
217
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
218
+ end
219
+
220
+ #-----------------------------------------------------------------
221
+ # PARSERS
222
+ #-----------------------------------------------------------------
223
+
224
+ class ListUsersParser < BasicIamListParser #:nodoc:
225
+ def reset
226
+ @expected_tags = %w{ Arn Path UserId UserName }
227
+ end
228
+ end
229
+
230
+ class GetUserParser < BasicIamParser #:nodoc:
231
+ def reset
232
+ @expected_tags = %w{ Arn Path UserId UserName }
233
+ end
234
+ end
235
+
236
+ class GetUserPolicyParser < BasicIamParser #:nodoc:
237
+ def reset
238
+ @expected_tags = %w{ PolicyDocument PolicyName UserName }
239
+ end
240
+ end
241
+
242
+ class GetLoginProfileParser < BasicIamParser #:nodoc:
243
+ def reset
244
+ @expected_tags = %w{ UserName }
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ end
251
+