Skip to content

Commit 53e717f

Browse files
committed
issues/1196
puppetlabs#1196 * Adds checksum and checksum_value parameter to apt::keyring, this should address issue/1196 as commented here puppetlabs#1196 (comment) * Includes tests, all green.
1 parent 9b6aa36 commit 53e717f

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

manifests/keyring.pp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
# source => 'https://apt.puppetlabs.com/keyring.gpg'
1414
# }
1515
# }
16+
# @example Deploy the apt source and associated keyring file with checksum
17+
# apt::source { 'puppet8-release':
18+
# location => 'http://apt.puppetlabs.com',
19+
# repos => 'puppet8',
20+
# key => {
21+
# name => 'puppetlabs-keyring.gpg',
22+
# source => 'https://apt.puppetlabs.com/keyring.gpg'
23+
# checksum => 'sha256',
24+
# checksum_value => '9d7a61ab06b18454e9373edec4fc7c87f9a91bacfc891893ba0da37a33069771',
25+
# }
26+
# }
1627
#
1728
# @param dir
1829
# Path to the directory where the keyring will be stored.
@@ -32,13 +43,28 @@
3243
# @param ensure
3344
# Ensure presence or absence of the resource.
3445
#
46+
# @param checksum
47+
# Checksum type of the keyfile.
48+
# Only md5, sha256, sha224, sha384 and sha512 are supported when specifying
49+
# this parameter. (due to checksum_value parameter).
50+
# Optional, but is useful if the keyfile is from a remote HTTP source that
51+
# does not provide the necessary headers for the file resource to determine if
52+
# content has changed.
53+
#
54+
# @param checksum_value
55+
# The value of the checksum, must be a String.
56+
# Only md5, sha256, sha224, sha384 and sha512 are supported when specifying
57+
# this parameter.
58+
#
3559
define apt::keyring (
36-
Stdlib::Absolutepath $dir = '/etc/apt/keyrings',
37-
String[1] $filename = $name,
38-
Stdlib::Filemode $mode = '0644',
39-
Optional[Stdlib::Filesource] $source = undef,
40-
Optional[String[1]] $content = undef,
41-
Enum['present','absent'] $ensure = 'present',
60+
Stdlib::Absolutepath $dir = '/etc/apt/keyrings',
61+
String[1] $filename = $name,
62+
Stdlib::Filemode $mode = '0644',
63+
Optional[Stdlib::Filesource] $source = undef,
64+
Optional[String[1]] $content = undef,
65+
Enum['present','absent'] $ensure = 'present',
66+
Optional[Enum['md5','sha256','sha224','sha384','sha512']] $checksum = undef,
67+
Optional[String] $checksum_value = undef,
4268
) {
4369
ensure_resource('file', $dir, { ensure => 'directory', mode => '0755', })
4470
if $source and $content {
@@ -52,12 +78,14 @@
5278
case $ensure {
5379
'present': {
5480
file { $file:
55-
ensure => 'file',
56-
mode => $mode,
57-
owner => 'root',
58-
group => 'root',
59-
source => $source,
60-
content => $content,
81+
ensure => 'file',
82+
mode => $mode,
83+
owner => 'root',
84+
group => 'root',
85+
source => $source,
86+
content => $content,
87+
checksum => $checksum,
88+
checksum_value => $checksum_value,
6189
}
6290
}
6391
'absent': {

spec/defines/keyring_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
let(:facts) { os_facts }
1616

1717
it { is_expected.to compile }
18+
19+
context 'with checksum verification enabled' do
20+
let (:params) do
21+
{
22+
source: 'https://apt.puppetlabs.com/pubkey.gpg',
23+
checksum: 'sha256',
24+
checksum_value: '9d7a61ab06b18454e9373edec4fc7c87f9a91bacfc891893ba0da37a33069771',
25+
}
26+
end
27+
28+
it { is_expected.to compile }
29+
end
1830
end
1931
end
2032
end

0 commit comments

Comments
 (0)