2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/fetcher"
|
|
|
|
require "inspec/metadata"
|
2016-02-21 17:03:48 +00:00
|
|
|
|
|
|
|
module SourceReaders
|
|
|
|
class Flat < Inspec.source_reader(1)
|
2019-06-11 22:24:35 +00:00
|
|
|
name "flat"
|
2016-02-21 17:03:48 +00:00
|
|
|
priority 5
|
|
|
|
|
|
|
|
def self.resolve(target)
|
|
|
|
# TODO: eventually remove the metadata.rb exception here
|
|
|
|
# when we have fully phased out metadata.rb in 1.0
|
2019-06-11 22:24:35 +00:00
|
|
|
files = target.files.find_all do |x|
|
|
|
|
x.end_with?(".rb") && !x.include?("/") && x != "metadata.rb"
|
|
|
|
end
|
2016-02-21 17:03:48 +00:00
|
|
|
return nil if files.empty?
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2016-02-21 17:03:48 +00:00
|
|
|
new(target, files)
|
|
|
|
end
|
|
|
|
|
2017-04-26 01:07:39 +00:00
|
|
|
attr_reader :metadata, :tests, :libraries, :data_files
|
2016-02-21 17:03:48 +00:00
|
|
|
|
|
|
|
def initialize(target, files)
|
|
|
|
@target = target
|
|
|
|
@metadata = ::Inspec::Metadata.new(nil)
|
|
|
|
@tests = load_tests(files)
|
|
|
|
@libraries = {}
|
2017-04-26 01:07:39 +00:00
|
|
|
@data_files = {}
|
2016-02-21 17:03:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_tests(files)
|
|
|
|
Hash[files.map { |x| [x, @target.read(x)] }]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|