mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #822 from portertech/vpc-fixes
[vpc-fixes] AWS security group model + VPC
This commit is contained in:
commit
16dbd66e7a
4 changed files with 49 additions and 25 deletions
|
@ -245,6 +245,7 @@ module Fog
|
|||
end
|
||||
|
||||
def self.parse_security_group_options(group_name, options)
|
||||
options ||= Hash.new
|
||||
if group_name.is_a?(Hash)
|
||||
options = group_name
|
||||
elsif group_name
|
||||
|
@ -254,11 +255,13 @@ module Fog
|
|||
options = options.clone
|
||||
options['GroupName'] = group_name
|
||||
end
|
||||
if !options.key?('GroupName') && !options.key?('GroupId')
|
||||
name_specified = options.key?('GroupName') && !options['GroupName'].nil?
|
||||
group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
|
||||
unless name_specified || group_id_specified
|
||||
raise Fog::Compute::AWS::Error, 'Neither GroupName nor GroupId specified'
|
||||
end
|
||||
if options.key?('GroupName') && options.key?('GroupId')
|
||||
raise Fog::Compute::AWS::Error, 'Both GroupName and GroupId specified'
|
||||
if name_specified && group_id_specified
|
||||
options.delete('GroupName')
|
||||
end
|
||||
options
|
||||
end
|
||||
|
|
|
@ -40,12 +40,13 @@ module Fog
|
|||
#
|
||||
|
||||
def authorize_group_and_owner(group, owner = nil)
|
||||
requires :name
|
||||
requires_one :name, :group_id
|
||||
|
||||
connection.authorize_security_group_ingress(
|
||||
name,
|
||||
'SourceSecurityGroupName' => group,
|
||||
'SourceSecurityGroupOwnerId' => owner
|
||||
'GroupId' => group_id,
|
||||
'SourceSecurityGroupName' => group,
|
||||
'SourceSecurityGroupOwnerId' => owner
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -78,14 +79,23 @@ module Fog
|
|||
#
|
||||
|
||||
def authorize_port_range(range, options = {})
|
||||
requires :name
|
||||
requires_one :name, :group_id
|
||||
|
||||
connection.authorize_security_group_ingress(
|
||||
name,
|
||||
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
|
||||
'FromPort' => range.min,
|
||||
'ToPort' => range.max,
|
||||
'IpProtocol' => options[:ip_protocol] || 'tcp'
|
||||
'GroupId' => group_id,
|
||||
'IpPermissions' => [
|
||||
{
|
||||
'FromPort' => range.min,
|
||||
'ToPort' => range.max,
|
||||
'IpProtocol' => options[:ip_protocol] || 'tcp',
|
||||
'IpRanges' => [
|
||||
{
|
||||
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -99,7 +109,7 @@ module Fog
|
|||
#
|
||||
|
||||
def destroy
|
||||
requires :name
|
||||
requires_one :name, :group_id
|
||||
|
||||
if group_id.nil?
|
||||
connection.delete_security_group(name)
|
||||
|
@ -136,12 +146,13 @@ module Fog
|
|||
#
|
||||
|
||||
def revoke_group_and_owner(group, owner = nil)
|
||||
requires :name
|
||||
requires_one :name, :group_id
|
||||
|
||||
connection.revoke_security_group_ingress(
|
||||
name,
|
||||
'SourceSecurityGroupName' => group,
|
||||
'SourceSecurityGroupOwnerId' => owner
|
||||
'GroupId' => group_id,
|
||||
'SourceSecurityGroupName' => group,
|
||||
'SourceSecurityGroupOwnerId' => owner
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -174,14 +185,23 @@ module Fog
|
|||
#
|
||||
|
||||
def revoke_port_range(range, options = {})
|
||||
requires :name
|
||||
requires_one :name, :group_id
|
||||
|
||||
connection.revoke_security_group_ingress(
|
||||
name,
|
||||
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
|
||||
'FromPort' => range.min,
|
||||
'ToPort' => range.max,
|
||||
'IpProtocol' => options[:ip_protocol] || 'tcp'
|
||||
'GroupId' => group_id,
|
||||
'IpPermissions' => [
|
||||
{
|
||||
'FromPort' => range.min,
|
||||
'ToPort' => range.max,
|
||||
'IpProtocol' => options[:ip_protocol] || 'tcp',
|
||||
'IpRanges' => [
|
||||
{
|
||||
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ module Fog
|
|||
when 'architecture', 'clientToken', 'dnsName', 'imageId',
|
||||
'instanceId', 'instanceType', 'ipAddress', 'kernelId',
|
||||
'keyName', 'platform', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
|
||||
'reason', 'rootDeviceType', 'subnetId', 'vpcId'
|
||||
'reason', 'rootDeviceType', 'subnetId', 'vpcId'
|
||||
@instance[name] = value
|
||||
when 'attachTime'
|
||||
@block_device_mapping[name] = Time.parse(value)
|
||||
|
|
|
@ -273,7 +273,7 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do
|
|||
end
|
||||
|
||||
group_id = Fog::Compute[:aws].describe_security_groups('group-name' => 'vpc_security_group').body['securityGroupInfo'].first['groupId']
|
||||
|
||||
|
||||
permissions = {
|
||||
'IpPermissions' => [
|
||||
{
|
||||
|
@ -413,9 +413,10 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do
|
|||
end
|
||||
|
||||
broken_params = [
|
||||
[ 'fog_security_group', { 'GroupName' => 'fog_security_group'}],
|
||||
[ 'fog_security_group', { 'GroupId' => 'sg-11223344'}],
|
||||
[ { 'GroupName' => 'fog_security_group', 'GroupId' => 'sg-11223344'}, nil]
|
||||
['fog_security_group', { 'GroupName' => 'fog_security_group' }],
|
||||
[nil, nil],
|
||||
[nil, { 'GroupId' => nil }],
|
||||
[nil, { 'GroupName' => nil, 'GroupId' => nil }]
|
||||
]
|
||||
|
||||
broken_params.each do |list_elem|
|
||||
|
|
Loading…
Add table
Reference in a new issue