mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
improvement: add checks to ensure the requested file is available
This commit is contained in:
parent
a8e50cd2cf
commit
be62b76dc2
1 changed files with 15 additions and 1 deletions
|
@ -15,7 +15,21 @@ class JsonConfig < Inspec.resource(1)
|
|||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@file_content = inspec.file(@path).content
|
||||
@file = inspec.file(@path)
|
||||
@file_content = @file.content
|
||||
|
||||
# check if file is available
|
||||
if !@file.file?
|
||||
skip_resource "Can't find file \"#{@conf_path}\""
|
||||
return @params = {}
|
||||
end
|
||||
|
||||
# check if file is readable
|
||||
if @file_content.empty? && @file.size > 0
|
||||
skip_resource "Can't read file \"#{@conf_path}\""
|
||||
return @params = {}
|
||||
end
|
||||
|
||||
@params = parse(@file_content)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue