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

first pass at security group mocks

This commit is contained in:
Wesley Beary 2009-09-16 20:02:32 -07:00
parent d968cd153c
commit 0f3cccc566
2 changed files with 126 additions and 54 deletions

View file

@ -1,4 +1,6 @@
module Fog
unless Fog.mocking?
module Fog
module AWS
class EC2
@ -29,4 +31,38 @@ module Fog
end
end
end
else
module Fog
module AWS
class EC2
# TODO: handle the GroupName/Source/Source case
def authorize_security_group_ingress(options = {})
response = Fog::Response.new
group = Fog::AWS::EC2.data[:security_groups][options['GroupName']]
group['ipPermissions'] ||= []
group['ipPermissions'] << {
'groups' => [],
'fromPort' => options['FromPort'],
'ipRanges' => [{ 'cidrIp' => options['CidrIp'] }],
'ipProtocol' => options['IpProtocol'],
'toPort' => options['ToPort']
}
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'return' => true
}
response
end
end
end
end
end

View file

@ -1,4 +1,6 @@
module Fog
unless Fog.mocking?
module Fog
module AWS
class EC2
@ -29,4 +31,38 @@ module Fog
end
end
end
else
module Fog
module AWS
class EC2
# TODO: handle the GroupName/Source/Source case
def revoke_security_group_ingress(options = {})
response = Fog::Response.new
group = Fog::AWS::EC2.data[:security_groups][options['GroupName']]
ingress = group['ipPermissions'].select {|permission|
permission['fromPort'] == options['FromPort'] &&
permission['ipProtocol'] == options['IpProtocol'] &&
permission['toPort'] == options['ToPort'] &&
permission['ipRanges'].first['cidrIp'] == options['CidrIp']
}.first
group['ipPermissions'].delete(ingress)
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'return' => true
}
response
end
end
end
end
end