2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class AWS
|
2010-03-16 18:46:21 -04:00
|
|
|
class Real
|
2009-09-16 23:02:32 -04:00
|
|
|
|
2011-08-24 21:37:00 -04:00
|
|
|
require 'fog/aws/parsers/compute/basic'
|
2011-02-22 22:05:14 -05:00
|
|
|
|
2009-09-16 23:02:32 -04:00
|
|
|
# Remove permissions from a security group
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
2012-03-09 03:09:28 -05:00
|
|
|
# * group_name<~String> - Name of group, optional (can also be specifed as GroupName in options)
|
2009-09-16 23:02:32 -04:00
|
|
|
# * options<~Hash>:
|
2012-03-09 03:09:28 -05:00
|
|
|
# * 'GroupName'<~String> - Name of security group to modify
|
|
|
|
# * 'GroupId'<~String> - Id of security group to modify
|
2009-09-16 23:02:32 -04:00
|
|
|
# * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
|
|
|
|
# * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
|
|
|
|
# or
|
2011-10-26 10:08:48 -04:00
|
|
|
# * 'CidrIp'<~String> - CIDR range
|
|
|
|
# * 'FromPort'<~Integer> - Start of port range (or -1 for ICMP wildcard)
|
|
|
|
# * 'IpProtocol'<~String> - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
|
|
|
# * 'ToPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
|
|
|
|
# or
|
|
|
|
# * 'IpPermissions'<~Array>:
|
|
|
|
# * permission<~Hash>:
|
|
|
|
# * 'FromPort'<~Integer> - Start of port range (or -1 for ICMP wildcard)
|
|
|
|
# * 'Groups'<~Array>:
|
|
|
|
# * group<~Hash>:
|
|
|
|
# * 'GroupName'<~String> - Name of security group to authorize
|
|
|
|
# * 'UserId'<~String> - Name of owner to authorize
|
|
|
|
# * 'IpProtocol'<~String> - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
|
|
|
# * 'IpRanges'<~Array>:
|
|
|
|
# * ip_range<~Hash>:
|
|
|
|
# * 'CidrIp'<~String> - CIDR range
|
|
|
|
# * 'ToPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
|
2009-09-16 23:02:32 -04:00
|
|
|
#
|
|
|
|
# === Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-09-16 23:02:32 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'requestId'<~String> - Id of request
|
|
|
|
# * 'return'<~Boolean> - success?
|
2011-05-19 12:31:56 -04:00
|
|
|
#
|
|
|
|
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-RevokeSecurityGroupIngress.html]
|
2011-03-03 18:44:49 -05:00
|
|
|
def revoke_security_group_ingress(group_name, options = {})
|
2012-03-09 03:09:28 -05:00
|
|
|
options = Fog::AWS.parse_security_group_options(group_name, options)
|
2011-10-26 10:08:48 -04:00
|
|
|
|
|
|
|
if ip_permissions = options.delete('IpPermissions')
|
|
|
|
options.merge!(indexed_ip_permissions_params(ip_permissions))
|
2011-03-03 18:44:49 -05:00
|
|
|
end
|
2011-10-26 10:08:48 -04:00
|
|
|
|
2009-09-16 23:02:32 -04:00
|
|
|
request({
|
2010-05-24 17:22:35 -04:00
|
|
|
'Action' => 'RevokeSecurityGroupIngress',
|
|
|
|
:idempotent => true,
|
2011-06-16 19:28:54 -04:00
|
|
|
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
2010-03-16 01:15:33 -04:00
|
|
|
}.merge!(options))
|
2009-09-16 23:02:32 -04:00
|
|
|
end
|
|
|
|
|
2009-07-14 18:02:56 -04:00
|
|
|
end
|
2009-09-16 23:02:32 -04:00
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2009-07-14 18:02:56 -04:00
|
|
|
|
2011-03-03 18:44:49 -05:00
|
|
|
def revoke_security_group_ingress(group_name, options = {})
|
2012-03-09 03:09:28 -05:00
|
|
|
options = Fog::AWS.parse_security_group_options(group_name, options)
|
|
|
|
if options.key?('GroupName')
|
|
|
|
group_name = options['GroupName']
|
|
|
|
else
|
|
|
|
group_name = self.data[:security_groups].reject { |k,v| v['groupId'] != options['GroupId'] } .keys.first
|
2011-03-03 18:44:49 -05:00
|
|
|
end
|
2011-10-26 10:08:48 -04:00
|
|
|
|
2010-05-24 20:41:01 -04:00
|
|
|
response = Excon::Response.new
|
2011-05-19 18:35:33 -04:00
|
|
|
group = self.data[:security_groups][group_name]
|
2011-10-26 10:08:48 -04:00
|
|
|
|
2010-05-24 20:41:01 -04:00
|
|
|
if group
|
2012-03-15 09:30:40 -04:00
|
|
|
verify_permission_options(options, group['vpcId'] != nil)
|
|
|
|
|
2011-10-26 10:08:48 -04:00
|
|
|
normalized_permissions = normalize_permissions(options)
|
|
|
|
|
|
|
|
normalized_permissions.each do |permission|
|
|
|
|
if matching_permission = find_matching_permission(group, permission)
|
|
|
|
matching_permission['ipRanges'] -= permission['ipRanges']
|
|
|
|
matching_permission['groups'] -= permission['groups']
|
|
|
|
|
|
|
|
if matching_permission['ipRanges'].empty? && matching_permission['groups'].empty?
|
|
|
|
group['ipPermissions'].delete(matching_permission)
|
2011-08-23 15:09:55 -04:00
|
|
|
end
|
|
|
|
end
|
2010-05-24 20:41:01 -04:00
|
|
|
end
|
2011-10-26 10:08:48 -04:00
|
|
|
|
2010-02-02 01:53:18 -05:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id,
|
|
|
|
'return' => true
|
|
|
|
}
|
2010-05-26 01:26:20 -04:00
|
|
|
response
|
2010-05-24 20:41:01 -04:00
|
|
|
else
|
2011-06-16 19:28:54 -04:00
|
|
|
raise Fog::Compute::AWS::NotFound.new("The security group '#{group_name}' does not exist")
|
2010-02-02 01:53:18 -05:00
|
|
|
end
|
2009-09-16 23:02:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-14 18:02:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|