Class: Inspec::Targets::TarHelper
- Inherits:
-
ArchiveHelper
- Object
- ArchiveHelper
- Inspec::Targets::TarHelper
- Defined in:
- lib/inspec/targets/tar.rb
Instance Method Summary collapse
- #content(input, files, rootdir = nil, opts = {}) ⇒ Object
- #handles?(target) ⇒ Boolean
- #structure(input) ⇒ Object
- #to_s ⇒ Object
Methods inherited from ArchiveHelper
Instance Method Details
#content(input, files, rootdir = nil, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inspec/targets/tar.rb', line 33 def content(input, files, rootdir = nil, opts = {}) content = [] Gem::Package::TarReader.new(Zlib::GzipReader.open(input)) do |tar| tar.each do |entry| if entry.directory? # nothing to do elsif entry.file? if files.include?(entry.full_name.gsub(rootdir, '')) h = { content: entry.read, type: opts[:as] || :test, # ref: File.join(input, entry.name), } content.push(h) end elsif entry.header.typeflag == '2' # ignore symlinks for now end end end content end |
#handles?(target) ⇒ Boolean
11 12 13 |
# File 'lib/inspec/targets/tar.rb', line 11 def handles?(target) File.file?(target) && target.end_with?('.tar.gz', '.tgz') end |
#structure(input) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inspec/targets/tar.rb', line 15 def structure(input) files = [] rootdir = '' Gem::Package::TarReader.new(Zlib::GzipReader.open(input)) do |tar| files = tar.map(&:full_name) end # find root dir of profile files.each { |f| pn = Pathname(f) rootdir = pn.dirname.to_s if pn.basename.to_s == 'inspec.yml' || pn.basename.to_s == 'metadata.rb' } # stores the rootdir of metadata.rb or inspec.yml rootdir += '/' if !rootdir.empty? [files, rootdir] end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/inspec/targets/tar.rb', line 56 def to_s 'tar.gz Loader' end |