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

[aws|compute] authorize/revoke security group requests name should be required param

This commit is contained in:
crazed 2011-02-22 08:34:43 +08:00 committed by Wesley Beary
parent 8880448fcb
commit 4f9972efcd
2 changed files with 30 additions and 12 deletions

View file

@ -42,7 +42,7 @@ module Fog
requires :name requires :name
connection.authorize_security_group_ingress( connection.authorize_security_group_ingress(
'GroupName' => name, name,
'SourceSecurityGroupName' => group, 'SourceSecurityGroupName' => group,
'SourceSecurityGroupOwnerId' => owner 'SourceSecurityGroupOwnerId' => owner
) )
@ -80,9 +80,9 @@ module Fog
requires :name requires :name
connection.authorize_security_group_ingress( connection.authorize_security_group_ingress(
name,
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0', 'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
'FromPort' => range.min, 'FromPort' => range.min,
'GroupName' => name,
'ToPort' => range.max, 'ToPort' => range.max,
'IpProtocol' => options[:ip_protocol] || 'tcp' 'IpProtocol' => options[:ip_protocol] || 'tcp'
) )
@ -134,7 +134,7 @@ module Fog
requires :name requires :name
connection.revoke_security_group_ingress( connection.revoke_security_group_ingress(
'GroupName' => name, name,
'SourceSecurityGroupName' => group, 'SourceSecurityGroupName' => group,
'SourceSecurityGroupOwnerId' => owner 'SourceSecurityGroupOwnerId' => owner
) )
@ -172,9 +172,9 @@ module Fog
requires :name requires :name
connection.revoke_security_group_ingress( connection.revoke_security_group_ingress(
name,
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0', 'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
'FromPort' => range.min, 'FromPort' => range.min,
'GroupName' => name,
'ToPort' => range.max, 'ToPort' => range.max,
'IpProtocol' => options[:ip_protocol] || 'tcp' 'IpProtocol' => options[:ip_protocol] || 'tcp'
) )

View file

@ -6,8 +6,8 @@ module Fog
# Add permissions to a security group # Add permissions to a security group
# #
# ==== Parameters # ==== Parameters
# * group_name<~String> - Name of group
# * options<~Hash>: # * options<~Hash>:
# * 'GroupName'<~String> - Name of group
# * 'SourceSecurityGroupName'<~String> - Name of security group to authorize # * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
# * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize # * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
# or # or
@ -22,9 +22,18 @@ module Fog
# * body<~Hash>: # * body<~Hash>:
# * 'requestId'<~String> - Id of request # * 'requestId'<~String> - Id of request
# * 'return'<~Boolean> - success? # * 'return'<~Boolean> - success?
def authorize_security_group_ingress(options = {}) def authorize_security_group_ingress(group_name, options = {})
if group_name.is_a?(Hash)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute#authorize_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({ request({
'Action' => 'AuthorizeSecurityGroupIngress', 'Action' => 'AuthorizeSecurityGroupIngress',
'GroupName' => group_name,
:idempotent => true, :idempotent => true,
:parser => Fog::Parsers::AWS::Compute::Basic.new :parser => Fog::Parsers::AWS::Compute::Basic.new
}.merge!(options)) }.merge!(options))
@ -34,16 +43,25 @@ module Fog
class Mock class Mock
def authorize_security_group_ingress(options = {}) def authorize_security_group_ingress(group_name, options = {})
if group_name.is_a?(Hash)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute#authorize_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 response = Excon::Response.new
group = @data[:security_groups][options['GroupName']] group = @data[:security_groups][group_name]
if group if group
group['ipPermissions'] ||= [] group['ipPermissions'] ||= []
if options['GroupName'] && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId'] if group_name && options['SourceSecurityGroupName'] && options['SourceSecurityGroupOwnerId']
['tcp', 'udp'].each do |protocol| ['tcp', 'udp'].each do |protocol|
group['ipPermissions'] << { group['ipPermissions'] << {
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}], 'groups' => [{'groupName' => group_name, 'userId' => @owner_id}],
'fromPort' => 1, 'fromPort' => 1,
'ipRanges' => [], 'ipRanges' => [],
'ipProtocol' => protocol, 'ipProtocol' => protocol,
@ -51,7 +69,7 @@ module Fog
} }
end end
group['ipPermissions'] << { group['ipPermissions'] << {
'groups' => [{'groupName' => options['GroupName'], 'userId' => @owner_id}], 'groups' => [{'groupName' => group_name, 'userId' => @owner_id}],
'fromPort' => -1, 'fromPort' => -1,
'ipRanges' => [], 'ipRanges' => [],
'ipProtocol' => 'icmp', 'ipProtocol' => 'icmp',
@ -76,7 +94,7 @@ module Fog
} }
response response
else 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
end end