mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
lazy eval inetd conf
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
075313b10e
commit
6a6c1fd7c8
1 changed files with 14 additions and 14 deletions
|
@ -17,10 +17,6 @@ class InetdConf < Vulcano.resource(1)
|
|||
|
||||
def initialize(path = nil)
|
||||
@conf_path = path || '/etc/inetd.conf'
|
||||
@files_contents = {}
|
||||
@content = nil
|
||||
@params = nil
|
||||
read_content
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -28,27 +24,31 @@ class InetdConf < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def method_missing(name)
|
||||
@params || read_content
|
||||
@params.nil? ? nil : @params[name.to_s]
|
||||
read_params[name.to_s]
|
||||
end
|
||||
|
||||
def read_content
|
||||
return @params unless @params.nil?
|
||||
|
||||
# read the file
|
||||
file = vulcano.file(@conf_path)
|
||||
if !file.file?
|
||||
return skip_resource "Can't find file \"#{@conf_path}\""
|
||||
skip_resource "Can't find file \"#{@conf_path}\""
|
||||
return @params = {}
|
||||
end
|
||||
@content = file.content
|
||||
if @content.empty? && file.size > 0
|
||||
return skip_resource "Can't read file \"#{@conf_path}\""
|
||||
|
||||
content = file.content
|
||||
if content.empty? && file.size > 0
|
||||
skip_resource "Can't read file \"#{@conf_path}\""
|
||||
return @params = {}
|
||||
end
|
||||
# parse the file
|
||||
@params = SimpleConfig.new(
|
||||
@content,
|
||||
conf = SimpleConfig.new(
|
||||
content,
|
||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||
key_vals: 6,
|
||||
multiple_values: false,
|
||||
).params
|
||||
@content
|
||||
)
|
||||
@params = conf.params
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue