mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Change :shasum key to :sha256 for future upgrade
Signed-off-by: Steven Danna <steve@chef.io>
This commit is contained in:
parent
6814d6ad2b
commit
8d63db9a2b
5 changed files with 24 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -85,21 +85,21 @@ module Fetchers
|
|||
@archive_path ||= download_archive(path)
|
||||
end
|
||||
|
||||
def shasum
|
||||
content = if @archive_path
|
||||
def sha256
|
||||
c = if @archive_path
|
||||
File.read(@archive_path)
|
||||
else
|
||||
remote_archive_content
|
||||
content
|
||||
end
|
||||
Digest::SHA256.hexdigest content
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <<EOF
|
||||
The remote source #{fetcher} no longer has the requested content:
|
||||
|
||||
Request Content Hash: #{target[:shasum]}
|
||||
Actual Content Hash: #{fetcher.resolved_source[:shasum]}
|
||||
Request Content Hash: #{target[:sha256]}
|
||||
Actual Content Hash: #{fetcher.resolved_source[:sha256]}
|
||||
|
||||
For URL, supermarket, compliance, and other sources that do not
|
||||
provide versioned artifacts, this likely means that the remote source
|
||||
|
|
|
@ -38,7 +38,7 @@ describe Fetchers::Url do
|
|||
res = fetcher.resolve(url)
|
||||
res.expects(:open).returns(mock_open)
|
||||
_(res).must_be_kind_of Fetchers::Url
|
||||
_(res.resolved_source).must_equal({url: 'http://chef.io/some.tar.gz', shasum: expected_shasum})
|
||||
_(res.resolved_source).must_equal({url: 'http://chef.io/some.tar.gz', sha256: expected_shasum})
|
||||
end
|
||||
|
||||
it 'handles a https url' do
|
||||
|
@ -46,7 +46,7 @@ describe Fetchers::Url do
|
|||
res = fetcher.resolve(url)
|
||||
res.expects(:open).returns(mock_open)
|
||||
_(res).must_be_kind_of Fetchers::Url
|
||||
_(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', shasum: expected_shasum})
|
||||
_(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum})
|
||||
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe Fetchers::Url do
|
|||
res = fetcher.resolve(github)
|
||||
res.expects(:open).returns(mock_open)
|
||||
_(res).wont_be_nil
|
||||
_(res.resolved_source).must_equal({url: 'https://github.com/chef/inspec/archive/master.tar.gz', shasum: expected_shasum})
|
||||
_(res.resolved_source).must_equal({url: 'https://github.com/chef/inspec/archive/master.tar.gz', sha256: expected_shasum})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ describe Fetchers::Url do
|
|||
res = fetcher.resolve(github)
|
||||
res.expects(:open).returns(mock_open)
|
||||
_(res).wont_be_nil
|
||||
_(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz', shasum: expected_shasum})
|
||||
_(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz', sha256: expected_shasum})
|
||||
end
|
||||
|
||||
it "resolves a github commit url" do
|
||||
|
@ -86,7 +86,7 @@ describe Fetchers::Url do
|
|||
res.expects(:open).returns(mock_open)
|
||||
_(res).wont_be_nil
|
||||
_(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz',
|
||||
shasum: expected_shasum})
|
||||
sha256: expected_shasum})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue