Skip to content

Commit 46f53b8

Browse files
kenyonbastelfreak
authored andcommitted
backports: add keyring support
1 parent 2239623 commit 46f53b8

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

examples/backports.pp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44
location => 'http://us.archive.ubuntu.com/ubuntu',
55
release => 'trusty-backports',
66
repos => 'main universe multiverse restricted',
7-
key => {
8-
id => '630239CC130E1A7FD81A27B140976EAF437D05B5',
9-
server => 'keyserver.ubuntu.com',
10-
},
117
}

manifests/backports.pp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
# @summary Manages backports.
22
#
3-
# @example Set up a backport source for Linux Mint qiana
4-
# class { 'apt::backports':
5-
# location => 'http://us.archive.ubuntu.com/ubuntu',
6-
# release => 'trusty-backports',
7-
# repos => 'main universe multiverse restricted',
8-
# key => {
9-
# id => '630239CC130E1A7FD81A27B140976EAF437D05B5',
10-
# server => 'keyserver.ubuntu.com',
11-
# },
12-
# }
3+
# @example Set up a backport source for Ubuntu
4+
# include apt::backports
135
#
146
# @param location
157
# Specifies an Apt repository containing the backports to manage. Valid options: a string containing a URL. Default value for Debian and
@@ -36,6 +28,11 @@
3628
# Specifies a key to authenticate the backports. Valid options: a string to be passed to the id parameter of the apt::key defined type, or a
3729
# hash of parameter => value pairs to be passed to apt::key's id, server, content, source, and/or options parameters.
3830
#
31+
# @param keyring
32+
# Absolute path to a file containing the PGP keyring used to sign this
33+
# repository. Value is passed to the apt::source and used to set signed-by on
34+
# the source entry.
35+
#
3936
# @param pin
4037
# Specifies a pin priority for the backports. Valid options: a number or string to be passed to the `id` parameter of the `apt::pin` defined
4138
# type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters.
@@ -48,6 +45,7 @@
4845
Optional[String] $release = undef,
4946
Optional[String] $repos = undef,
5047
Optional[Variant[String, Hash]] $key = undef,
48+
Stdlib::AbsolutePath $keyring = "/usr/share/keyrings/${facts['os']['name'].downcase}-archive-keyring.gpg",
5149
Variant[Integer, String, Hash] $pin = 200,
5250
Variant[Hash] $include = {},
5351
) {
@@ -56,32 +54,43 @@
5654
if $location {
5755
$_location = $location
5856
}
57+
5958
if $release {
6059
$_release = $release
6160
}
61+
6262
if $repos {
6363
$_repos = $repos
6464
}
6565

6666
if (!($facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu')) {
67-
unless $location and $release and $repos and $key {
68-
fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key')
67+
unless $location and $release and $repos {
68+
fail('If not on Debian or Ubuntu, you must explicitly pass location, release, and repos')
6969
}
7070
}
71+
7172
unless $location {
7273
$_location = $apt::backports['location']
7374
}
75+
7476
unless $release {
7577
if fact('os.distro.codename') {
7678
$_release = "${fact('os.distro.codename')}-backports"
7779
} else {
7880
fail('os.distro.codename fact not available: release parameter required')
7981
}
8082
}
83+
8184
unless $repos {
8285
$_repos = $apt::backports['repos']
8386
}
8487

88+
$_keyring = if $key {
89+
undef
90+
} else {
91+
$keyring
92+
}
93+
8594
if $pin =~ Hash {
8695
$_pin = $pin
8796
} elsif $pin =~ Numeric or $pin =~ String {
@@ -101,6 +110,7 @@
101110
repos => $_repos,
102111
include => $include,
103112
key => $key,
113+
keyring => $_keyring,
104114
pin => $_pin,
105115
}
106116
}

spec/classes/apt_backports_spec.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'priority' => 200,
3535
'release' => 'bullseye-backports'
3636
},
37+
keyring: '/usr/share/keyrings/debian-archive-keyring.gpg',
3738
)
3839
}
3940
end
@@ -65,6 +66,7 @@
6566
'priority' => 200,
6667
'release' => 'jammy-backports'
6768
},
69+
keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg',
6870
)
6971
}
7072
end
@@ -144,7 +146,7 @@
144146
end
145147
end
146148

147-
describe 'mint tests' do
149+
describe 'linuxmint tests' do
148150
let(:facts) do
149151
{
150152
os: {
@@ -193,7 +195,7 @@
193195
end
194196

195197
it do
196-
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
198+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos})
197199
end
198200
end
199201

@@ -207,7 +209,7 @@
207209
end
208210

209211
it do
210-
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
212+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos})
211213
end
212214
end
213215

@@ -221,21 +223,7 @@
221223
end
222224

223225
it do
224-
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
225-
end
226-
end
227-
228-
context 'with missing key' do
229-
let(:params) do
230-
{
231-
location: 'http://archive.ubuntu.com/ubuntu',
232-
release: 'trusty-backports',
233-
repos: 'main universe multiverse restricted'
234-
}
235-
end
236-
237-
it do
238-
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
226+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos})
239227
end
240228
end
241229
end

0 commit comments

Comments
 (0)