Skip to content

Commit 5663e09

Browse files
authored
Merge pull request #2 from jps-help/deb822
Add support for deb822 APT sources
2 parents 22ed8ab + 44c0a7c commit 5663e09

File tree

6 files changed

+317
-2
lines changed

6 files changed

+317
-2
lines changed

REFERENCE.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* [`apt::ppa`](#apt--ppa): Manages PPA repositories using `add-apt-repository`. Not supported on Debian.
2727
* [`apt::setting`](#apt--setting): Manages Apt configuration files.
2828
* [`apt::source`](#apt--source): Manages the Apt sources in /etc/apt/sources.list.d/.
29+
* [`apt::source_deb822`](#apt--source_deb822): Manage deb822 formatted APT sources under `/etc/apt/sources.list.d`
2930

3031
### Resource types
3132

@@ -1181,6 +1182,156 @@ Specifies whether to check if the package release date is valid. Defaults to `Tr
11811182

11821183
Default value: `true`
11831184

1185+
### <a name="apt--source_deb822"></a>`apt::source_deb822`
1186+
1187+
Manage deb822 formatted APT sources under `/etc/apt/sources.list.d`
1188+
1189+
#### Examples
1190+
1191+
##### Manage the Puppetlabs repo
1192+
1193+
```puppet
1194+
apt::source_deb822 { 'Puppetlabs-puppet':
1195+
comment => 'Manage the puppetlabs repo',
1196+
enabled => true,
1197+
types => ['deb'],
1198+
uris => ['http://apt.puppet.com'],
1199+
suites => ['jammy'],
1200+
components => ['puppet8'],
1201+
signed_by => ['/etc/apt/keyrings/linuxembl-ebi.gpg'],
1202+
}
1203+
```
1204+
1205+
##### Ensure absence of a repo
1206+
1207+
```puppet
1208+
apt::source_deb822 { 'testing123':
1209+
ensure => 'absent',
1210+
}
1211+
```
1212+
1213+
#### Parameters
1214+
1215+
The following parameters are available in the `apt::source_deb822` defined type:
1216+
1217+
* [`notify_update`](#-apt--source_deb822--notify_update)
1218+
* [`ensure`](#-apt--source_deb822--ensure)
1219+
* [`enabled`](#-apt--source_deb822--enabled)
1220+
* [`comment`](#-apt--source_deb822--comment)
1221+
* [`types`](#-apt--source_deb822--types)
1222+
* [`uris`](#-apt--source_deb822--uris)
1223+
* [`suites`](#-apt--source_deb822--suites)
1224+
* [`components`](#-apt--source_deb822--components)
1225+
* [`architectures`](#-apt--source_deb822--architectures)
1226+
* [`allow_insecure`](#-apt--source_deb822--allow_insecure)
1227+
* [`repo_trusted`](#-apt--source_deb822--repo_trusted)
1228+
* [`check_valid_until`](#-apt--source_deb822--check_valid_until)
1229+
* [`signed_by`](#-apt--source_deb822--signed_by)
1230+
1231+
##### <a name="-apt--source_deb822--notify_update"></a>`notify_update`
1232+
1233+
Data type: `Boolean`
1234+
1235+
Specifies whether to trigger an `apt-get update` run.
1236+
1237+
Default value: `true`
1238+
1239+
##### <a name="-apt--source_deb822--ensure"></a>`ensure`
1240+
1241+
Data type: `Enum['present','absent']`
1242+
1243+
Specifies whether the Apt source file should exist.
1244+
1245+
Default value: `'present'`
1246+
1247+
##### <a name="-apt--source_deb822--enabled"></a>`enabled`
1248+
1249+
Data type: `Boolean`
1250+
1251+
Enable or Disable the APT source.
1252+
1253+
Default value: `true`
1254+
1255+
##### <a name="-apt--source_deb822--comment"></a>`comment`
1256+
1257+
Data type: `String`
1258+
1259+
Provide a comment to the APT source file.
1260+
1261+
Default value: `$name`
1262+
1263+
##### <a name="-apt--source_deb822--types"></a>`types`
1264+
1265+
Data type: `Array[Enum['deb','deb-src'], 1, 2]`
1266+
1267+
The package types this source manages.
1268+
1269+
Default value: `['deb']`
1270+
1271+
##### <a name="-apt--source_deb822--uris"></a>`uris`
1272+
1273+
Data type: `Optional[Array[String]]`
1274+
1275+
A list of URIs for the APT source.
1276+
1277+
Default value: `undef`
1278+
1279+
##### <a name="-apt--source_deb822--suites"></a>`suites`
1280+
1281+
Data type: `Optional[Array[String]]`
1282+
1283+
A list of suites for the APT source ('jammy-updates', 'bookworm', 'stable', etc.).
1284+
1285+
Default value: `undef`
1286+
1287+
##### <a name="-apt--source_deb822--components"></a>`components`
1288+
1289+
Data type: `Optional[Array[String]]`
1290+
1291+
A list of components for the APT source ('main', 'contrib', 'non-free', etc.).
1292+
1293+
Default value: `undef`
1294+
1295+
##### <a name="-apt--source_deb822--architectures"></a>`architectures`
1296+
1297+
Data type: `Optional[Array[String]]`
1298+
1299+
A list of supported architectures for the APT source ('amd64', 'i386', etc.).
1300+
1301+
Default value: `undef`
1302+
1303+
##### <a name="-apt--source_deb822--allow_insecure"></a>`allow_insecure`
1304+
1305+
Data type: `Optional[Boolean]`
1306+
1307+
Specifies whether to allow downloads from insecure repositories.
1308+
1309+
Default value: `undef`
1310+
1311+
##### <a name="-apt--source_deb822--repo_trusted"></a>`repo_trusted`
1312+
1313+
Data type: `Optional[Boolean]`
1314+
1315+
Consider the APT source trusted, even if authentication checks fail.
1316+
1317+
Default value: `undef`
1318+
1319+
##### <a name="-apt--source_deb822--check_valid_until"></a>`check_valid_until`
1320+
1321+
Data type: `Optional[Boolean]`
1322+
1323+
Specifies whether to check if the package release date is valid.
1324+
1325+
Default value: `undef`
1326+
1327+
##### <a name="-apt--source_deb822--signed_by"></a>`signed_by`
1328+
1329+
Data type: `Optional[Variant[Array[Stdlib::AbsolutePath],String]]`
1330+
1331+
Absolute path to a file containing the PGP keyring used to sign this repository.
1332+
1333+
Default value: `undef`
1334+
11841335
## Data types
11851336

11861337
### <a name="Apt--Auth_conf_entry"></a>`Apt::Auth_conf_entry`

manifests/params.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
'path' => $sources_list_d,
4545
'ext' => '.list',
4646
},
47+
'source' => {
48+
'path' => $sources_list_d,
49+
'ext' => '.sources',
50+
},
4751
}
4852

4953
$update_defaults = {

manifests/setting.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$setting_type = $title_array[0]
3939
$base_name = join(delete_at($title_array, 0), '-')
4040

41-
assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
41+
assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/, /\Asource\z/], $setting_type) |$a, $b| {
4242
fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
4343
}
4444

@@ -49,7 +49,7 @@
4949
}
5050
}
5151

52-
if ($setting_type == 'list') or ($setting_type == 'pref') {
52+
if ($setting_type == 'list') or ($setting_type == 'pref') or ($setting_type == 'source') {
5353
$_priority = ''
5454
} else {
5555
$_priority = $priority

manifests/source_deb822.pp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# @summary Manage deb822 formatted APT sources under `/etc/apt/sources.list.d`
2+
#
3+
# @example Manage the Puppetlabs repo
4+
# apt::source_deb822 { 'Puppetlabs-puppet':
5+
# comment => 'Manage the puppetlabs repo',
6+
# enabled => true,
7+
# types => ['deb'],
8+
# uris => ['http://apt.puppet.com'],
9+
# suites => ['jammy'],
10+
# components => ['puppet8'],
11+
# signed_by => ['/etc/apt/keyrings/linuxembl-ebi.gpg'],
12+
# }
13+
#
14+
# @example Ensure absence of a repo
15+
# apt::source_deb822 { 'testing123':
16+
# ensure => 'absent',
17+
# }
18+
#
19+
# @param notify_update
20+
# Specifies whether to trigger an `apt-get update` run.
21+
#
22+
# @param ensure
23+
# Specifies whether the Apt source file should exist.
24+
#
25+
# @param enabled
26+
# Enable or Disable the APT source.
27+
#
28+
# @param comment
29+
# Provide a comment to the APT source file.
30+
#
31+
# @param types
32+
# The package types this source manages.
33+
#
34+
# @param uris
35+
# A list of URIs for the APT source.
36+
#
37+
# @param suites
38+
# A list of suites for the APT source ('jammy-updates', 'bookworm', 'stable', etc.).
39+
#
40+
# @param components
41+
# A list of components for the APT source ('main', 'contrib', 'non-free', etc.).
42+
#
43+
# @param architectures
44+
# A list of supported architectures for the APT source ('amd64', 'i386', etc.).
45+
#
46+
# @param allow_insecure
47+
# Specifies whether to allow downloads from insecure repositories.
48+
#
49+
# @param repo_trusted
50+
# Consider the APT source trusted, even if authentication checks fail.
51+
#
52+
# @param check_valid_until
53+
# Specifies whether to check if the package release date is valid.
54+
#
55+
# @param signed_by
56+
# Absolute path to a file containing the PGP keyring used to sign this repository.
57+
#
58+
define apt::source_deb822 (
59+
Enum['present','absent'] $ensure = 'present',
60+
Boolean $notify_update = true,
61+
Boolean $enabled = true,
62+
String $comment = $name,
63+
Array[Enum['deb','deb-src'], 1, 2] $types = ['deb'],
64+
Optional[Array[String]] $uris = undef,
65+
Optional[Array[String]] $suites = undef,
66+
Optional[Array[String]] $components = undef,
67+
Optional[Array[String]] $architectures = undef,
68+
Optional[Boolean] $allow_insecure = undef,
69+
Optional[Boolean] $repo_trusted = undef,
70+
Optional[Boolean] $check_valid_until = undef,
71+
Optional[Variant[Array[Stdlib::AbsolutePath],String]] $signed_by = undef,
72+
) {
73+
case $ensure {
74+
'present': {
75+
$header = epp('apt/_header.epp')
76+
$source_content = epp('apt/source_deb822.epp', delete_undef_values({
77+
'uris' => $uris,
78+
'suites' => $suites,
79+
'components' => $components,
80+
'types' => $types,
81+
'comment' => $comment,
82+
'enabled' => $enabled ? { true => 'yes', false => 'no' },
83+
'architectures' => $architectures,
84+
'allow_insecure' => $allow_insecure ? { true => 'yes', false => 'no', default => undef },
85+
'repo_trusted' => $repo_trusted ? { true => 'yes', false => 'no', default => undef },
86+
'check_valid_until' => $check_valid_until ? { true => 'yes', false => 'no', default => undef },
87+
'signed_by' => $signed_by,
88+
}
89+
)
90+
)
91+
}
92+
'absent': {
93+
$header = undef
94+
$source_content = undef
95+
}
96+
default: {
97+
fail('Unexpected value for $ensure parameter.')
98+
}
99+
}
100+
101+
apt::setting { "source-${name}":
102+
ensure => $ensure,
103+
content => "${header}${source_content}",
104+
notify_update => $notify_update,
105+
}
106+
}

spec/defines/source_deb822_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'apt::source_deb822' do
6+
let(:title) { 'namevar' }
7+
let(:params) do
8+
{}
9+
end
10+
11+
on_supported_os.each do |os, os_facts|
12+
context "on #{os}" do
13+
let(:facts) { os_facts }
14+
15+
it { is_expected.to compile }
16+
end
17+
end
18+
end

templates/source_deb822.epp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<% | String $comment,
2+
Enum['yes','no'] $enabled,
3+
Array[String] $types,
4+
Array[String] $uris,
5+
Array[String] $suites,
6+
Array[String] $components,
7+
Optional[Array] $architectures = undef,
8+
Optional[Enum['yes','no']] $allow_insecure = undef,
9+
Optional[Enum['yes','no']] $repo_trusted = undef,
10+
Optional[Enum['yes','no']] $check_valid_until = undef,
11+
Optional[Variant[Array[String], String]] $signed_by = undef,
12+
| -%>
13+
# <%= $comment %>
14+
Enabled: <%= $enabled %>
15+
Types: <% $types.each |String $type| { -%> <%= $type %> <% } %>
16+
URIs: <% $uris.each | String $uri | { -%> <%= $uri %> <% } %>
17+
Suites: <% $suites.each | String $suite | { -%> <%= $suite %> <% } %>
18+
Components: <% $components.each | String $component | { -%> <%= $component %> <% } %>
19+
<% if $architectures { -%>
20+
Architectures:<% $architectures.each | String $arch | { %> <%= $arch %><% } %>
21+
<%- } -%>
22+
<% if $allow_insecure { -%>
23+
Allow-Insecure: <%= $allow_insecure %>
24+
<% } -%>
25+
<% if $repo_trusted { -%>
26+
Trusted: <%= $repo_trusted %>
27+
<% } -%>
28+
<% if $check_valid_until { -%>
29+
Check-Valid-Until: <%= $check_valid_until %>
30+
<% } -%>
31+
<% if $signed_by { -%>
32+
Signed-By: <% if type($signed_by) =~ Type[Array] { -%><%- $signed_by.each |String $keyring| { -%><%= $keyring %> <% } %>
33+
<%- } -%>
34+
<%- elsif type($signed_by) =~ Type[String] { %>
35+
<%= $signed_by -%>
36+
<%- }} -%>

0 commit comments

Comments
 (0)