Skip to content

Commit a843b84

Browse files
authored
Merge pull request #1162 from kenyon/backports-keyring
Backports: add keyring support
2 parents 3e364df + 46f53b8 commit a843b84

File tree

3 files changed

+82
-71
lines changed

3 files changed

+82
-71
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: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@
33
require 'spec_helper'
44

55
describe 'apt::backports', type: :class do
6-
let(:pre_condition) { "class{ '::apt': }" }
6+
let(:pre_condition) { 'include apt' }
77

88
describe 'debian/ubuntu tests' do
9-
context 'with defaults on deb' do
9+
context 'with defaults on debian' do
1010
let(:facts) do
1111
{
1212
os: {
1313
family: 'Debian',
1414
name: 'Debian',
1515
release: {
16-
major: '9',
17-
full: '9.0'
16+
full: '11.8',
17+
major: '11',
18+
minor: '8'
1819
},
1920
distro: {
20-
codename: 'stretch',
21+
codename: 'bullseye',
2122
id: 'Debian'
2223
}
2324
}
2425
}
2526
end
2627

2728
it {
28-
expect(subject).to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian',
29-
repos: 'main contrib non-free',
30-
release: 'stretch-backports',
31-
pin: { 'priority' => 200, 'release' => 'stretch-backports' })
29+
expect(subject).to contain_apt__source('backports').with(
30+
location: 'http://deb.debian.org/debian',
31+
repos: 'main contrib non-free',
32+
release: 'bullseye-backports',
33+
pin: {
34+
'priority' => 200,
35+
'release' => 'bullseye-backports'
36+
},
37+
keyring: '/usr/share/keyrings/debian-archive-keyring.gpg',
38+
)
3239
}
3340
end
3441

@@ -39,22 +46,28 @@
3946
family: 'Debian',
4047
name: 'Ubuntu',
4148
release: {
42-
major: '18',
43-
full: '18.04'
49+
major: '22.04',
50+
full: '22.04'
4451
},
4552
distro: {
46-
codename: 'bionic',
53+
codename: 'jammy',
4754
id: 'Ubuntu'
4855
}
4956
}
5057
}
5158
end
5259

5360
it {
54-
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
55-
repos: 'main universe multiverse restricted',
56-
release: 'bionic-backports',
57-
pin: { 'priority' => 200, 'release' => 'bionic-backports' })
61+
expect(subject).to contain_apt__source('backports').with(
62+
location: 'http://archive.ubuntu.com/ubuntu',
63+
repos: 'main universe multiverse restricted',
64+
release: 'jammy-backports',
65+
pin: {
66+
'priority' => 200,
67+
'release' => 'jammy-backports'
68+
},
69+
keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg',
70+
)
5871
}
5972
end
6073

@@ -65,11 +78,11 @@
6578
family: 'Debian',
6679
name: 'Ubuntu',
6780
release: {
68-
major: '18',
69-
full: '18.04'
81+
major: '22.04',
82+
full: '22.04'
7083
},
7184
distro: {
72-
codename: 'bionic',
85+
codename: 'jammy',
7386
id: 'Ubuntu'
7487
}
7588
}
@@ -86,11 +99,13 @@
8699
end
87100

88101
it {
89-
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu-test',
90-
key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
91-
repos: 'main',
92-
release: 'vivid',
93-
pin: { 'priority' => 90, 'release' => 'vivid' })
102+
expect(subject).to contain_apt__source('backports').with(
103+
location: 'http://archive.ubuntu.com/ubuntu-test',
104+
key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
105+
repos: 'main',
106+
release: 'vivid',
107+
pin: { 'priority' => 90, 'release' => 'vivid' },
108+
)
94109
}
95110
end
96111

@@ -101,11 +116,11 @@
101116
family: 'Debian',
102117
name: 'Ubuntu',
103118
release: {
104-
major: '18',
105-
full: '18.04'
119+
major: '22.04',
120+
full: '22.04'
106121
},
107122
distro: {
108-
codename: 'bionic',
123+
codename: 'jammy',
109124
id: 'Ubuntu'
110125
}
111126
}
@@ -123,13 +138,15 @@
123138
end
124139

125140
it {
126-
expect(subject).to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
127-
pin: { 'priority' => '90' })
141+
expect(subject).to contain_apt__source('backports').with(
142+
key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
143+
pin: { 'priority' => '90' },
144+
)
128145
}
129146
end
130147
end
131148

132-
describe 'mint tests' do
149+
describe 'linuxmint tests' do
133150
let(:facts) do
134151
{
135152
os: {
@@ -158,11 +175,13 @@
158175
end
159176

160177
it {
161-
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
162-
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
163-
repos: 'main universe multiverse restricted',
164-
release: 'trusty-backports',
165-
pin: { 'priority' => 200, 'release' => 'trusty-backports' })
178+
expect(subject).to contain_apt__source('backports').with(
179+
location: 'http://archive.ubuntu.com/ubuntu',
180+
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
181+
repos: 'main universe multiverse restricted',
182+
release: 'trusty-backports',
183+
pin: { 'priority' => 200, 'release' => 'trusty-backports' },
184+
)
166185
}
167186
end
168187

@@ -176,7 +195,7 @@
176195
end
177196

178197
it do
179-
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})
180199
end
181200
end
182201

@@ -190,7 +209,7 @@
190209
end
191210

192211
it do
193-
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})
194213
end
195214
end
196215

@@ -204,21 +223,7 @@
204223
end
205224

206225
it do
207-
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
208-
end
209-
end
210-
211-
context 'with missing key' do
212-
let(:params) do
213-
{
214-
location: 'http://archive.ubuntu.com/ubuntu',
215-
release: 'trusty-backports',
216-
repos: 'main universe multiverse restricted'
217-
}
218-
end
219-
220-
it do
221-
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})
222227
end
223228
end
224229
end
@@ -230,11 +235,11 @@
230235
family: 'Debian',
231236
name: 'Ubuntu',
232237
release: {
233-
major: '18',
234-
full: '18.04'
238+
major: '22.04',
239+
full: '22.04'
235240
},
236241
distro: {
237-
codename: 'bionic',
242+
codename: 'jammy',
238243
id: 'Ubuntu'
239244
}
240245
}

0 commit comments

Comments
 (0)