diff --git a/lib/fetchers/local.rb b/lib/fetchers/local.rb index dd1fe88a2..31c9494a6 100644 --- a/lib/fetchers/local.rb +++ b/lib/fetchers/local.rb @@ -56,17 +56,17 @@ module Fetchers end def cache_key - archive_shasum.to_s + sha256.to_s end - def archive_shasum + def sha256 return nil if File.directory?(@target) @archive_shasum ||= Digest::SHA256.hexdigest File.read(@target) end def resolved_source h = { path: @target } - h[:shasum] = archive_shasum if archive_shasum + h[:sha256] = sha256 if sha256 h end end diff --git a/lib/fetchers/url.rb b/lib/fetchers/url.rb index 635984f35..dbe7ee115 100644 --- a/lib/fetchers/url.rb +++ b/lib/fetchers/url.rb @@ -85,21 +85,21 @@ module Fetchers @archive_path ||= download_archive(path) end - def shasum - content = if @archive_path - File.read(@archive_path) - else - remote_archive_content - end - Digest::SHA256.hexdigest content + def sha256 + c = if @archive_path + File.read(@archive_path) + else + content + end + Digest::SHA256.hexdigest c end def resolved_source - @resolved_source ||= { url: @target, shasum: shasum } + @resolved_source ||= { url: @target, sha256: sha256 } end def cache_key - shasum + sha256 end def to_s @@ -116,7 +116,7 @@ module Fetchers open(@target, http_opts) end - def remote_archive_content + def content open_target.read end diff --git a/lib/inspec/fetcher.rb b/lib/inspec/fetcher.rb index c16c526d4..f77a3ba7b 100644 --- a/lib/inspec/fetcher.rb +++ b/lib/inspec/fetcher.rb @@ -16,7 +16,7 @@ module Inspec end end - NON_FETCHER_KEYS = [:name, :version_constraint, :cwd, :backend, :cache, :shasum].freeze + NON_FETCHER_KEYS = [:name, :version_constraint, :cwd, :backend, :cache, :sha256].freeze def fetcher_specified?(target) # Only set a default for Hash-based (i.e. from # inspec.yml/inspec.lock) targets diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index c5d3a1300..e6ab9284d 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -33,7 +33,7 @@ module Inspec end cache_key = if target.is_a?(Hash) - target[:shasum] || target[:ref] || fetcher.cache_key + target[:sha256] || target[:ref] || fetcher.cache_key else fetcher.cache_key end @@ -43,13 +43,13 @@ module Inspec cache.prefered_entry_for(cache_key) else fetcher.fetch(cache.base_path_for(fetcher.cache_key)) - if target.respond_to?(:key?) && target.key?(:shasum) - if fetcher.resolved_source[:shasum] != target[:shasum] + if target.respond_to?(:key?) && target.key?(:sha256) + if fetcher.resolved_source[:sha256] != target[:sha256] fail <