awsum 0.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +14 -20
- data/README.rdoc +1 -1
- data/Rakefile +3 -3
- data/functional/ec2/instances_spec.rb +46 -0
- data/functional/spec_helper.rb +71 -0
- data/lib/awsum.rb +2 -2
- data/lib/awsum/ec2.rb +85 -68
- data/lib/awsum/ec2/image.rb +1 -1
- data/lib/awsum/ec2/instance.rb +35 -6
- data/lib/awsum/ec2/parsers/image_parser.rb +3 -5
- data/lib/awsum/ec2/parsers/instance_parser.rb +24 -15
- data/lib/awsum/ec2/parsers/snapshot_parser.rb +3 -3
- data/lib/awsum/ec2/parsers/tag_parser.rb +56 -0
- data/lib/awsum/ec2/parsers/volume_parser.rb +3 -5
- data/lib/awsum/ec2/region.rb +8 -5
- data/lib/awsum/ec2/security_group.rb +12 -16
- data/lib/awsum/ec2/snapshot.rb +9 -0
- data/lib/awsum/ec2/state.rb +22 -0
- data/lib/awsum/ec2/tag.rb +17 -0
- data/lib/awsum/ec2/volume.rb +12 -2
- data/lib/awsum/requestable.rb +53 -3
- data/spec/fixtures/ec2/authorize_group_access.xml +12 -0
- data/spec/fixtures/ec2/create_security_group.xml +3 -3
- data/spec/fixtures/ec2/delete_security_group.xml +3 -3
- data/spec/fixtures/ec2/purchase_reserved_instances_offering2.xml +5 -0
- data/spec/fixtures/ec2/tags.xml +12 -0
- data/spec/lib/awsum/ec2/image_spec.rb +60 -0
- data/spec/lib/awsum/ec2/instance_spec.rb +39 -1
- data/spec/lib/awsum/ec2/parsers/instance_parser_spec.rb +4 -3
- data/spec/lib/awsum/ec2/parsers/tag_parser_spec.rb +29 -0
- data/spec/lib/awsum/ec2/region_spec.rb +31 -2
- data/spec/lib/awsum/ec2/reserved_instance_spec.rb +3 -19
- data/spec/lib/awsum/ec2/security_group_spec.rb +123 -51
- data/spec/lib/awsum/ec2/snapshots_spec.rb +27 -1
- data/spec/lib/awsum/ec2/state_spec.rb +11 -0
- data/spec/lib/awsum/ec2/tag_spec.rb +45 -0
- data/spec/lib/awsum/ec2/volume_spec.rb +47 -0
- data/spec/lib/awsum/requestable_spec.rb +1 -1
- data/tools/dump.rb +55 -0
- metadata +176 -32
- data/.gitignore +0 -5
- data/spec/fixtures/ec2/purchase_reserved_instances_offerings.xml +0 -6
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
|
3
|
+
<requestId>26e2d0ad-6af4-40ff-bd0b-b7f7a4a26036</requestId>
|
4
|
+
<securityGroupInfo>
|
5
|
+
<item>
|
6
|
+
<ownerId>026338013131</ownerId>
|
7
|
+
<groupName>test-group</groupName>
|
8
|
+
<groupDescription>A test group</groupDescription>
|
9
|
+
<ipPermissions/>
|
10
|
+
</item>
|
11
|
+
</securityGroupInfo>
|
12
|
+
</DescribeSecurityGroupsResponse>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/
|
3
|
-
<requestId>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
|
3
|
+
<requestId>60be0979-1bb8-4e5a-9c6b-0b5d17b9d22b</requestId>
|
4
4
|
<return>true</return>
|
5
5
|
</CreateSecurityGroupResponse>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/
|
3
|
-
<requestId>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
|
3
|
+
<requestId>37eaab54-074d-466d-a38e-0137d221c72d</requestId>
|
4
4
|
<return>true</return>
|
5
5
|
</DeleteSecurityGroupResponse>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<PurchaseReservedInstancesOfferingResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
|
3
|
+
<requestId>c9f3d2f8-cb9d-467f-9a4d-b3a682ad2460</requestId>
|
4
|
+
<reservedInstancesId>4357912c-baae-4f49-80bc-61fcb17c97d9</reservedInstancesId>
|
5
|
+
</PurchaseReservedInstancesOfferingResponse>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<DescribeTagsResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
|
3
|
+
<requestId>ba2577eb-3227-46b7-b80c-df1353c320d1</requestId>
|
4
|
+
<tagSet>
|
5
|
+
<item>
|
6
|
+
<resourceId>ari-f9c22690</resourceId>
|
7
|
+
<resourceType>image</resourceType>
|
8
|
+
<key>name</key>
|
9
|
+
<value>Test</value>
|
10
|
+
</item>
|
11
|
+
</tagSet>
|
12
|
+
</DescribeTagsResponse>
|
@@ -42,6 +42,66 @@ module Awsum
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "retrieving a filtered list of images" do
|
46
|
+
before do
|
47
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeImages.*Filter.1.Name=architecture.*Filter.1.Value.1=i386|, :body => fixture('ec2/images'), :status => 200)
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:result) { ec2.images(:filter => {:architecture => 'i386'}) }
|
51
|
+
|
52
|
+
it "should return an array of images" do
|
53
|
+
result.first.should be_a(Awsum::Ec2::Image)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "retrieving a filtered list of images with a complicated filter" do
|
58
|
+
before do
|
59
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeImages.*Filter.1.Name=tag%3AName.*Filter.1.Value.1=Test.*Filter.2.Name=image-type.*Filter.2.Value.1=machine.*Filter.2.Value.2=kernel.*Filter.2.Value.3=ramdisk.*Filter.3.Name=architecture.*Filter.3.Value.1=i386|, :body => fixture('ec2/images'), :status => 200)
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:result) { ec2.images(:filter => {:architecture => 'i386', 'tag:Name' => 'Test', 'image-type' => ['machine', 'kernel', 'ramdisk']}) }
|
63
|
+
|
64
|
+
it "should return an array of images" do
|
65
|
+
result.first.should be_a(Awsum::Ec2::Image)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "retrieving a filtered list of images by tag" do
|
70
|
+
before do
|
71
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeImages.*Filter.1.Name=tag%3Aname.*Filter.1.Value.1=Test|, :body => fixture('ec2/images'), :status => 200)
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:result) { ec2.images(:tags => {:name => 'Test'}) }
|
75
|
+
|
76
|
+
it "should return an array of images" do
|
77
|
+
result.first.should be_a(Awsum::Ec2::Image)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "retrieving a filtered list of owned images" do
|
82
|
+
before do
|
83
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeImages.*Filter.1.Name=architecture.*Filter.1.Value.1=i386.*Owner.1=self|, :body => fixture('ec2/images'), :status => 200)
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:result) { ec2.my_images(:filter => {:architecture => 'i386'}) }
|
87
|
+
|
88
|
+
it "should return an array of images" do
|
89
|
+
result.first.should be_a(Awsum::Ec2::Image)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "retrieving a filtered list of owned images by tag" do
|
94
|
+
before do
|
95
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeImages.*Filter.1.Name=tag%3Aname.*Filter.1.Value.1=Test.*Owner.1=self|, :body => fixture('ec2/images'), :status => 200)
|
96
|
+
end
|
97
|
+
|
98
|
+
let(:result) { ec2.my_images(:tags => {:name => 'Test'}) }
|
99
|
+
|
100
|
+
it "should return an array of images" do
|
101
|
+
result.first.should be_a(Awsum::Ec2::Image)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
45
105
|
describe "registering an image" do
|
46
106
|
before do
|
47
107
|
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RegisterImage.*ImageLocation=s3.bucket.location|, :body => fixture('ec2/register_image'), :status => 200)
|
@@ -18,6 +18,20 @@ module Awsum
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
describe "running an instance with a tag" do
|
22
|
+
before do
|
23
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RunInstances.*ImageId=ari-f9c22690|, :body => fixture('ec2/run_instances'), :status => 200)
|
24
|
+
|
25
|
+
ec2.should_receive(:create_tags).with(['i-f92fa890'], :name => 'Test')
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:result) { ec2.run_instances 'ari-f9c22690', :tags => {:name => 'Test'} }
|
29
|
+
|
30
|
+
it "should return an array of instances" do
|
31
|
+
result.first.should be_a(Awsum::Ec2::Instance)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
21
35
|
describe "retrieving a list of instances" do
|
22
36
|
before do
|
23
37
|
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeInstances|, :body => fixture('ec2/run_instances'), :status => 200)
|
@@ -30,6 +44,30 @@ module Awsum
|
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
47
|
+
describe "retrieving a list of instances with a filter" do
|
48
|
+
before do
|
49
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeInstances.*Filter.1.Name=architecture.*Filter.1.Value.1=i386|, :body => fixture('ec2/run_instances'), :status => 200)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:result) { ec2.instances(:filter => {:architecture => 'i386'}) }
|
53
|
+
|
54
|
+
it "should return an array of instances" do
|
55
|
+
result.first.should be_a(Awsum::Ec2::Instance)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "retrieving a list of instances by tag" do
|
60
|
+
before do
|
61
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeInstances.*Filter.1.Name=tag%3Aname.*Filter.1.Value.1=Test|, :body => fixture('ec2/run_instances'), :status => 200)
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:result) { ec2.instances(:tags => {:name => 'Test'}) }
|
65
|
+
|
66
|
+
it "should return an array of instances" do
|
67
|
+
result.first.should be_a(Awsum::Ec2::Instance)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
33
71
|
describe "retrieving a single instance" do
|
34
72
|
before do
|
35
73
|
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeInstances.*InstanceId.1=i-3f1cc856|, :body => fixture('ec2/instance'), :status => 200)
|
@@ -90,7 +128,7 @@ module Awsum
|
|
90
128
|
|
91
129
|
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AttachVolume.*InstanceId=i-3f1cc856.*VolumeId=vol-44d6322d|, :body => fixture('ec2/attach_volume'), :status => 200)
|
92
130
|
|
93
|
-
instance.create_volume(10)
|
131
|
+
instance.create_volume(10, :device => '/dev/sdh')
|
94
132
|
end
|
95
133
|
end
|
96
134
|
|
@@ -24,7 +24,7 @@ module Awsum
|
|
24
24
|
:type => 'm1.small',
|
25
25
|
:availability_zone => 'us-east-1b',
|
26
26
|
:launch_time => Time.parse('2008-06-18T12:51:52.000Z'),
|
27
|
-
:state =>
|
27
|
+
:state => Ec2::State.new(0, 'pending')
|
28
28
|
}.each do |key, value|
|
29
29
|
it "should have the correct #{key}" do
|
30
30
|
instance.send(key).should == value
|
@@ -36,7 +36,8 @@ module Awsum
|
|
36
36
|
let(:instance) { result[1] }
|
37
37
|
|
38
38
|
it "should have the correct state" do
|
39
|
-
instance.state.should ==
|
39
|
+
instance.state.should == 16
|
40
|
+
instance.state.should == 'running'
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -64,7 +65,7 @@ module Awsum
|
|
64
65
|
:type => 'm1.small',
|
65
66
|
:availability_zone => 'us-east-1b',
|
66
67
|
:launch_time => Time.parse('2009-01-11T13:09:01.000Z'),
|
67
|
-
:state =>
|
68
|
+
:state => Ec2::State.new(0, 'pending')
|
68
69
|
}.each do |key, value|
|
69
70
|
it "should have the correct #{key}" do
|
70
71
|
instance.send(key).should == value
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Awsum
|
4
|
+
describe Ec2::TagParser do
|
5
|
+
subject { Ec2.new('abc', 'xyz') }
|
6
|
+
let(:ec2) { subject }
|
7
|
+
let(:parser) { Awsum::Ec2::TagParser.new(ec2) }
|
8
|
+
let(:result) { parser.parse(fixture('ec2/tags')) }
|
9
|
+
|
10
|
+
it "should return an array of tags" do
|
11
|
+
result.should be_a(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "the first tag" do
|
15
|
+
let(:tag) { result.first }
|
16
|
+
|
17
|
+
{
|
18
|
+
:resource_id => 'ari-f9c22690',
|
19
|
+
:resource_type => 'image',
|
20
|
+
:key => 'name',
|
21
|
+
:value => 'Test'
|
22
|
+
}.each do |key, value|
|
23
|
+
it "should have the correct #{key}" do
|
24
|
+
tag.send(key).should == value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -28,6 +28,26 @@ module Awsum
|
|
28
28
|
it "should return a region" do
|
29
29
|
result.should be_a(Awsum::Ec2::Region)
|
30
30
|
end
|
31
|
+
|
32
|
+
it "should work in block mode (with a supplied parameter)" do
|
33
|
+
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=DescribeAvailabilityZones|, :body => fixture('ec2/availability_zones'), :status => 200)
|
34
|
+
|
35
|
+
zones = ec2.region('eu-west-1') do |region|
|
36
|
+
region.availability_zones
|
37
|
+
end
|
38
|
+
|
39
|
+
zones.first.should be_a(Awsum::Ec2::AvailabilityZone)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should work in block mode (without a supplied parameter)" do
|
43
|
+
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=DescribeAvailabilityZones|, :body => fixture('ec2/availability_zones'), :status => 200)
|
44
|
+
|
45
|
+
zones = ec2.region('eu-west-1') do
|
46
|
+
availability_zones
|
47
|
+
end
|
48
|
+
|
49
|
+
zones.first.should be_a(Awsum::Ec2::AvailabilityZone)
|
50
|
+
end
|
31
51
|
end
|
32
52
|
|
33
53
|
describe "a region" do
|
@@ -46,7 +66,7 @@ module Awsum
|
|
46
66
|
it "should work in block mode (with a supplied parameter)" do
|
47
67
|
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=DescribeAvailabilityZones|, :body => fixture('ec2/availability_zones'), :status => 200)
|
48
68
|
|
49
|
-
zones =
|
69
|
+
zones = region.use do |region|
|
50
70
|
region.availability_zones
|
51
71
|
end
|
52
72
|
|
@@ -56,13 +76,22 @@ module Awsum
|
|
56
76
|
it "should work in block mode (without a supplied parameter)" do
|
57
77
|
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=DescribeAvailabilityZones|, :body => fixture('ec2/availability_zones'), :status => 200)
|
58
78
|
|
59
|
-
zones =
|
79
|
+
zones = region.use do
|
60
80
|
availability_zones
|
61
81
|
end
|
62
82
|
|
63
83
|
zones.first.should be_a(Awsum::Ec2::AvailabilityZone)
|
64
84
|
end
|
65
85
|
|
86
|
+
it "should be able to set a region" do
|
87
|
+
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=DescribeAvailabilityZones|, :body => fixture('ec2/availability_zones'), :status => 200)
|
88
|
+
|
89
|
+
region.use
|
90
|
+
zones = ec2.availability_zones
|
91
|
+
|
92
|
+
zones.first.should be_a(Awsum::Ec2::AvailabilityZone)
|
93
|
+
end
|
94
|
+
|
66
95
|
it "should receive ec2 methods (pass-through)" do
|
67
96
|
FakeWeb.register_uri(:get, %r|https://eu-west-1\.ec2\.amazonaws\.com/?.*Action=RunInstances.*ImageId=9-123456789|, :body => fixture('ec2/run_instances'), :status => 200)
|
68
97
|
|
@@ -8,29 +8,13 @@ module Awsum
|
|
8
8
|
|
9
9
|
describe "purchasing a reserved instance" do
|
10
10
|
before do
|
11
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=PurchaseReservedInstancesOffering.*InstanceCount
|
12
|
-
|
13
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeReservedInstances.*ReservedInstanceId.1=1ba8e2e3-e6f7-4ef5-8c6c-6c6e4fad0a56|, :body => fixture('ec2/reserved_instances'), :status => 200)
|
11
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=PurchaseReservedInstancesOffering.*InstanceCount=1.*ReservedInstancesOfferingId=e5a2ff3b-f6eb-4b4e-83f8-b879d7060257|, :body => fixture('ec2/purchase_reserved_instances_offering'), :status => 200)
|
14
12
|
end
|
15
13
|
|
16
14
|
let(:result) { ec2.purchase_reserved_instances_offering 'e5a2ff3b-f6eb-4b4e-83f8-b879d7060257' }
|
17
15
|
|
18
|
-
it "should return
|
19
|
-
result.should
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "purchasing multiple reserved instances" do
|
24
|
-
before do
|
25
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=PurchaseReservedInstancesOffering.*InstanceCount.1=1.*InstanceCount.2=2.*ReservedInstancesOfferingId.1=e5a2ff3b-f6eb-4b4e-83f8-b879d7060257.*ReservedInstancesOfferingId.2=248e7b75-afbc-4724-82b2-d78353299433|, :body => fixture('ec2/purchase_reserved_instances_offering'), :status => 200)
|
26
|
-
|
27
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeReservedInstances.*ReservedInstanceId.1=1ba8e2e3-e6f7-4ef5-8c6c-6c6e4fad0a56|, :body => fixture('ec2/reserved_instances'), :status => 200)
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:result) { ec2.purchase_reserved_instances_offering ['e5a2ff3b-f6eb-4b4e-83f8-b879d7060257', '248e7b75-afbc-4724-82b2-d78353299433'], [1, 2] }
|
31
|
-
|
32
|
-
it "should return an array of reserverd instances" do
|
33
|
-
result.first.should be_a(Awsum::Ec2::ReservedInstance)
|
16
|
+
it "should return an array of reserved instance ids" do
|
17
|
+
result.should == ['1ba8e2e3-e6f7-4ef5-8c6c-6c6e4fad0a56']
|
34
18
|
end
|
35
19
|
end
|
36
20
|
|
@@ -51,90 +51,156 @@ module Awsum
|
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "authorizing group access" do
|
54
|
-
|
55
|
-
|
54
|
+
context "with a single option hash" do
|
55
|
+
before do
|
56
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return true" do
|
60
|
+
ec2.authorize_security_group_ingress('test', {:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]}).should be_true
|
61
|
+
end
|
56
62
|
end
|
57
63
|
|
58
|
-
|
59
|
-
|
64
|
+
context "with an array of option hashes" do
|
65
|
+
before do
|
66
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.Groups.1.GroupName=webservers.*IpPermissions.2.Groups.2.GroupName=dbservers.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return true" do
|
70
|
+
ec2.authorize_security_group_ingress('test', [
|
71
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]},
|
72
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :groups => [{:group_name => :webservers}, {:group_name => :dbservers}]}
|
73
|
+
]).should be_true
|
74
|
+
end
|
60
75
|
end
|
61
76
|
end
|
62
77
|
|
63
78
|
describe "authorizing ip access" do
|
64
|
-
|
65
|
-
|
66
|
-
|
79
|
+
context "with a single option hash" do
|
80
|
+
before do
|
81
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
82
|
+
end
|
67
83
|
|
68
|
-
|
69
|
-
|
84
|
+
it "should return true" do
|
85
|
+
ec2.authorize_security_group_ingress('test', [{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]}])
|
86
|
+
end
|
70
87
|
end
|
71
|
-
end
|
72
88
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
89
|
+
context "with an array of option hashes" do
|
90
|
+
before do
|
91
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.2.IpRanges.2.CidrIp=12.34.56.78%2F0.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
92
|
+
end
|
78
93
|
|
79
|
-
|
80
|
-
|
81
|
-
|
94
|
+
it "should return true" do
|
95
|
+
ec2.authorize_security_group_ingress('test', [
|
96
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]},
|
97
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}, {:cidr_ip => '12.34.56.78/0'}]}
|
98
|
+
])
|
99
|
+
end
|
82
100
|
end
|
83
101
|
end
|
84
102
|
|
85
|
-
describe "
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
103
|
+
describe "authorizing both group and ip access" do
|
104
|
+
context "with a single call" do
|
105
|
+
before do
|
106
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.Groups.1.GroupName=webservers.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
107
|
+
end
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
109
|
+
it "should return true" do
|
110
|
+
ec2.authorize_security_group_ingress('test', [
|
111
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]},
|
112
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :groups => [{:group_name => 'webservers'}]}
|
113
|
+
])
|
114
|
+
end
|
94
115
|
end
|
95
116
|
end
|
96
117
|
|
97
118
|
describe "revoking group access" do
|
98
|
-
|
99
|
-
|
119
|
+
context "with a single option hash" do
|
120
|
+
before do
|
121
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return true" do
|
125
|
+
ec2.revoke_security_group_ingress('test', {:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]}).should be_true
|
126
|
+
end
|
100
127
|
end
|
101
128
|
|
102
|
-
|
103
|
-
|
129
|
+
context "with an array of option hashes" do
|
130
|
+
before do
|
131
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.Groups.1.GroupName=webservers.*IpPermissions.2.Groups.2.GroupName=dbservers.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return true" do
|
135
|
+
ec2.revoke_security_group_ingress('test', [
|
136
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]},
|
137
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :groups => [{:group_name => :webservers}, {:group_name => :dbservers}]}
|
138
|
+
]).should be_true
|
139
|
+
end
|
104
140
|
end
|
105
141
|
end
|
106
142
|
|
107
143
|
describe "revoking ip access" do
|
108
|
-
|
109
|
-
|
144
|
+
context "with a single option hash" do
|
145
|
+
before do
|
146
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should return true" do
|
150
|
+
ec2.revoke_security_group_ingress('test', [{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]}])
|
151
|
+
end
|
110
152
|
end
|
111
153
|
|
112
|
-
|
113
|
-
|
154
|
+
context "with an array of option hashes" do
|
155
|
+
before do
|
156
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.2.IpRanges.2.CidrIp=12.34.56.78%2F0.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should return true" do
|
160
|
+
ec2.revoke_security_group_ingress('test', [
|
161
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]},
|
162
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}, {:cidr_ip => '12.34.56.78/0'}]}
|
163
|
+
])
|
164
|
+
end
|
114
165
|
end
|
115
166
|
end
|
116
167
|
|
117
|
-
describe "
|
168
|
+
describe "revoking both group and ip access" do
|
169
|
+
context "with a single call" do
|
170
|
+
before do
|
171
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.Groups.1.GroupName=webservers.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return true" do
|
175
|
+
ec2.revoke_security_group_ingress('test', [
|
176
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]},
|
177
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :groups => [{:group_name => 'webservers'}]}
|
178
|
+
])
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "sending both ip and user/group options to an authorization request" do
|
118
184
|
it "should raise an error" do
|
119
|
-
expect { ec2.
|
185
|
+
expect { ec2.authorize_security_group_ingress('test', [{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}], :groups => [{:group_name => :webservers}]}]) }.to raise_error(ArgumentError)
|
120
186
|
end
|
121
187
|
end
|
122
188
|
|
123
|
-
describe "
|
189
|
+
describe "including a wrong protocol in an authorization request" do
|
124
190
|
it "should raise an error" do
|
125
|
-
expect { ec2.
|
191
|
+
expect { ec2.authorize_security_group_ingress('test', [{:ip_protocol => :test, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]}]) }.to raise_error(ArgumentError)
|
126
192
|
end
|
127
193
|
end
|
128
194
|
|
129
|
-
describe "sending
|
195
|
+
describe "sending both ip and user/group options to a revokation request" do
|
130
196
|
it "should raise an error" do
|
131
|
-
expect { ec2.
|
197
|
+
expect { ec2.authorize_security_group_ingress('test', [{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}], :groups => [{:group_name => :webservers}]}]) }.to raise_error(ArgumentError)
|
132
198
|
end
|
133
199
|
end
|
134
200
|
|
135
|
-
describe "including a wrong protocol in
|
201
|
+
describe "including a wrong protocol in a revokation request" do
|
136
202
|
it "should raise an error" do
|
137
|
-
expect { ec2.
|
203
|
+
expect { ec2.authorize_security_group_ingress('test', [{:ip_protocol => :test, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]}]) }.to raise_error(ArgumentError)
|
138
204
|
end
|
139
205
|
end
|
140
206
|
|
@@ -146,27 +212,33 @@ module Awsum
|
|
146
212
|
let(:security_group) { ec2.security_group('default') }
|
147
213
|
|
148
214
|
it "should be able to authorize a group" do
|
149
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=default.*
|
215
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=default.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
150
216
|
|
151
|
-
security_group.
|
217
|
+
security_group.authorize({:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]}).should be_true
|
152
218
|
end
|
153
219
|
|
154
220
|
it "should be able to authorize ip access" do
|
155
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*CidrIp=
|
221
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=default.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.2.IpRanges.2.CidrIp=12.34.56.78%2F0.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
156
222
|
|
157
|
-
security_group.
|
223
|
+
security_group.authorize([
|
224
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]},
|
225
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}, {:cidr_ip => '12.34.56.78/0'}]}
|
226
|
+
])
|
158
227
|
end
|
159
228
|
|
160
229
|
it "should be able to revoke a group" do
|
161
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=default.*
|
230
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=default.*IpPermissions.1.FromPort=80.*IpPermissions.1.Groups.1.GroupName=webservers.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.ToPort=80.*IpPermissions.2.FromPort=22.*IpPermissions.2.Groups.1.GroupName=webservers.*IpPermissions.2.Groups.2.GroupName=dbservers.*IpPermissions.2.IpProtocol=tcp.*IpPermissions.2.ToPort=22|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
162
231
|
|
163
|
-
security_group.
|
232
|
+
security_group.revoke([
|
233
|
+
{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :groups => [{:group_name => :webservers}]},
|
234
|
+
{:ip_protocol => :tcp, :from_port => 22, :to_port => 22, :groups => [{:group_name => :webservers}, {:group_name => :dbservers}]}
|
235
|
+
]).should be_true
|
164
236
|
end
|
165
237
|
|
166
|
-
it "should be able to
|
167
|
-
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*
|
238
|
+
it "should be able to revoke ip access" do
|
239
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=default.*IpPermissions.1.FromPort=80.*IpPermissions.1.IpProtocol=tcp.*IpPermissions.1.IpRanges.1.CidrIp=12.23.34.45%2F0.*IpPermissions.1.ToPort=80|, :body => fixture('ec2/authorize_group_access'), :status => 200)
|
168
240
|
|
169
|
-
security_group.
|
241
|
+
security_group.revoke([{:ip_protocol => :tcp, :from_port => 80, :to_port => 80, :ip_ranges => [{:cidr_ip => '12.23.34.45/0'}]}])
|
170
242
|
end
|
171
243
|
|
172
244
|
it "should be able to delete itself" do
|