diff --git a/lib/fetchers/tar.rb b/lib/fetchers/tar.rb index 4fd599859..71c5afee6 100644 --- a/lib/fetchers/tar.rb +++ b/lib/fetchers/tar.rb @@ -13,7 +13,6 @@ module Fetchers attr_reader :files def self.resolve(target) - target = target.path if target.respond_to?(:path) return nil unless File.file?(target) return nil unless target.end_with?('.tar.gz', '.tgz') new(target) diff --git a/lib/fetchers/url.rb b/lib/fetchers/url.rb index 5d02536f1..5665e056b 100644 --- a/lib/fetchers/url.rb +++ b/lib/fetchers/url.rb @@ -20,7 +20,9 @@ module Fetchers target = transform(target) # TODO: for now, this can be much less strict now vv return nil unless target.end_with?('tar.gz', 'zip') - resolve_url(target, opts) + # fetch this url and hand it off + res = new(target, opts) + resolve_next(res.archive.path, res) rescue URI::Error => _e nil end @@ -90,13 +92,11 @@ module Fetchers archive end - def self.resolve_url(url, opts) - archive = download_archive(url, opts) - # TODO: At the moment we hand over the Tempfile object. This is necessary, - # since otherwise Ruby will delete the file on disk(!!) as soon as - # this call is finished (due to garbage-collection of Tempfile). - # Resolve this by handling over the intermediate resolver to the next. - resolve_next(archive) + attr_reader :archive + + def initialize(url, opts) + @target = url + @archive = self.class.download_archive(url, opts) end end end diff --git a/lib/fetchers/zip.rb b/lib/fetchers/zip.rb index 17ba7e396..7b4fe23a5 100644 --- a/lib/fetchers/zip.rb +++ b/lib/fetchers/zip.rb @@ -12,7 +12,6 @@ module Fetchers attr_reader :files def self.resolve(target) - target = target.path if target.respond_to?(:path) return nil unless File.file?(target) and target.end_with?('.zip') new(target) end diff --git a/lib/inspec/plugins/fetcher.rb b/lib/inspec/plugins/fetcher.rb index f0c6bf92c..9aecb989f 100644 --- a/lib/inspec/plugins/fetcher.rb +++ b/lib/inspec/plugins/fetcher.rb @@ -39,11 +39,14 @@ module Inspec # # @param [Any] the current target that needs resolving # @return [Fetcher] a fetcher if it can be resolved, nil otherwise - def self.resolve_next(target) - Inspec::Fetcher.resolve(target) + def self.resolve_next(target, parent) + res = Inspec::Fetcher.resolve(target) + res.parent = parent + res end attr_reader :target + attr_accessor :parent # Provide a list of files that are available to this fetcher. # diff --git a/test/unit/fetchers/url_test.rb b/test/unit/fetchers/url_test.rb index 8d5d61922..fc02066e6 100644 --- a/test/unit/fetchers/url_test.rb +++ b/test/unit/fetchers/url_test.rb @@ -27,6 +27,10 @@ describe Fetchers::Url do _(res).must_be_kind_of Fetchers::Tar end + it 'must be resolved to the final format' do + _(res.parent).must_be_kind_of fetcher + end + it 'must contain all files' do _(res.files).must_equal ["inspec.yml", "controls", "controls/filesystem_spec.rb"] end