mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +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
|
end
|
||||||
|
|
||||||
def cache_key
|
def cache_key
|
||||||
archive_shasum.to_s
|
sha256.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive_shasum
|
def sha256
|
||||||
return nil if File.directory?(@target)
|
return nil if File.directory?(@target)
|
||||||
@archive_shasum ||= Digest::SHA256.hexdigest File.read(@target)
|
@archive_shasum ||= Digest::SHA256.hexdigest File.read(@target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_source
|
def resolved_source
|
||||||
h = { path: @target }
|
h = { path: @target }
|
||||||
h[:shasum] = archive_shasum if archive_shasum
|
h[:sha256] = sha256 if sha256
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,21 +85,21 @@ module Fetchers
|
||||||
@archive_path ||= download_archive(path)
|
@archive_path ||= download_archive(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def shasum
|
def sha256
|
||||||
content = if @archive_path
|
c = if @archive_path
|
||||||
File.read(@archive_path)
|
File.read(@archive_path)
|
||||||
else
|
else
|
||||||
remote_archive_content
|
content
|
||||||
end
|
end
|
||||||
Digest::SHA256.hexdigest content
|
Digest::SHA256.hexdigest c
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_source
|
def resolved_source
|
||||||
@resolved_source ||= { url: @target, shasum: shasum }
|
@resolved_source ||= { url: @target, sha256: sha256 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_key
|
def cache_key
|
||||||
shasum
|
sha256
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -116,7 +116,7 @@ module Fetchers
|
||||||
open(@target, http_opts)
|
open(@target, http_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_archive_content
|
def content
|
||||||
open_target.read
|
open_target.read
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Inspec
|
||||||
end
|
end
|
||||||
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)
|
def fetcher_specified?(target)
|
||||||
# Only set a default for Hash-based (i.e. from
|
# Only set a default for Hash-based (i.e. from
|
||||||
# inspec.yml/inspec.lock) targets
|
# inspec.yml/inspec.lock) targets
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Inspec
|
||||||
end
|
end
|
||||||
|
|
||||||
cache_key = if target.is_a?(Hash)
|
cache_key = if target.is_a?(Hash)
|
||||||
target[:shasum] || target[:ref] || fetcher.cache_key
|
target[:sha256] || target[:ref] || fetcher.cache_key
|
||||||
else
|
else
|
||||||
fetcher.cache_key
|
fetcher.cache_key
|
||||||
end
|
end
|
||||||
|
@ -43,13 +43,13 @@ module Inspec
|
||||||
cache.prefered_entry_for(cache_key)
|
cache.prefered_entry_for(cache_key)
|
||||||
else
|
else
|
||||||
fetcher.fetch(cache.base_path_for(fetcher.cache_key))
|
fetcher.fetch(cache.base_path_for(fetcher.cache_key))
|
||||||
if target.respond_to?(:key?) && target.key?(:shasum)
|
if target.respond_to?(:key?) && target.key?(:sha256)
|
||||||
if fetcher.resolved_source[:shasum] != target[:shasum]
|
if fetcher.resolved_source[:sha256] != target[:sha256]
|
||||||
fail <<EOF
|
fail <<EOF
|
||||||
The remote source #{fetcher} no longer has the requested content:
|
The remote source #{fetcher} no longer has the requested content:
|
||||||
|
|
||||||
Request Content Hash: #{target[:shasum]}
|
Request Content Hash: #{target[:sha256]}
|
||||||
Actual Content Hash: #{fetcher.resolved_source[:shasum]}
|
Actual Content Hash: #{fetcher.resolved_source[:sha256]}
|
||||||
|
|
||||||
For URL, supermarket, compliance, and other sources that do not
|
For URL, supermarket, compliance, and other sources that do not
|
||||||
provide versioned artifacts, this likely means that the remote source
|
provide versioned artifacts, this likely means that the remote source
|
||||||
|
|
|
@ -38,7 +38,7 @@ describe Fetchers::Url do
|
||||||
res = fetcher.resolve(url)
|
res = fetcher.resolve(url)
|
||||||
res.expects(:open).returns(mock_open)
|
res.expects(:open).returns(mock_open)
|
||||||
_(res).must_be_kind_of Fetchers::Url
|
_(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
|
end
|
||||||
|
|
||||||
it 'handles a https url' do
|
it 'handles a https url' do
|
||||||
|
@ -46,7 +46,7 @@ describe Fetchers::Url do
|
||||||
res = fetcher.resolve(url)
|
res = fetcher.resolve(url)
|
||||||
res.expects(:open).returns(mock_open)
|
res.expects(:open).returns(mock_open)
|
||||||
_(res).must_be_kind_of Fetchers::Url
|
_(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
|
end
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ describe Fetchers::Url do
|
||||||
res = fetcher.resolve(github)
|
res = fetcher.resolve(github)
|
||||||
res.expects(:open).returns(mock_open)
|
res.expects(:open).returns(mock_open)
|
||||||
_(res).wont_be_nil
|
_(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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ describe Fetchers::Url do
|
||||||
res = fetcher.resolve(github)
|
res = fetcher.resolve(github)
|
||||||
res.expects(:open).returns(mock_open)
|
res.expects(:open).returns(mock_open)
|
||||||
_(res).wont_be_nil
|
_(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
|
end
|
||||||
|
|
||||||
it "resolves a github commit url" do
|
it "resolves a github commit url" do
|
||||||
|
@ -86,7 +86,7 @@ describe Fetchers::Url do
|
||||||
res.expects(:open).returns(mock_open)
|
res.expects(:open).returns(mock_open)
|
||||||
_(res).wont_be_nil
|
_(res).wont_be_nil
|
||||||
_(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz',
|
_(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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue