Class: Inspec::Resources::IpNat

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/ipnat.rb

Instance Method Summary collapse

Constructor Details

#initializeIpNat

Returns a new instance of IpNat.



14
15
16
17
18
19
20
21
# File 'lib/inspec/resources/ipnat.rb', line 14

def initialize
  # checks if the instance is either bsd or solaris
  return if (inspec.os.bsd? && !inspec.os.darwin?) || inspec.os.solaris?

  # ensures, all calls are aborted for non-supported os
  @ipnat_cache = []
  skip_resource "The `ipnat` resource is not supported on your OS yet."
end

Instance Method Details

#has_rule?(rule = nil) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/inspec/resources/ipnat.rb', line 23

def has_rule?(rule = nil)
  # checks if the rule is part of the ruleset
  retrieve_rules.any? { |line| line.casecmp(rule) == 0 }
end

#resource_idObject



44
45
46
# File 'lib/inspec/resources/ipnat.rb', line 44

def resource_id
  "Ipnat"
end

#retrieve_rulesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/inspec/resources/ipnat.rb', line 28

def retrieve_rules
  # this would be true if the OS family was not bsd/solaris when checked in initliaze
  return @ipnat_cache if defined?(@ipnat_cache)

  # construct ipnat command to show the list of current IP NAT table entry mappings
  bin = find_ipnat_or_error
  ipnat_cmd = "#{bin} -l"
  cmd = inspec.command(ipnat_cmd)

  # Return empty array when command is not executed successfully
  return [] if cmd.exit_status.to_i != 0

  # split rules, returns array or rules
  @ipnat_cache = cmd.stdout.split("\n").map(&:strip)
end

#to_sObject



48
49
50
# File 'lib/inspec/resources/ipnat.rb', line 48

def to_s
  "Ipnat"
end