mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
security group specs
This commit is contained in:
parent
5775b8b536
commit
f072170cd6
9 changed files with 144 additions and 38 deletions
|
@ -27,6 +27,7 @@ require "#{parsers_directory}/terminate_instances"
|
||||||
|
|
||||||
requests_directory = "#{current_directory}/requests/ec2"
|
requests_directory = "#{current_directory}/requests/ec2"
|
||||||
require "#{requests_directory}/allocate_address"
|
require "#{requests_directory}/allocate_address"
|
||||||
|
require "#{requests_directory}/authorize_security_group_ingress"
|
||||||
require "#{requests_directory}/create_key_pair"
|
require "#{requests_directory}/create_key_pair"
|
||||||
require "#{requests_directory}/create_security_group"
|
require "#{requests_directory}/create_security_group"
|
||||||
require "#{requests_directory}/create_snapshot"
|
require "#{requests_directory}/create_snapshot"
|
||||||
|
@ -44,6 +45,7 @@ require "#{requests_directory}/describe_security_groups"
|
||||||
require "#{requests_directory}/describe_snapshots"
|
require "#{requests_directory}/describe_snapshots"
|
||||||
require "#{requests_directory}/describe_volumes"
|
require "#{requests_directory}/describe_volumes"
|
||||||
require "#{requests_directory}/release_address"
|
require "#{requests_directory}/release_address"
|
||||||
|
require "#{requests_directory}/revoke_security_group_ingress"
|
||||||
require "#{requests_directory}/run_instances"
|
require "#{requests_directory}/run_instances"
|
||||||
require "#{requests_directory}/terminate_instances"
|
require "#{requests_directory}/terminate_instances"
|
||||||
|
|
||||||
|
@ -112,7 +114,7 @@ module Fog
|
||||||
|
|
||||||
response = @connection.request({
|
response = @connection.request({
|
||||||
:body => body,
|
:body => body,
|
||||||
:expects => 200,
|
# :expects => 200,
|
||||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||||
:host => @host,
|
:host => @host,
|
||||||
:method => 'POST',
|
:method => 'POST',
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Fog
|
||||||
if @in_groups
|
if @in_groups
|
||||||
@group[:group_name] = @value
|
@group[:group_name] = @value
|
||||||
else
|
else
|
||||||
@group[:group_name] = @value
|
@security_group[:group_name] = @value
|
||||||
end
|
end
|
||||||
when 'ipPermissions'
|
when 'ipPermissions'
|
||||||
@in_ip_permissions = false
|
@in_ip_permissions = false
|
||||||
|
|
|
@ -5,25 +5,31 @@ module Fog
|
||||||
# Add permissions to a security group
|
# Add permissions to a security group
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * cidr_ip - CIDR range
|
# * options<~Hash>:
|
||||||
# * from_port - Start of port range (or -1 for ICMP wildcard)
|
# * :group_name<~String> - Name of group
|
||||||
# * group_name - Name of group to modify
|
# * :source_security_group_name<~String> - Name of security group to authorize
|
||||||
# * ip_protocol - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
# * :source_security_group_owner_id<~String> - Name of owner to authorize
|
||||||
# * to_port - End of port range (or -1 for ICMP wildcard)
|
# or
|
||||||
# * user_id - AWS Access Key ID
|
# * :cidr_ip - CIDR range
|
||||||
|
# * :from_port - Start of port range (or -1 for ICMP wildcard)
|
||||||
|
# * :group_name - Name of group to modify
|
||||||
|
# * :ip_protocol - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
||||||
|
# * :to_port - End of port range (or -1 for ICMP wildcard)
|
||||||
#
|
#
|
||||||
# === Returns
|
# === Returns
|
||||||
# FIXME: docs
|
# * response<~Fog::AWS::Response>:
|
||||||
def authorize_security_group_ingress(cidr_ip, from_port, group_name,
|
# * body<~Hash>:
|
||||||
ip_protocol, to_port, user_id)
|
# * :return<~Boolean> - success?
|
||||||
|
def authorize_security_group_ingress(options = {})
|
||||||
request({
|
request({
|
||||||
'Action' => 'AuthorizeSecurityGroupIngress',
|
'Action' => 'AuthorizeSecurityGroupIngress',
|
||||||
'CidrIp' => cidr_ip,
|
'CidrIp' => options[:cidr_ip],
|
||||||
'FromPort' => from_port,
|
'FromPort' => options[:from_port],
|
||||||
'GroupName' => group_name,
|
'GroupName' => options[:group_name],
|
||||||
'IpProtocol' => ip_protocol,
|
'IpProtocol' => options[:ip_protocol],
|
||||||
'ToPort' => to_port,
|
'SourceSecurityGroupName' => options[:source_security_group_name],
|
||||||
'UserId' => user_id
|
'SourceSecurityGroupOwnerId' => options[:source_security_group_owner_id],
|
||||||
|
'ToPort' => options[:to_port]
|
||||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,25 +5,31 @@ module Fog
|
||||||
# Remove permissions from a security group
|
# Remove permissions from a security group
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * cidr_ip - CIDR range
|
# * options<~Hash>:
|
||||||
# * from_port - Start of port range (or -1 for ICMP wildcard)
|
# * :group_name<~String> - Name of group
|
||||||
# * group_name - Name of group to modify
|
# * :source_security_group_name<~String> - Name of security group to authorize
|
||||||
# * ip_protocol - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
# * :source_security_group_owner_id<~String> - Name of owner to authorize
|
||||||
# * to_port - End of port range (or -1 for ICMP wildcard)
|
# or
|
||||||
# * user_id - AWS Access Key ID
|
# * :cidr_ip - CIDR range
|
||||||
|
# * :from_port - Start of port range (or -1 for ICMP wildcard)
|
||||||
|
# * :group_name - Name of group to modify
|
||||||
|
# * :ip_protocol - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
||||||
|
# * :to_port - End of port range (or -1 for ICMP wildcard)
|
||||||
#
|
#
|
||||||
# === Returns
|
# === Returns
|
||||||
# FIXME: docs
|
# * response<~Fog::AWS::Response>:
|
||||||
def revoke_security_group_ingress(cidr_ip, from_port, group_name,
|
# * body<~Hash>:
|
||||||
ip_protocol, to_port, user_id)
|
# * :return<~Boolean> - success?
|
||||||
|
def revoke_security_group_ingress(options = {})
|
||||||
request({
|
request({
|
||||||
'Action' => 'RevokeSecurityGroupIngress',
|
'Action' => 'RevokeSecurityGroupIngress',
|
||||||
'CidrIp' => cidr_ip,
|
'CidrIp' => options[:cidr_ip],
|
||||||
'FromPort' => from_port,
|
'FromPort' => options[:from_port],
|
||||||
'GroupName' => group_name,
|
'GroupName' => options[:group_name],
|
||||||
'IpProtocol' => ip_protocol,
|
'IpProtocol' => options[:ip_protocol],
|
||||||
'ToPort' => to_port,
|
'SourceSecurityGroupName' => options[:source_security_group_name],
|
||||||
'UserId' => user_id
|
'SourceSecurityGroupOwnerId' => options[:source_security_group_owner_id],
|
||||||
|
'ToPort' => options[:to_port]
|
||||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,24 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
||||||
|
|
||||||
describe 'EC2.authorize_security_group_ingress' do
|
describe 'EC2.authorize_security_group_ingress' do
|
||||||
|
|
||||||
it "should return proper attributes"
|
before(:all) do
|
||||||
|
ec2.create_security_group('fog_security_group', 'a security group for testing fog')
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
ec2.delete_security_group('fog_security_group')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return proper attributes" do
|
||||||
|
actual = ec2.authorize_security_group_ingress({
|
||||||
|
:cidr_id => '127.0.0.1',
|
||||||
|
:from_port => 80,
|
||||||
|
:group_name => 'fog_security_group',
|
||||||
|
:ip_protocol => 'tcp',
|
||||||
|
:to_port => 80,
|
||||||
|
})
|
||||||
|
actual.body[:request_id].should be_a(String)
|
||||||
|
[false, true].should include(actual.body[:return])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe 'EC2.create_snapshot' do
|
||||||
|
|
||||||
after(:all) do
|
after(:all) do
|
||||||
ec2.delete_volume(@volume_id)
|
ec2.delete_volume(@volume_id)
|
||||||
ec2.delete_snapshot(@snapshot_id)
|
eventually { ec2.delete_snapshot(@snapshot_id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return proper attributes" do
|
it "should return proper attributes" do
|
||||||
|
|
|
@ -6,8 +6,11 @@ describe 'EC2.describe_security_groups' do
|
||||||
actual = ec2.describe_security_groups
|
actual = ec2.describe_security_groups
|
||||||
actual.body[:request_id].should be_a(String)
|
actual.body[:request_id].should be_a(String)
|
||||||
actual.body[:security_group_info].should be_an(Array)
|
actual.body[:security_group_info].should be_an(Array)
|
||||||
security_group = actual.body[:security_group_info].first
|
security_group = actual.body[:security_group_info].select do |security_group|
|
||||||
|
security_group[:group_name] == 'default'
|
||||||
|
end.first
|
||||||
security_group[:group_description].should be_a(String)
|
security_group[:group_description].should be_a(String)
|
||||||
|
security_group[:group_name].should be_a(String)
|
||||||
security_group[:owner_id].should be_a(String)
|
security_group[:owner_id].should be_a(String)
|
||||||
security_group[:ip_permissions].should be_an(Array)
|
security_group[:ip_permissions].should be_an(Array)
|
||||||
ip_permission = security_group[:ip_permissions].first
|
ip_permission = security_group[:ip_permissions].first
|
||||||
|
@ -21,6 +24,26 @@ describe 'EC2.describe_security_groups' do
|
||||||
ip_permission[:to_port].should be_an(Integer)
|
ip_permission[:to_port].should be_an(Integer)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return proper attributes with params"
|
it "should return proper attributes with params" do
|
||||||
|
actual = ec2.describe_security_groups('default')
|
||||||
|
actual.body[:request_id].should be_a(String)
|
||||||
|
actual.body[:security_group_info].should be_an(Array)
|
||||||
|
security_group = actual.body[:security_group_info].select do |security_group|
|
||||||
|
security_group[:group_name] == 'default'
|
||||||
|
end.first
|
||||||
|
security_group[:group_description].should be_a(String)
|
||||||
|
security_group[:group_name].should be_a(String)
|
||||||
|
security_group[:owner_id].should be_a(String)
|
||||||
|
security_group[:ip_permissions].should be_an(Array)
|
||||||
|
ip_permission = security_group[:ip_permissions].first
|
||||||
|
ip_permission[:groups].should be_an(Array)
|
||||||
|
group = ip_permission[:groups].first
|
||||||
|
group[:user_id].should be_a(String)
|
||||||
|
group[:group_name].should be_a(String)
|
||||||
|
ip_permission[:from_port].should be_an(Integer)
|
||||||
|
ip_permission[:ip_protocol].should be_a(String)
|
||||||
|
ip_permission[:ip_ranges].should be_an(Array)
|
||||||
|
ip_permission[:to_port].should be_an(Integer)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,57 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
||||||
|
|
||||||
describe 'EC2.revoke_security_group_ingress' do
|
describe 'EC2.revoke_security_group_ingress' do
|
||||||
|
|
||||||
it "should return proper attributes"
|
before(:all) do
|
||||||
|
ec2.create_security_group('fog_security_group', 'a security group for testing fog')
|
||||||
|
ec2.authorize_security_group_ingress({
|
||||||
|
:cidr_id => '127.0.0.1',
|
||||||
|
:from_port => 80,
|
||||||
|
:group_name => 'fog_security_group',
|
||||||
|
:ip_protocol => 'tcp',
|
||||||
|
:to_port => 80,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
ec2.delete_security_group('fog_security_group')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return proper attributes" do
|
||||||
|
actual = ec2.revoke_security_group_ingress({
|
||||||
|
:cidr_id => '127.0.0.1',
|
||||||
|
:from_port => 80,
|
||||||
|
:group_name => 'fog_security_group',
|
||||||
|
:ip_protocol => 'tcp',
|
||||||
|
:to_port => 80,
|
||||||
|
})
|
||||||
|
actual.body[:request_id].should be_a(String)
|
||||||
|
[false, true].should include(actual.body[:return])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||||
|
|
||||||
|
describe 'EC2.authorize_security_group_ingress' do
|
||||||
|
|
||||||
|
before(:all) do
|
||||||
|
ec2.create_security_group('fog_security_group', 'a security group for testing fog')
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
ec2.delete_security_group('fog_security_group')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return proper attributes" do
|
||||||
|
actual = ec2.authorize_security_group_ingress({
|
||||||
|
:cidr_id => '127.0.0.1',
|
||||||
|
:from_port => 80,
|
||||||
|
:group_name => 'fog_security_group',
|
||||||
|
:ip_protocol => 'tcp',
|
||||||
|
:to_port => 80,
|
||||||
|
})
|
||||||
|
actual.body[:request_id].should be_a(String)
|
||||||
|
[false, true].should include(actual.body[:return])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ def eventually(&block)
|
||||||
sleep(delay)
|
sleep(delay)
|
||||||
yield
|
yield
|
||||||
break
|
break
|
||||||
rescue Spec::Expectations::ExpectationNotMetError => error
|
rescue error => error
|
||||||
raise error if delay == 16
|
raise error if delay == 16
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue