mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +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)
|
def initialize(path = nil)
|
||||||
@conf_path = path || '/etc/inetd.conf'
|
@conf_path = path || '/etc/inetd.conf'
|
||||||
@files_contents = {}
|
|
||||||
@content = nil
|
|
||||||
@params = nil
|
|
||||||
read_content
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -28,27 +24,31 @@ class InetdConf < Vulcano.resource(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(name)
|
def method_missing(name)
|
||||||
@params || read_content
|
read_params[name.to_s]
|
||||||
@params.nil? ? nil : @params[name.to_s]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_content
|
def read_content
|
||||||
|
return @params unless @params.nil?
|
||||||
|
|
||||||
# read the file
|
# read the file
|
||||||
file = vulcano.file(@conf_path)
|
file = vulcano.file(@conf_path)
|
||||||
if !file.file?
|
if !file.file?
|
||||||
return skip_resource "Can't find file \"#{@conf_path}\""
|
skip_resource "Can't find file \"#{@conf_path}\""
|
||||||
|
return @params = {}
|
||||||
end
|
end
|
||||||
@content = file.content
|
|
||||||
if @content.empty? && file.size > 0
|
content = file.content
|
||||||
return skip_resource "Can't read file \"#{@conf_path}\""
|
if content.empty? && file.size > 0
|
||||||
|
skip_resource "Can't read file \"#{@conf_path}\""
|
||||||
|
return @params = {}
|
||||||
end
|
end
|
||||||
# parse the file
|
# parse the file
|
||||||
@params = SimpleConfig.new(
|
conf = SimpleConfig.new(
|
||||||
@content,
|
content,
|
||||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||||
key_vals: 6,
|
key_vals: 6,
|
||||||
multiple_values: false,
|
multiple_values: false,
|
||||||
).params
|
)
|
||||||
@content
|
@params = conf.params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue