mirror of
https://github.com/inspec/inspec
synced 2025-02-18 15:08:44 +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)
|
def initialize(path)
|
||||||
@path = 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)
|
@params = parse(@file_content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue