Class: AWS::EC2::SecurityGroup::IpPermission

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/ec2/security_group/ip_permission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(security_group, protocol, ports, options = {}) ⇒ IpPermission

Returns a new instance of IpPermission.

Parameters:

  • protocol (:tcp, :udp, :icmp)
  • port (Range, Integer)

    An integer or a range of integers to open ports for.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ip_ranges (Array)

    An array of CIDR ip address to grant permission to.

  • :groups (Array)

    An array of SecurityGroup objects to grant permission to.



31
32
33
34
35
36
37
38
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 31

def initialize security_group, protocol, ports, options = {}
  @security_group = security_group
  @protocol = protocol.to_s.downcase.to_sym
  @port_range = (Array(ports).first..Array(ports).last)
  @ip_ranges = Array(options[:ip_ranges])
  @groups = Array(options[:groups])
  super
end

Instance Attribute Details

#groupsArray (readonly)

granted access with this permission.

Returns:

  • (Array)

    An array of security groups that have been



55
56
57
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 55

def groups
  @groups
end

#ip_rangesArray (readonly)

Returns An array if string CIDR ip addresses.

Returns:

  • (Array)

    An array if string CIDR ip addresses.



51
52
53
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 51

def ip_ranges
  @ip_ranges
end

#port_rangeRange (readonly)

Returns The port range (e.g. 80..80, 4000..4010, etc).

Returns:

  • (Range)

    The port range (e.g. 80..80, 4000..4010, etc)



48
49
50
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 48

def port_range
  @port_range
end

#protocolSymbol (readonly)

Returns The protocol (:tcp, :udp, :icmp).

Returns:

  • (Symbol)

    The protocol (:tcp, :udp, :icmp)



45
46
47
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 45

def protocol
  @protocol
end

#security_groupSecurityGroup (readonly)

Returns The security group this permission is authorized for.

Returns:

  • (SecurityGroup)

    The security group this permission is authorized for.



42
43
44
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 42

def security_group
  @security_group
end

Instance Method Details

#authorizeObject



57
58
59
60
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 57

def authorize
  sources = groups + ip_ranges
  security_group.authorize_ingress(protocol, port_range, *sources)
end

#revokeObject



62
63
64
65
# File 'lib/aws/ec2/security_group/ip_permission.rb', line 62

def revoke
  sources = groups + ip_ranges
  security_group.revoke_ingress(protocol, port_range, *sources)
end