Skip to content

Commit 480d42b

Browse files
Merge pull request #991 from johanfleury/feature/add-support-for-signed-by-in-source-entries
[MODULES-9695] - Add support for signed-by in source entries
2 parents 9c34cc6 + 0c35168 commit 480d42b

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

manifests/source.pp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
# defined type, or a hash of `parameter => value` pairs to be passed to `apt::key`'s `id`, `server`, `content`, `source`, and/or
4040
# `options` parameters.
4141
#
42+
# @param keyring
43+
# Absolute path to a file containing the PGP keyring used to sign this repository. Value is used to set signed-by on the source entry.
44+
# See https://wiki.debian.org/DebianRepository/UseThirdParty for details.
45+
#
4246
# @param pin
4347
# Creates a declaration of the apt::pin defined type. Valid options: a number or string to be passed to the `id` parameter of the
4448
# `apt::pin` defined type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters.
@@ -62,6 +66,7 @@
6266
String $repos = 'main',
6367
Optional[Variant[Hash]] $include = {},
6468
Optional[Variant[String, Hash]] $key = undef,
69+
Optional[Stdlib::AbsolutePath] $keyring = undef,
6570
Optional[Variant[Hash, Numeric, String]] $pin = undef,
6671
Optional[String] $architecture = undef,
6772
Boolean $allow_unsigned = false,
@@ -103,6 +108,10 @@
103108

104109
$includes = merge($::apt::include_defaults, $include)
105110

111+
if $key and $keyring {
112+
fail("parameters key and keyring are mutualy exclusive")
113+
}
114+
106115
if $key {
107116
if $key =~ Hash {
108117
unless $key['id'] {
@@ -119,8 +128,11 @@
119128
$sourcelist = epp('apt/source.list.epp', {
120129
'comment' => $comment,
121130
'includes' => $includes,
122-
'opt_architecture' => $architecture,
123-
'allow_unsigned' => $allow_unsigned,
131+
'options' => delete_undef_values({
132+
'arch' => $architecture,
133+
'trusted' => $allow_unsigned ? {true => "yes", false => undef},
134+
'signed-by' => $keyring,
135+
}),
124136
'location' => $_location,
125137
'release' => $_release,
126138
'repos' => $repos,

spec/defines/source_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,38 @@
154154
}
155155
end
156156

157+
context 'with keyring set' do
158+
let :params do
159+
{
160+
location: 'hello.there',
161+
keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
162+
}
163+
end
164+
165+
it {
166+
is_expected.to contain_apt__setting('list-my_source')
167+
.with(ensure: 'present')
168+
.with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
169+
}
170+
end
171+
172+
context 'with keyring, architecture and allow_unsigned set' do
173+
let :params do
174+
{
175+
location: 'hello.there',
176+
architecture: 'amd64',
177+
allow_unsigned: true,
178+
keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
179+
}
180+
end
181+
182+
it {
183+
is_expected.to contain_apt__setting('list-my_source')
184+
.with(ensure: 'present')
185+
.with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
186+
}
187+
end
188+
157189
context 'with a https location, install apt-transport-https' do
158190
let :params do
159191
{

templates/source.list.epp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<%- | String $comment, Hash $includes, $opt_architecture, Boolean $allow_unsigned, $location, $release, String $repos | -%>
1+
<%- | String $comment, Hash $includes, Hash $options, $location, $release, String $repos | -%>
22
# <%= $comment %>
33
<%- if $includes['deb'] { -%>
4-
deb <%- if ($opt_architecture or $allow_unsigned) {-%>
5-
[<%- if ($opt_architecture) {%>arch=<%= $opt_architecture %><% } %><%if ($opt_architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
4+
deb <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { "${key}=${value}" }.join(" ") %>] <% } -%> <%= $location %> <%= $release %> <%= $repos %>
65
<%- } -%>
76
<%- if $includes['src'] { -%>
8-
deb-src <%- if $opt_architecture or $allow_unsigned { -%>
9-
[<%- if ($opt_architecture) {%>arch=<%= $opt_architecture %><% } %><%if ($opt_architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
7+
deb-src <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { "${key}=${value}" }.join(" ") %>] <% } -%> <%= $location %> <%= $release %> <%= $repos %>
108
<%- } -%>

0 commit comments

Comments
 (0)