Class: Inspec::Resources::InetdConf

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

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ InetdConf

Returns a new instance of InetdConf.



20
21
22
# File 'lib/resources/inetd_conf.rb', line 20

def initialize(path = nil)
  @conf_path = path || '/etc/inetd.conf'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



30
31
32
# File 'lib/resources/inetd_conf.rb', line 30

def method_missing(name)
  read_params[name.to_s]
end

Instance Method Details

#execObject

overwrite exec to ensure it works with its TODO: this needs to be fixed in RSpec



26
27
28
# File 'lib/resources/inetd_conf.rb', line 26

def exec
  read_params['exec']
end

#read_paramsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/resources/inetd_conf.rb', line 34

def read_params
  return @params if defined?(@params)

  # read the file
  file = inspec.file(@conf_path)
  if !file.file?
    skip_resource "Can't find file \"#{@conf_path}\""
    return @params = {}
  end

  content = file.content
  if content.empty? && !file.empty?
    skip_resource "Can't read file \"#{@conf_path}\""
    return @params = {}
  end
  # parse the file
  conf = SimpleConfig.new(
    content,
    assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
    key_values: 6,
    multiple_values: false,
  )
  @params = conf.params
end

#to_sObject



59
60
61
# File 'lib/resources/inetd_conf.rb', line 59

def to_s
  'inetd.conf'
end