mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Changes to the security group handling:
* CreateSecurityGroup now includes the group id in the reply, this patch makes the code store this * The patch also changes the delete call to use the group id if present (since you must use the id when deleting VPC groups) * Fix teh security group mock and test code to handle this new behavior
This commit is contained in:
parent
4846a16053
commit
06d2bcdd40
4 changed files with 44 additions and 7 deletions
|
@ -101,7 +101,11 @@ module Fog
|
|||
def destroy
|
||||
requires :name
|
||||
|
||||
connection.delete_security_group(name)
|
||||
if group_id.nil?
|
||||
connection.delete_security_group(name)
|
||||
else
|
||||
connection.delete_security_group(nil, group_id)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -195,6 +199,8 @@ module Fog
|
|||
def save
|
||||
requires :description, :name
|
||||
data = connection.create_security_group(name, description, vpc_id).body
|
||||
new_attributes = data.reject {|key,value| key == 'requestId'}
|
||||
merge_attributes(new_attributes)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
24
lib/fog/aws/parsers/compute/create_security_group.rb
Normal file
24
lib/fog/aws/parsers/compute/create_security_group.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module AWS
|
||||
|
||||
class CreateSecurityGroup < Fog::Parsers::Base
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'return'
|
||||
if value == 'true'
|
||||
@response[name] = true
|
||||
else
|
||||
@response[name] = false
|
||||
end
|
||||
when 'requestId', 'groupId'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/compute/basic'
|
||||
require 'fog/aws/parsers/compute/create_security_group'
|
||||
|
||||
# Create a new security group
|
||||
#
|
||||
|
@ -17,6 +17,7 @@ module Fog
|
|||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
# * 'groupId'<~String> - Id of created group
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSecurityGroup.html]
|
||||
def create_security_group(name, description, vpc_id=nil)
|
||||
|
@ -24,8 +25,8 @@ module Fog
|
|||
'Action' => 'CreateSecurityGroup',
|
||||
'GroupName' => name,
|
||||
'GroupDescription' => description,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new,
|
||||
'VpcId' => vpc_id
|
||||
'VpcId' => vpc_id,
|
||||
:parser => Fog::Parsers::Compute::AWS::CreateSecurityGroup.new
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -48,6 +49,7 @@ module Fog
|
|||
self.data[:security_groups][name] = data
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'groupId' => data['groupId'],
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do
|
||||
@create_security_group_format = {
|
||||
'requestId' => String,
|
||||
'groupId' => String,
|
||||
'return' => Fog::Boolean
|
||||
}
|
||||
|
||||
@security_groups_format = {
|
||||
'requestId' => String,
|
||||
|
@ -23,11 +28,11 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do
|
|||
|
||||
tests('success') do
|
||||
|
||||
tests("#create_security_group('fog_security_group', 'tests group')").formats(AWS::Compute::Formats::BASIC) do
|
||||
tests("#create_security_group('fog_security_group', 'tests group')").formats(@create_security_group_format) do
|
||||
Fog::Compute[:aws].create_security_group('fog_security_group', 'tests group').body
|
||||
end
|
||||
|
||||
tests("#create_security_group('fog_security_group_two', 'tests group')").formats(AWS::Compute::Formats::BASIC) do
|
||||
tests("#create_security_group('fog_security_group_two', 'tests group')").formats(@create_security_group_format) do
|
||||
Fog::Compute[:aws].create_security_group('fog_security_group_two', 'tests group').body
|
||||
end
|
||||
|
||||
|
@ -264,7 +269,7 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do
|
|||
vpc_id = Fog::Compute[:aws].create_vpc('10.255.254.64/28').body['vpcSet'].first['vpcId']
|
||||
|
||||
# Create security group in VPC
|
||||
tests("#create_security_group('vpc_security_group', 'tests group')").formats(AWS::Compute::Formats::BASIC) do
|
||||
tests("#create_security_group('vpc_security_group', 'tests group')").formats(@create_security_group_format) do
|
||||
Fog::Compute[:aws].create_security_group('vpc_security_group', 'tests group', vpc_id).body
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue