Skip to content

Commit

Permalink
Fix voxpupuliGH-204 resolve camptocamp archive regression
Browse files Browse the repository at this point in the history
The camptocamp archive digest_type default of :none overwrote puppet
archive checksum_type value, so even when we have a valid checksum such
as md5, the digest_type overwrote to :none. This results in files with
invalid checksums not being replaced. This PR addresses this bug.
  • Loading branch information
nanliu authored and randradas committed Oct 30, 2016
1 parent 0854a08 commit 96b9c7f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
20 changes: 9 additions & 11 deletions lib/puppet/provider/archive/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ def download(filepath)
end

def remote_checksum
@remote_checksum ||= begin
params = curl_params(
[
resource[:checksum_url],
'-fsSL',
'--max-redirs',
5
]
)
params = curl_params(
[
resource[:checksum_url],
'-fsSL',
'--max-redirs',
5
]
)

curl(params)[%r{\b[\da-f]{32,128}\b}i]
end
curl(params)[%r{\b[\da-f]{32,128}\b}i]
end
end
22 changes: 10 additions & 12 deletions lib/puppet/provider/archive/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@ def creates=(_value)
end

def checksum
resource[:checksum] || (remote_checksum if resource[:checksum_url])
resource[:checksum] || (resource[:checksum] = remote_checksum if resource[:checksum_url])
end

def remote_checksum
@remote_checksum ||= begin
PuppetX::Bodeco::Util.content(
resource[:checksum_url],
username: resource[:username],
password: resource[:password],
cookie: resource[:cookie],
proxy_server: resource[:proxy_server],
proxy_type: resource[:proxy_type],
insecure: resource[:allow_insecure]
)[%r{\b[\da-f]{32,128}\b}i]
end
PuppetX::Bodeco::Util.content(
resource[:checksum_url],
username: resource[:username],
password: resource[:password],
cookie: resource[:cookie],
proxy_server: resource[:proxy_server],
proxy_type: resource[:proxy_type],
insecure: resource[:allow_insecure]
)[%r{\b[\da-f]{32,128}\b}i]
end

# Private: See if local archive checksum matches.
Expand Down
20 changes: 9 additions & 11 deletions lib/puppet/provider/archive/wget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ def download(filepath)
end

def remote_checksum
@remote_checksum ||= begin
params = wget_params(
[
'-qO-',
Shellwords.shellescape(resource[:checksum_url]),
'--max-redirect=5'
]
)
params = wget_params(
[
'-qO-',
Shellwords.shellescape(resource[:checksum_url]),
'--max-redirect=5'
]
)

command = "wget #{params.join(' ')}"
Puppet::Util::Execution.execute(command)[%r{\b[\da-f]{32,128}\b}i]
end
command = "wget #{params.join(' ')}"
Puppet::Util::Execution.execute(command)[%r{\b[\da-f]{32,128}\b}i]
end
end
1 change: 0 additions & 1 deletion lib/puppet/type/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def should_to_s(value)
desc 'archive file checksum type (none|md5|sha1|sha2|sh256|sha384|sha512)
(this parameter is camptocamp/archive compatibility).'
newvalues(:none, :md5, :sha1, :sha2, :sha256, :sha384, :sha512)
defaultto(:none)
munge do |val|
resource[:checksum_type] = val
end
Expand Down
1 change: 1 addition & 0 deletions spec/unit/puppet/type/archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
expect(resource[:extract]).to eq :false
expect(resource[:cleanup]).to eq :true
expect(resource[:checksum_type]).to eq :none
expect(resource[:digest_type]).to eq nil
expect(resource[:checksum_verify]).to eq :true
expect(resource[:extract_flags]).to eq :undef
expect(resource[:allow_insecure]).to eq false
Expand Down

0 comments on commit 96b9c7f

Please sign in to comment.