Sha256: a77ccd8e52f0f86a10047b051cf78ed5736fab9280445584a3f56c4bd82a82c9

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

unless Fog.mocking?

  module Fog
    module AWS
      class EC2

        # Remove permissions from a security group
        #
        # ==== Parameters
        # * options<~Hash>:
        #   * 'GroupName'<~String> - Name of group
        #   * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
        #   * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
        #   or
        #   * 'CidrIp' - CIDR range
        #   * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
        #   * 'GroupName' - Name of group to modify
        #   * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
        #   * 'ToPort' - End of port range (or -1 for ICMP wildcard)
        #
        # === Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'return'<~Boolean> - success?
        def revoke_security_group_ingress(options = {})
          request({
            'Action' => 'RevokeSecurityGroupIngress'
          }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
        end

      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fog-0.0.31 lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb
fog-0.0.30 lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb