right_aws 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +22 -1
- data/Manifest.txt +11 -1
- data/README.txt +0 -4
- data/Rakefile +19 -25
- data/lib/acf/right_acf_interface.rb +199 -135
- data/lib/acf/right_acf_invalidations.rb +144 -0
- data/lib/acf/right_acf_origin_access_identities.rb +4 -4
- data/lib/acf/right_acf_streaming_interface.rb +19 -26
- data/lib/acw/right_acw_interface.rb +1 -2
- data/lib/as/right_as_interface.rb +6 -7
- data/lib/awsbase/right_awsbase.rb +287 -91
- data/lib/awsbase/support.rb +2 -82
- data/lib/awsbase/version.rb +9 -0
- data/lib/ec2/right_ec2.rb +101 -38
- data/lib/ec2/right_ec2_ebs.rb +71 -58
- data/lib/ec2/right_ec2_images.rb +82 -42
- data/lib/ec2/right_ec2_instances.rb +74 -44
- data/lib/ec2/right_ec2_placement_groups.rb +108 -0
- data/lib/ec2/right_ec2_reserved_instances.rb +50 -46
- data/lib/ec2/right_ec2_security_groups.rb +148 -32
- data/lib/ec2/right_ec2_spot_instances.rb +53 -27
- data/lib/ec2/right_ec2_tags.rb +139 -0
- data/lib/ec2/right_ec2_vpc.rb +151 -139
- data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
- data/lib/elb/right_elb_interface.rb +93 -18
- data/lib/iam/right_iam_access_keys.rb +71 -0
- data/lib/iam/right_iam_groups.rb +195 -0
- data/lib/iam/right_iam_interface.rb +341 -0
- data/lib/iam/right_iam_mfa_devices.rb +67 -0
- data/lib/iam/right_iam_users.rb +251 -0
- data/lib/rds/right_rds_interface.rb +513 -202
- data/lib/right_aws.rb +12 -12
- data/lib/route_53/right_route_53_interface.rb +630 -0
- data/lib/s3/right_s3.rb +9 -12
- data/lib/s3/right_s3_interface.rb +10 -11
- data/lib/sdb/active_sdb.rb +18 -33
- data/lib/sdb/right_sdb_interface.rb +36 -4
- data/lib/sqs/right_sqs.rb +1 -2
- data/lib/sqs/right_sqs_gen2.rb +0 -1
- data/lib/sqs/right_sqs_gen2_interface.rb +4 -5
- data/lib/sqs/right_sqs_interface.rb +6 -7
- data/right_aws.gemspec +91 -0
- data/test/awsbase/test_helper.rb +2 -0
- data/test/awsbase/test_right_awsbase.rb +12 -0
- data/test/s3/test_right_s3.rb +1 -1
- data/test/sdb/test_active_sdb.rb +1 -1
- data/test/sdb/test_batch_put_attributes.rb +54 -0
- data/test/sqs/test_right_sqs.rb +0 -6
- data/test/sqs/test_right_sqs_gen2.rb +1 -1
- metadata +109 -58
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 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
|
+
class Ec2
|
27
|
+
|
28
|
+
def describe_licenses(*license_ids)
|
29
|
+
link = generate_request("DescribeLicenses", amazonize_list('LicenseId', license_ids))
|
30
|
+
request_info(link, QEc2DescribeLicensesParser.new(:logger => @logger))
|
31
|
+
end
|
32
|
+
|
33
|
+
def activate_license(license_id, capacity)
|
34
|
+
link = generate_request("ActivateLicense", 'LicenseId' => license_id,
|
35
|
+
'Capacity' => capacity)
|
36
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
37
|
+
end
|
38
|
+
|
39
|
+
# def get_license_capacity(license_id)
|
40
|
+
# link = generate_request("GetLicenseCapacity", 'LicenseId' => license_id)
|
41
|
+
# request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
42
|
+
# end
|
43
|
+
|
44
|
+
def deactivate_license(license_id, capacity)
|
45
|
+
link = generate_request("DeactivateLicense", 'LicenseId' => license_id,
|
46
|
+
'Capacity' => capacity)
|
47
|
+
request_info(link, RightBoolResponseParser.new(:logger => @logger))
|
48
|
+
end
|
49
|
+
|
50
|
+
#-----------------------------------------------------------------
|
51
|
+
# PARSERS: Images
|
52
|
+
#-----------------------------------------------------------------
|
53
|
+
|
54
|
+
class QEc2DescribeLicensesParser < RightAWSParser #:nodoc:
|
55
|
+
def tagstart(name, attributes)
|
56
|
+
case full_tag_name
|
57
|
+
when %r{/licenseSet/item$} then @item = { :capacities => [] }
|
58
|
+
when %r{/capacitySet/item$} then @capacity_item = {}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
def tagend(name)
|
62
|
+
case name
|
63
|
+
when 'licenseId' then @item[:license_id] = @text
|
64
|
+
when 'type' then @item[:type] = @text
|
65
|
+
when 'pool' then @item[:pool] = @text
|
66
|
+
when 'capacity' then @capacity_item[:capacity] = @text.to_i
|
67
|
+
when 'instanceCapacity' then @capacity_item[:instance_capacity] = @text.to_i
|
68
|
+
when 'state' then @capacity_item[:state] = @text
|
69
|
+
when 'earliestAllowedDeactivationTime' then @capacity_item[:earliest_allowed_deactivation_time] = @text
|
70
|
+
else
|
71
|
+
case full_tag_name
|
72
|
+
when %r{/capacitySet/item$} then @item[:capacities] << @capacity_item
|
73
|
+
when %r{/licenseSet/item$} then @result << @item
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
def reset
|
78
|
+
@result = []
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -62,12 +62,14 @@ module RightAws
|
|
62
62
|
include RightAwsBaseInterface
|
63
63
|
|
64
64
|
# Amazon ELB API version being used
|
65
|
-
API_VERSION = "
|
65
|
+
API_VERSION = "2010-07-01"
|
66
66
|
DEFAULT_HOST = "elasticloadbalancing.amazonaws.com"
|
67
67
|
DEFAULT_PATH = '/'
|
68
68
|
DEFAULT_PROTOCOL = 'https'
|
69
69
|
DEFAULT_PORT = 443
|
70
70
|
|
71
|
+
LISTENER_PROTOCOLS = [ 'HTTP', 'HTTPS', 'TCP', 'SSL' ]
|
72
|
+
|
71
73
|
@@bench = AwsBenchmarkingBlock.new
|
72
74
|
def self.bench_xml
|
73
75
|
@@bench.xml
|
@@ -83,7 +85,6 @@ module RightAws
|
|
83
85
|
# * <tt>:server</tt>: ELB service host, default: DEFAULT_HOST
|
84
86
|
# * <tt>:port</tt>: ELB service port, default: DEFAULT_PORT
|
85
87
|
# * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
|
86
|
-
# * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
|
87
88
|
# * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
|
88
89
|
# * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
|
89
90
|
# * <tt>:cache</tt>: true/false(default): caching works for: describe_load_balancers
|
@@ -166,35 +167,33 @@ module RightAws
|
|
166
167
|
load_balancers = load_balancers.flatten.compact
|
167
168
|
request_hash = amazonize_list("LoadBalancerNames.member", load_balancers)
|
168
169
|
link = generate_request("DescribeLoadBalancers", request_hash)
|
169
|
-
request_cache_or_info(:describe_load_balancers, link, DescribeLoadBalancersParser, @@bench, load_balancers.
|
170
|
+
request_cache_or_info(:describe_load_balancers, link, DescribeLoadBalancersParser, @@bench, load_balancers.right_blank?)
|
170
171
|
end
|
171
172
|
|
172
173
|
# Create new load balancer.
|
173
174
|
# Returns a new load balancer DNS name.
|
174
175
|
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
|
179
|
-
#
|
176
|
+
# Listener options: :protocol, :load_balancer_port, :instance_port and :ssl_certificate_id
|
177
|
+
# Protocols: :tcp, :http, :https or :ssl
|
178
|
+
#
|
179
|
+
# elb.create_load_balancer( 'test-kd1',
|
180
|
+
# ['us-east-1a', 'us-east-1b'],
|
181
|
+
# [ { :protocol => :http, :load_balancer_port => 80, :instance_port => 80 },
|
182
|
+
# { :protocol => :https, :load_balancer_port => 443, :instance_port => 443,
|
183
|
+
# :ssl_certificate_id => 'arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/Bob' } ])
|
184
|
+
# #=> "test-kd1-1519253964.us-east-1.elb.amazonaws.com"
|
180
185
|
#
|
181
186
|
def create_load_balancer(load_balancer_name, availability_zones=[], listeners=[])
|
182
187
|
request_hash = { 'LoadBalancerName' => load_balancer_name }
|
183
188
|
# merge zones
|
184
189
|
request_hash.merge!( amazonize_list("AvailabilityZones.member", availability_zones) )
|
185
190
|
# merge listeners
|
186
|
-
if listeners.
|
191
|
+
if listeners.right_blank?
|
187
192
|
listeners = { :protocol => :http,
|
188
193
|
:load_balancer_port => 80,
|
189
194
|
:instance_port => 80 }
|
190
195
|
end
|
191
|
-
|
192
|
-
request_hash.merge!( amazonize_list( ['Listeners.member.?.Protocol',
|
193
|
-
'Listeners.member.?.LoadBalancerPort',
|
194
|
-
'Listeners.member.?.InstancePort'],
|
195
|
-
listeners.map{|i| [ (i[:protocol] || 'HTTP').to_s.upcase,
|
196
|
-
(i[:load_balancer_port] || 80),
|
197
|
-
(i[:instance_port] || 80) ] } ) )
|
196
|
+
request_hash = merge_listeners_into_request_hash(request_hash, listeners)
|
198
197
|
link = generate_request("CreateLoadBalancer", request_hash)
|
199
198
|
request_info(link, CreateLoadBalancerParser.new(:logger => @logger))
|
200
199
|
end
|
@@ -212,6 +211,37 @@ module RightAws
|
|
212
211
|
request_info(link, DeleteLoadBalancerParser.new(:logger => @logger))
|
213
212
|
end
|
214
213
|
|
214
|
+
# Creates one or more new listeners on a LoadBalancer for the specified port. If a listener with the given
|
215
|
+
# port does not already exist, it will be created; otherwise, the properties of the new listener must match
|
216
|
+
# the the properties of the existing listener.
|
217
|
+
#
|
218
|
+
# Listener options: :protocol, :load_balancer_port, :instance_port and :ssl_certificate_id
|
219
|
+
# Protocols: :tcp, :http, :https or :ssl
|
220
|
+
#
|
221
|
+
# elb.create_load_balancer_listeners( 'test-kd1',
|
222
|
+
# [ { :protocol => :http, :load_balancer_port => 80, :instance_port => 80 },
|
223
|
+
# { :protocol => :https, :load_balancer_port => 443, :instance_port => 443,
|
224
|
+
# :ssl_certificate_id => 'arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/Bob' } ]) #=> true
|
225
|
+
#
|
226
|
+
def create_load_balancer_listeners(load_balancer_name, listeners)
|
227
|
+
request_hash = { 'LoadBalancerName' => load_balancer_name }
|
228
|
+
request_hash = merge_listeners_into_request_hash(request_hash, listeners)
|
229
|
+
link = generate_request("CreateLoadBalancerListeners", request_hash)
|
230
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
231
|
+
end
|
232
|
+
|
233
|
+
# Removes listeners from the load balancer for the specified port number.
|
234
|
+
#
|
235
|
+
# elb.delete_load_balancer_listeners( 'kd_test', 80, 443) #=> true
|
236
|
+
#
|
237
|
+
def delete_load_balancer_listeners(load_balancer_name, *load_balancer_ports)
|
238
|
+
load_balancer_ports.flatten!
|
239
|
+
request_hash = { 'LoadBalancerName' => load_balancer_name }
|
240
|
+
request_hash.merge!( amazonize_list("LoadBalancerPorts.member", load_balancer_ports ) )
|
241
|
+
link = generate_request("DeleteLoadBalancerListeners", request_hash )
|
242
|
+
request_info(link, DeleteLoadBalancerParser.new(:logger => @logger))
|
243
|
+
end
|
244
|
+
|
215
245
|
# Add one or more zones to a load balancer.
|
216
246
|
# Returns a list of updated availability zones for the load balancer.
|
217
247
|
#
|
@@ -251,7 +281,7 @@ module RightAws
|
|
251
281
|
#
|
252
282
|
def configure_health_check(load_balancer_name, health_check)
|
253
283
|
request_hash = { 'LoadBalancerName' => load_balancer_name }
|
254
|
-
health_check.each{ |key, value| request_hash["HealthCheck.#{key.to_s.
|
284
|
+
health_check.each{ |key, value| request_hash["HealthCheck.#{key.to_s.right_camelize}"] = value }
|
255
285
|
link = generate_request("ConfigureHealthCheck", request_hash)
|
256
286
|
request_info(link, HealthCheckParser.new(:logger => @logger))
|
257
287
|
end
|
@@ -348,11 +378,55 @@ module RightAws
|
|
348
378
|
policy_names.flatten!
|
349
379
|
request_hash = { 'LoadBalancerName' => load_balancer_name,
|
350
380
|
'LoadBalancerPort' => load_balancer_port }
|
351
|
-
|
381
|
+
if policy_names.right_blank?
|
382
|
+
request_hash['PolicyNames'] = ''
|
383
|
+
else
|
384
|
+
request_hash.merge!(amazonize_list('PolicyNames.member', policy_names))
|
385
|
+
end
|
352
386
|
link = generate_request("SetLoadBalancerPoliciesOfListener", request_hash)
|
353
387
|
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
354
388
|
end
|
355
389
|
|
390
|
+
# Deletes a policy from the load balancer. The specified policy must not be enabled for any listeners.
|
391
|
+
#
|
392
|
+
# elb.delete_load_balancer_policy('my-load-balancer', 'MyLoadBalancerPolicy') #=> true
|
393
|
+
#
|
394
|
+
def delete_load_balancer_policy(load_balancer_name, policy_name)
|
395
|
+
request_hash = { 'LoadBalancerName' => load_balancer_name,
|
396
|
+
'PolicyName' => policy_name }
|
397
|
+
link = generate_request("DeleteLoadBalancerPolicy", request_hash)
|
398
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
399
|
+
end
|
400
|
+
|
401
|
+
def set_load_balancer_listener_ssl_certificate(load_balancer_name, load_balancer_port, ssl_sertificate_id)
|
402
|
+
request_hash = { 'LoadBalancerName' => load_balancer_name,
|
403
|
+
'LoadBalancerPort' => load_balancer_port,
|
404
|
+
'SSLCertificateId' => ssl_sertificate_id }
|
405
|
+
link = generate_request("SetLoadBalancerListenerSSLCertificate", request_hash)
|
406
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
407
|
+
end
|
408
|
+
|
409
|
+
#-----------------------------------------------------------------
|
410
|
+
# Helpers
|
411
|
+
#-----------------------------------------------------------------
|
412
|
+
|
413
|
+
def merge_listeners_into_request_hash(request_hash, listeners) # :nodoc:
|
414
|
+
listeners = [listeners] unless listeners.is_a?(Array)
|
415
|
+
request_hash.merge(amazonize_list( ['Listeners.member.?.Protocol',
|
416
|
+
'Listeners.member.?.LoadBalancerPort',
|
417
|
+
'Listeners.member.?.InstancePort',
|
418
|
+
'Listeners.member.?.SSLCertificateId'],
|
419
|
+
listeners.map{ |i|
|
420
|
+
[ (i[:protocol] || 'HTTP').to_s.upcase,
|
421
|
+
i[:load_balancer_port] || 80,
|
422
|
+
i[:instance_port] || 80,
|
423
|
+
i[:ssl_certificate_id]]
|
424
|
+
},
|
425
|
+
:default => :skip_nils
|
426
|
+
)
|
427
|
+
)
|
428
|
+
end
|
429
|
+
|
356
430
|
#-----------------------------------------------------------------
|
357
431
|
# PARSERS: Load Balancers
|
358
432
|
#-----------------------------------------------------------------
|
@@ -385,6 +459,7 @@ module RightAws
|
|
385
459
|
when 'Protocol' then @listener[:protocol] = @text
|
386
460
|
when 'LoadBalancerPort' then @listener[:load_balancer_port] = @text
|
387
461
|
when 'InstancePort' then @listener[:instance_port] = @text
|
462
|
+
when 'SSLCertificateId' then @listener[:ssl_certificate_id] = @text
|
388
463
|
end
|
389
464
|
case full_tag_name
|
390
465
|
when %r{AvailabilityZones/member$} then @item[:availability_zones] << @text
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module RightAws
|
2
|
+
|
3
|
+
class IamInterface < RightAwsBase
|
4
|
+
|
5
|
+
#-----------------------------------------------------------------
|
6
|
+
# Access Keys
|
7
|
+
#-----------------------------------------------------------------
|
8
|
+
|
9
|
+
# Returns information about the Access Key IDs associated with the specified User.
|
10
|
+
#
|
11
|
+
# Options: :user_name, :max_items, :marker
|
12
|
+
#
|
13
|
+
# iam.list_access_keys #=>
|
14
|
+
# [{:create_date=>"2007-01-09T06:16:30Z",
|
15
|
+
# :status=>"Active",
|
16
|
+
# :access_key_id=>"00000000000000000000"}]
|
17
|
+
#
|
18
|
+
def list_access_keys(options={}, &block)
|
19
|
+
incrementally_list_iam_resources('ListAccessKeys', options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a new AWS Secret Access Key and corresponding AWS Access Key ID for the specified User.
|
23
|
+
#
|
24
|
+
# Options: :user_name
|
25
|
+
#
|
26
|
+
# iam.create_access_key(:user_name => 'kd1') #=>
|
27
|
+
# {:access_key_id=>"AK0000000000000000ZQ",
|
28
|
+
# :status=>"Active",
|
29
|
+
# :secret_access_key=>"QXN0000000000000000000000000000000000Ioj",
|
30
|
+
# :create_date=>"2010-10-29T07:16:32.210Z",
|
31
|
+
# :user_name=>"kd1"}
|
32
|
+
#
|
33
|
+
def create_access_key(options={})
|
34
|
+
request_hash = {}
|
35
|
+
request_hash['UserName'] = options[:user_name] unless options[:user_name].right_blank?
|
36
|
+
link = generate_request("CreateAccessKey", request_hash)
|
37
|
+
request_info(link, CreateAccessKeyParser.new(:logger => @logger))
|
38
|
+
end
|
39
|
+
|
40
|
+
# Deletes the access key associated with the specified User.
|
41
|
+
#
|
42
|
+
# Options: :user_name
|
43
|
+
#
|
44
|
+
# iam.delete_access_key('AK00000000000000006A', :user_name => 'kd1') #=> true
|
45
|
+
#
|
46
|
+
def delete_access_key(access_key_id, options={})
|
47
|
+
request_hash = { 'AccessKeyId' => access_key_id }
|
48
|
+
request_hash['UserName'] = options[:user_name] unless options[:user_name].right_blank?
|
49
|
+
link = generate_request("DeleteAccessKey", request_hash)
|
50
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
51
|
+
end
|
52
|
+
|
53
|
+
#-----------------------------------------------------------------
|
54
|
+
# PARSERS
|
55
|
+
#-----------------------------------------------------------------
|
56
|
+
|
57
|
+
class ListAccessKeysParser < BasicIamListParser #:nodoc:
|
58
|
+
def reset
|
59
|
+
@expected_tags = %w{ AccessKeyId CreateDate Status UserName }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class CreateAccessKeyParser < BasicIamParser #:nodoc:
|
64
|
+
def reset
|
65
|
+
@expected_tags = %w{ AccessKeyId CreateDate SecretAccessKey Status UserName }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
module RightAws
|
2
|
+
|
3
|
+
class IamInterface < RightAwsBase
|
4
|
+
|
5
|
+
#-----------------------------------------------------------------
|
6
|
+
# Groups
|
7
|
+
#-----------------------------------------------------------------
|
8
|
+
|
9
|
+
# Lists the groups that have the specified path prefix.
|
10
|
+
#
|
11
|
+
# Options: :path_prefix, :max_items, :marker
|
12
|
+
#
|
13
|
+
# iam.list_groups #=>
|
14
|
+
# [{:group_id=>"AGP000000000000000UTY",
|
15
|
+
# :arn=>"arn:aws:iam::640000000037:group/kd_test",
|
16
|
+
# :path=>"/",
|
17
|
+
# :group_name=>"kd_test"}]
|
18
|
+
#
|
19
|
+
def list_groups(options={}, &block)
|
20
|
+
incrementally_list_iam_resources('ListGroups', options, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a new group.
|
24
|
+
#
|
25
|
+
# iam.create_group('kd_group') #=>
|
26
|
+
# {:group_id=>"AGP000000000000000UTY",
|
27
|
+
# :arn=>"arn:aws:iam::640000000037:group/kd_test",
|
28
|
+
# :path=>"/",
|
29
|
+
# :group_name=>"kd_test"}
|
30
|
+
#
|
31
|
+
# iam.create_group('kd_test_3', '/kd/') #=>
|
32
|
+
# {:group_id=>"AGP000000000000000G6Q",
|
33
|
+
# :arn=>"arn:aws:iam::640000000037:group/kd/kd_test_3",
|
34
|
+
# :path=>"/kd/",
|
35
|
+
# :group_name=>"kd_test_3"}
|
36
|
+
#
|
37
|
+
def create_group(group_name, path=nil)
|
38
|
+
request_hash = { 'GroupName' => group_name }
|
39
|
+
request_hash['Path'] = path unless path.right_blank?
|
40
|
+
link = generate_request("CreateGroup", request_hash)
|
41
|
+
request_info(link, CreateGroupParser.new(:logger => @logger))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Updates the name and/or the path of the specified group
|
45
|
+
#
|
46
|
+
# Options: :new_group_name, :new_path
|
47
|
+
#
|
48
|
+
# iam.update_group('kd_test', :new_group_name => 'kd_test_1', :new_path => '/kd1/') #=> true
|
49
|
+
#
|
50
|
+
def update_group(group_name, options={})
|
51
|
+
request_hash = { 'GroupName' => group_name}
|
52
|
+
request_hash['NewGroupName'] = options[:new_group_name] unless options[:new_group_name].right_blank?
|
53
|
+
request_hash['NewPath'] = options[:new_path] unless options[:new_path].right_blank?
|
54
|
+
link = generate_request("UpdateGroup", request_hash)
|
55
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a list of Users that are in the specified group.
|
59
|
+
#
|
60
|
+
# Options: :max_items, :marker
|
61
|
+
#
|
62
|
+
# iam.get_group('kd_test') #=>
|
63
|
+
# {:arn=>"arn:aws:iam::640000000037:group/kd1/kd_test_1",
|
64
|
+
# :users=>
|
65
|
+
# [{:arn=>"arn:aws:iam::640000000037:user/kd",
|
66
|
+
# :path=>"/",
|
67
|
+
# :user_name=>"kd",
|
68
|
+
# :user_id=>"AID000000000000000WZ2"}],
|
69
|
+
# :group_name=>"kd_test_1",
|
70
|
+
# :group_id=>"AGP000000000000000UTY",
|
71
|
+
# :path=>"/kd1/"}
|
72
|
+
#
|
73
|
+
def get_group(group_name, options={}, &block)
|
74
|
+
options[:group_name] = group_name
|
75
|
+
incrementally_list_iam_resources('GetGroup', options, :items => :users, :except => [:marker, :is_truncated], &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Deletes the specified group. The group must not contain any Users or have any attached policies.
|
79
|
+
#
|
80
|
+
# iam.delete_group('kd_test_3') #=> true
|
81
|
+
#
|
82
|
+
def delete_group(group_name)
|
83
|
+
request_hash = { 'GroupName' => group_name }
|
84
|
+
link = generate_request("DeleteGroup", request_hash)
|
85
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
86
|
+
end
|
87
|
+
|
88
|
+
#-----------------------------------------------------------------
|
89
|
+
# Group Policies
|
90
|
+
#-----------------------------------------------------------------
|
91
|
+
|
92
|
+
# Lists the names of the policies associated with the specified group.
|
93
|
+
#
|
94
|
+
# Options: :max_items, :marker
|
95
|
+
#
|
96
|
+
# iam.list_group_policies('kd_test') #=> ["kd_policy_1"]
|
97
|
+
#
|
98
|
+
def list_group_policies(group_name, options={}, &block)
|
99
|
+
options[:group_name] = group_name
|
100
|
+
incrementally_list_iam_resources('ListGroupPolicies', options, :parser => BasicIamListParser, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Adds (or updates) a policy document associated with the specified group.
|
104
|
+
#
|
105
|
+
# iam.put_group_policy('kd_test', 'kd_policy_1', %Q({"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]})) #=> true
|
106
|
+
#
|
107
|
+
def put_group_policy(group_name, policy_name, policy_document)
|
108
|
+
request_hash = { 'GroupName' => group_name,
|
109
|
+
'PolicyDocument' => policy_document,
|
110
|
+
'PolicyName' => policy_name }
|
111
|
+
link = generate_request_impl(:post, "PutGroupPolicy", request_hash)
|
112
|
+
result = request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
113
|
+
result[:policy_document] = URI::decode(result[:policy_document])
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
# Retrieves the specified policy document for the specified group.
|
118
|
+
#
|
119
|
+
# iam.get_group_policy('kd_test', 'kd_policy_1') #=>
|
120
|
+
# {:policy_name=>"kd_policy_1",
|
121
|
+
# :policy_document=>"{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}",
|
122
|
+
# :group_name=>"kd_test"}
|
123
|
+
#
|
124
|
+
def get_group_policy(group_name, policy_name)
|
125
|
+
request_hash = { 'GroupName' => group_name,
|
126
|
+
'PolicyName' => policy_name }
|
127
|
+
link = generate_request("GetGroupPolicy", request_hash)
|
128
|
+
request_info(link, GetGroupPolicyParser.new(:logger => @logger))
|
129
|
+
end
|
130
|
+
|
131
|
+
# Deletes the specified policy that is associated with the specified group
|
132
|
+
#
|
133
|
+
# iam.delete_group_policy('kd_test', 'kd_policy_1') #=> true
|
134
|
+
#
|
135
|
+
def delete_group_policy(group_name, policy_name)
|
136
|
+
request_hash = { 'GroupName' => group_name,
|
137
|
+
'PolicyName' => policy_name }
|
138
|
+
link = generate_request("DeleteGroupPolicy", request_hash)
|
139
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
140
|
+
end
|
141
|
+
|
142
|
+
#-----------------------------------------------------------------
|
143
|
+
# PARSERS:
|
144
|
+
#-----------------------------------------------------------------
|
145
|
+
|
146
|
+
class ListGroupsParser < BasicIamListParser #:nodoc:
|
147
|
+
def reset
|
148
|
+
@expected_tags = %w{ Arn GroupId GroupName Path }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class CreateGroupParser < BasicIamParser #:nodoc:
|
153
|
+
def reset
|
154
|
+
@expected_tags = %w{ Arn GroupId GroupName Path }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
class GetGroupParser < RightAWSParser #:nodoc:
|
159
|
+
def tagstart(name, attributes)
|
160
|
+
@item = {} if name == 'member'
|
161
|
+
end
|
162
|
+
def tagend(name)
|
163
|
+
case name
|
164
|
+
when 'Marker' then @result[:marker] = @text
|
165
|
+
when 'IsTruncated' then @result[:is_truncated] = @text == 'true'
|
166
|
+
|
167
|
+
when 'GroupName' then @result[:group_name] = @text
|
168
|
+
when 'GroupId' then @result[:group_id] = @text
|
169
|
+
when 'UserName' then @item[:user_name] = @text
|
170
|
+
when 'UserId' then @item[:user_id] = @text
|
171
|
+
when 'member' then @result[:users] << @item
|
172
|
+
else
|
173
|
+
case full_tag_name
|
174
|
+
when %r{/Group/Path$} then @result[:path] = @text
|
175
|
+
when %r{/Group/Arn$} then @result[:arn] = @text
|
176
|
+
when %r{/member/Path$} then @item[:path] = @text
|
177
|
+
when %r{/member/Arn$} then @item[:arn] = @text
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
def reset
|
182
|
+
@result = { :users => [] }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class GetGroupPolicyParser < BasicIamParser #:nodoc:
|
187
|
+
def reset
|
188
|
+
@expected_tags = %w{ GroupName PolicyDocument PolicyName }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|