mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
move zip and tar helpers
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
7a59d9ce76
commit
5875864f45
4 changed files with 45 additions and 29 deletions
|
@ -1,28 +0,0 @@
|
|||
# encoding: utf-8
|
||||
require 'zip'
|
||||
|
||||
module Vulcano::Targets
|
||||
class ZipHelper
|
||||
|
||||
def content input
|
||||
content = {}
|
||||
::Zip::InputStream.open(input) do |io|
|
||||
while (entry = io.get_next_entry)
|
||||
content[entry.name] = io.read
|
||||
end
|
||||
end
|
||||
return content
|
||||
end
|
||||
|
||||
def structure input
|
||||
files = Array.new
|
||||
::Zip::InputStream.open(input) do |io|
|
||||
while (entry = io.get_next_entry)
|
||||
files.push(entry.name)
|
||||
end
|
||||
end
|
||||
return files
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -25,7 +25,7 @@ module Vulcano::Targets
|
|||
zipfile.binmode
|
||||
zipfile.write(open(url).read)
|
||||
zipfile.rewind
|
||||
content = ZipHelper.resolve(zipfile.path)
|
||||
content = ZipHelper.new.resolve(zipfile.path)
|
||||
zipfile.close
|
||||
zipfile.unlink
|
||||
return content
|
||||
|
|
44
lib/vulcano/targets/zip.rb
Normal file
44
lib/vulcano/targets/zip.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# encoding: utf-8
|
||||
require 'zip'
|
||||
require 'vulcano/targets/dir'
|
||||
|
||||
module Vulcano::Targets
|
||||
class ZipHelper
|
||||
|
||||
def content input, filter
|
||||
content = []
|
||||
::Zip::InputStream.open(input) do |io|
|
||||
while (entry = io.get_next_entry)
|
||||
content.push({
|
||||
content: io.read,
|
||||
ref: File::join(input, entry.name),
|
||||
})
|
||||
end
|
||||
end
|
||||
return content
|
||||
end
|
||||
|
||||
def structure input
|
||||
files = Array.new
|
||||
::Zip::InputStream.open(input) do |io|
|
||||
while (entry = io.get_next_entry)
|
||||
files.push(entry.name)
|
||||
end
|
||||
end
|
||||
return files
|
||||
end
|
||||
|
||||
def resolve(path)
|
||||
files = structure(path)
|
||||
helper = DirsHelper.getHandler(files)
|
||||
if helper.nil?
|
||||
raise "Don't know how to handle folder #{path}"
|
||||
end
|
||||
# get all file contents
|
||||
file_handler = Vulcano::Targets.modules['file']
|
||||
test_files = helper.get_filenames(files)
|
||||
content(path, test_files)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue