Class: Awshark::Ec2::SecurityRule

Inherits:
Object
  • Object
show all
Defined in:
lib/awshark/ec2/security_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SecurityRule

Returns a new instance of SecurityRule.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/awshark/ec2/security_rule.rb', line 8

def initialize(args)
  if args.is_a?(Aws::EC2::Types::IpPermission)
    @ip_protocol = args.ip_protocol
    @ip_ranges = args.ip_ranges
    @from_port = args.from_port
    @to_port = args.to_port
  else
    ip = args.fetch(:ip)
    description = args.fetch(:description)
    @ip_protocol = args.fetch(:ip_protocol, 'tcp')
    @ip_ranges = [OpenStruct.new({ cidr_ip: "#{ip}/32", description: description })]
    @from_port = args.fetch(:from_port)
    @to_port = args.fetch(:to_port)
  end
end

Instance Attribute Details

#from_portObject (readonly)

Returns the value of attribute from_port.



6
7
8
# File 'lib/awshark/ec2/security_rule.rb', line 6

def from_port
  @from_port
end

#ip_protocolObject (readonly)

Returns the value of attribute ip_protocol.



6
7
8
# File 'lib/awshark/ec2/security_rule.rb', line 6

def ip_protocol
  @ip_protocol
end

#ip_rangesObject (readonly)

Returns the value of attribute ip_ranges.



6
7
8
# File 'lib/awshark/ec2/security_rule.rb', line 6

def ip_ranges
  @ip_ranges
end

#to_portObject (readonly)

Returns the value of attribute to_port.



6
7
8
# File 'lib/awshark/ec2/security_rule.rb', line 6

def to_port
  @to_port
end

Instance Method Details

#cidr_ipObject



24
25
26
# File 'lib/awshark/ec2/security_rule.rb', line 24

def cidr_ip
  ip_ranges[0].cidr_ip
end

#descriptionObject



28
29
30
# File 'lib/awshark/ec2/security_rule.rb', line 28

def description
  ip_ranges[0].description
end

#to_hashObject



32
33
34
35
36
37
38
39
# File 'lib/awshark/ec2/security_rule.rb', line 32

def to_hash
  {
    ip_protocol: ip_protocol,
    from_port: from_port,
    to_port: to_port,
    ip_ranges: ip_ranges.map(&:to_h)
  }
end