1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|compute] fix revoke_security_group method signature

This commit is contained in:
geemus 2011-03-03 15:44:49 -08:00
parent 1397c2d613
commit 17e137efa0
2 changed files with 93 additions and 60 deletions

View file

@ -8,14 +8,13 @@ module Fog
# Remove permissions from a security group
#
# ==== Parameters
# * options<~Hash>:
# * 'GroupName'<~String> - Name of group
# * options<~Hash>:
# * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
# * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
# or
# * 'CidrIp' - CIDR range
# * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
# * 'GroupName' - Name of group to modify
# * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
# * 'ToPort' - End of port range (or -1 for ICMP wildcard)
#
@ -24,9 +23,18 @@ module Fog
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'return'<~Boolean> - success?
def revoke_security_group_ingress(options = {})
def revoke_security_group_ingress(group_name, options = {})
if group_name.is_a?(Hash)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute#revoke_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
options = group_name
group_name = options['GroupName']
end
request({
'Action' => 'RevokeSecurityGroupIngress',
'GroupName' => group_name,
:idempotent => true,
:parser => Fog::Parsers::AWS::Compute::Basic.new
}.merge!(options))
@ -36,13 +44,21 @@ module Fog
class Mock
def revoke_security_group_ingress(options = {})
def revoke_security_group_ingress(group_name, options = {})
if group_name.is_a?(Hash)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute#revoke_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
options = group_name
group_name = options['GroupName']
end
response = Excon::Response.new
group = @data[:security_groups][options['GroupName']]
group = @data[:security_groups][group_name]
if group
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
if options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
group['ipPermissions'].delete_if {|permission|
permission['groups'].first['groupName'] == options['GroupName']
permission['groups'].first['groupName'] == group_name
}
else
ingress = group['ipPermissions'].select {|permission|
@ -66,7 +82,7 @@ module Fog
}
response
else
raise Fog::AWS::Compute::NotFound.new("The security group '#{options['GroupName']}' does not exist")
raise Fog::AWS::Compute::NotFound.new("The security group '#{group_name}' does not exist")
end
end

View file

@ -24,21 +24,25 @@ Shindo.tests('AWS::Compute | security group requests', ['aws']) do
AWS[:compute].create_security_group('fog_security_group', 'tests group').body
end
tests("#authorize_security_group_ingress({'FromPort' => 80, 'GroupName' => 'fog_security_group', 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].authorize_security_group_ingress({
tests("#authorize_security_group_ingress('fog_security_group', {'FromPort' => 80, 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].authorize_security_group_ingress(
'fog_security_group',
{
'FromPort' => 80,
'GroupName' => 'fog_security_group',
'IpProtocol' => 'tcp',
'ToPort' => 80,
}).body
}
).body
end
tests("#authorize_security_group_ingress({'GroupName' => 'fog_security_group', 'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].authorize_security_group_ingress({
'GroupName' => 'fog_security_group',
tests("#authorize_security_group_ingress('fog_security_group', {'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].authorize_security_group_ingress(
'fog_security_group',
{
'SourceSecurityGroupName' => 'fog_security_group',
'SourceSecurityGroupOwnerId' => @owner_id
}).body
}
).body
end
tests("#describe_security_groups").formats(@security_groups_format) do
@ -49,21 +53,26 @@ Shindo.tests('AWS::Compute | security group requests', ['aws']) do
AWS[:compute].describe_security_groups('group-name' => 'fog_security_group').body
end
tests("#revoke_security_group_ingress({'FromPort' => 80, 'GroupName' => 'fog_security_group', 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].revoke_security_group_ingress({
tests("#revoke_security_group_ingress('fog_security_group', {'FromPort' => 80, 'IpProtocol' => 'tcp', 'toPort' => 80})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].revoke_security_group_ingress(
'fog_security_group',
{
'FromPort' => 80,
'GroupName' => 'fog_security_group',
'IpProtocol' => 'tcp',
'ToPort' => 80,
}).body
}
).body
end
tests("#revoke_security_group_ingress({'GroupName' => 'fog_security_group', 'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].revoke_security_group_ingress({
tests("#revoke_security_group_ingress('fog_security_group', {'SourceSecurityGroupName' => 'fog_security_group', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").formats(AWS::Compute::Formats::BASIC) do
AWS[:compute].revoke_security_group_ingress(
'fog_security_group',
{
'GroupName' => 'fog_security_group',
'SourceSecurityGroupName' => 'fog_security_group',
'SourceSecurityGroupOwnerId' => @owner_id
}).body
}
).body
end
tests("#delete_security_group('fog_security_group')").formats(AWS::Compute::Formats::BASIC) do
@ -79,38 +88,46 @@ Shindo.tests('AWS::Compute | security group requests', ['aws']) do
AWS[:compute].create_security_group(@security_group.name, @security_group.description)
end
tests("#authorize_security_group_ingress({'FromPort' => 80, 'GroupName' => 'not_a_group_name', 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].authorize_security_group_ingress({
tests("#authorize_security_group_ingress('not_a_group_name', {'FromPort' => 80, 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].authorize_security_group_ingress(
'not_a_group_name',
{
'FromPort' => 80,
'GroupName' => 'not_a_group_name',
'IpProtocol' => 'tcp',
'ToPort' => 80,
})
}
)
end
tests("#authorize_security_group_ingress({'GroupName' => 'not_a_group_name', 'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].authorize_security_group_ingress({
'GroupName' => 'not_a_group_name',
tests("#authorize_security_group_ingress('not_a_group_name', {'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].authorize_security_group_ingress(
'not_a_group_name',
{
'SourceSecurityGroupName' => 'not_a_group_name',
'SourceSecurityGroupOwnerId' => @owner_id
})
}
)
end
tests("#revoke_security_group_ingress({'FromPort' => 80, 'GroupName' => 'not_a_group_name', 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].revoke_security_group_ingress({
tests("#revoke_security_group_ingress('not_a_group_name', {'FromPort' => 80, 'IpProtocol' => 'tcp', 'toPort' => 80})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].revoke_security_group_ingress(
'not_a_group_name',
{
'FromPort' => 80,
'GroupName' => 'not_a_group_name',
'IpProtocol' => 'tcp',
'ToPort' => 80,
})
}
)
end
tests("#revoke_security_group_ingress({'GroupName' => 'not_a_group_name', 'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].revoke_security_group_ingress({
'GroupName' => 'not_a_group_name',
tests("#revoke_security_group_ingress('not_a_group_name', {'SourceSecurityGroupName' => 'not_a_group_name', 'SourceSecurityGroupOwnerId' => '#{@owner_id}'})").raises(Fog::AWS::Compute::NotFound) do
AWS[:compute].revoke_security_group_ingress(
'not_a_group_name',
{
'SourceSecurityGroupName' => 'not_a_group_name',
'SourceSecurityGroupOwnerId' => @owner_id
})
}
)
end
tests("#delete_security_group('not_a_group_name')").raises(Fog::AWS::Compute::NotFound) do