mirror of
https://github.com/inspec/inspec
synced 2024-11-15 01:17:08 +00:00
sync archive+tar+zip helpers to new dir-resolver
This commit is contained in:
parent
6bd757c585
commit
19a0a18db1
3 changed files with 16 additions and 30 deletions
|
@ -8,40 +8,26 @@ require 'inspec/targets/dir'
|
|||
|
||||
module Inspec::Targets
|
||||
class ArchiveHelper < DirsResolver
|
||||
def get_files(target)
|
||||
files, rootdir = structure(target)
|
||||
attr_reader :files
|
||||
|
||||
def initialize(target, _opts)
|
||||
@target = target
|
||||
files, @rootdir = structure(target)
|
||||
|
||||
# remove trailing slashes
|
||||
files = files.collect { |f| f.chomp('/') }
|
||||
|
||||
# remove leading directory
|
||||
files.collect { |f|
|
||||
Pathname(f).relative_path_from(Pathname(rootdir)).to_s
|
||||
root = Pathname(@rootdir)
|
||||
@files = files.collect { |f|
|
||||
Pathname(f).relative_path_from(root).to_s
|
||||
}
|
||||
end
|
||||
|
||||
def resolve(target, _opts = {})
|
||||
files = get_files(target)
|
||||
helper = DirsHelper.get_handler(files) ||
|
||||
fail("Don't know how to handle folder #{target}")
|
||||
|
||||
_, rootdir = structure(target)
|
||||
|
||||
res = {
|
||||
test: collect(helper, files, :get_filenames),
|
||||
library: collect(helper, files, :get_libraries),
|
||||
metadata: collect(helper, files, :get_metadata),
|
||||
}.map { |as, list|
|
||||
content(target, list, rootdir, base_folder: target, as: as)
|
||||
}
|
||||
|
||||
res.flatten
|
||||
end
|
||||
|
||||
# FIXME(sr) dedup inspec/targets/folder
|
||||
def collect(helper, files, getter)
|
||||
return [] unless helper.respond_to? getter
|
||||
helper.method(getter).call(files)
|
||||
def resolve(path, opts = {})
|
||||
o = (opts || {})
|
||||
o[:base_folder] = @target
|
||||
content(@target, [path], @rootdir, o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ require 'inspec/targets/archive'
|
|||
|
||||
module Inspec::Targets
|
||||
class TarHelper < ArchiveHelper
|
||||
def handles?(target)
|
||||
def self.handles?(target)
|
||||
File.file?(target) && target.end_with?('.tar.gz', '.tgz')
|
||||
end
|
||||
|
||||
|
@ -59,5 +59,5 @@ module Inspec::Targets
|
|||
end
|
||||
end
|
||||
|
||||
Inspec::Targets.add_module('tar', TarHelper.new)
|
||||
Inspec::Targets.add_module('tar', TarHelper)
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ require 'inspec/targets/archive'
|
|||
|
||||
module Inspec::Targets
|
||||
class ZipHelper < ArchiveHelper
|
||||
def handles?(target)
|
||||
def self.handles?(target)
|
||||
File.file?(target) and target.end_with?('.zip')
|
||||
end
|
||||
|
||||
|
@ -51,5 +51,5 @@ module Inspec::Targets
|
|||
end
|
||||
end
|
||||
|
||||
Inspec::Targets.add_module('zip', ZipHelper.new)
|
||||
Inspec::Targets.add_module('zip', ZipHelper)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue