Skip to content

Commit 4f4adf4

Browse files
authored
Merge pull request #4 from jps-help/deb822_source
deb822 backward compatibility
2 parents d977450 + 5a0c2ef commit 4f4adf4

File tree

3 files changed

+90
-139
lines changed

3 files changed

+90
-139
lines changed

REFERENCE.md

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,9 @@ apt::source { 'puppetlabs':
10401040
```puppet
10411041
apt::source { 'puppetlabs':
10421042
source_format => 'sources'
1043-
uris => ['http://apt.puppetlabs.com'],
1044-
suites => [$facts['os']['distro']['codename']],
1045-
components => ['puppet8'],
1046-
signed_by => '/etc/apt/keyrings/puppetlabs.gpg',
1043+
location => ['http://apt.puppetlabs.com'],
1044+
repos => ['puppet8'],
1045+
keyring => '/etc/apt/keyrings/puppetlabs.gpg',
10471046
}
10481047
```
10491048

@@ -1054,23 +1053,17 @@ The following parameters are available in the `apt::source` defined type:
10541053
* [`source_format`](#-apt--source--source_format)
10551054
* [`location`](#-apt--source--location)
10561055
* [`types`](#-apt--source--types)
1057-
* [`uris`](#-apt--source--uris)
10581056
* [`enabled`](#-apt--source--enabled)
10591057
* [`comment`](#-apt--source--comment)
10601058
* [`ensure`](#-apt--source--ensure)
10611059
* [`release`](#-apt--source--release)
1062-
* [`suites`](#-apt--source--suites)
10631060
* [`repos`](#-apt--source--repos)
1064-
* [`components`](#-apt--source--components)
10651061
* [`include`](#-apt--source--include)
10661062
* [`key`](#-apt--source--key)
10671063
* [`keyring`](#-apt--source--keyring)
1068-
* [`signed_by`](#-apt--source--signed_by)
10691064
* [`pin`](#-apt--source--pin)
10701065
* [`architecture`](#-apt--source--architecture)
1071-
* [`architectures`](#-apt--source--architectures)
10721066
* [`allow_unsigned`](#-apt--source--allow_unsigned)
1073-
* [`repo_trusted`](#-apt--source--repo_trusted)
10741067
* [`allow_insecure`](#-apt--source--allow_insecure)
10751068
* [`notify_update`](#-apt--source--notify_update)
10761069
* [`check_valid_until`](#-apt--source--check_valid_until)
@@ -1085,9 +1078,10 @@ Default value: `'list'`
10851078

10861079
##### <a name="-apt--source--location"></a>`location`
10871080

1088-
Data type: `Optional[String]`
1081+
Data type: `Optional[Variant[String, Array[String]]]`
10891082

10901083
Required, unless ensure is set to 'absent'. Specifies an Apt repository. Valid options: a string containing a repository URL.
1084+
DEB822: Supports an array of URL values
10911085

10921086
Default value: `undef`
10931087

@@ -1099,14 +1093,6 @@ DEB822: The package types this source manages.
10991093

11001094
Default value: `['deb']`
11011095

1102-
##### <a name="-apt--source--uris"></a>`uris`
1103-
1104-
Data type: `Optional[Array[String]]`
1105-
1106-
DEB822: A list of URIs for the APT source.
1107-
1108-
Default value: `undef`
1109-
11101096
##### <a name="-apt--source--enabled"></a>`enabled`
11111097

11121098
Data type: `Boolean`
@@ -1133,36 +1119,22 @@ Default value: `present`
11331119

11341120
##### <a name="-apt--source--release"></a>`release`
11351121

1136-
Data type: `Optional[String]`
1122+
Data type: `Optional[Variant[String, Array[String]]]`
11371123

11381124
Specifies a distribution of the Apt repository.
1139-
1140-
Default value: `undef`
1141-
1142-
##### <a name="-apt--source--suites"></a>`suites`
1143-
1144-
Data type: `Optional[Array[String]]`
1145-
1146-
DEB822: A list of suites for the APT source ('jammy-updates', 'bookworm', 'stable', etc.).
1125+
DEB822: Supports an array of values
11471126

11481127
Default value: `undef`
11491128

11501129
##### <a name="-apt--source--repos"></a>`repos`
11511130

1152-
Data type: `String`
1131+
Data type: `Variant[String, Array[String]]`
11531132

11541133
Specifies a component of the Apt repository.
1134+
DEB822: Supports an array of values
11551135

11561136
Default value: `'main'`
11571137

1158-
##### <a name="-apt--source--components"></a>`components`
1159-
1160-
Data type: `Optional[Array[String]]`
1161-
1162-
DEB822: A list of components for the APT source ('main', 'contrib', 'non-free', etc.).
1163-
1164-
Default value: `undef`
1165-
11661138
##### <a name="-apt--source--include"></a>`include`
11671139

11681140
Data type: `Variant[Hash]`
@@ -1199,14 +1171,6 @@ See https://wiki.debian.org/DebianRepository/UseThirdParty for details.
11991171

12001172
Default value: `undef`
12011173

1202-
##### <a name="-apt--source--signed_by"></a>`signed_by`
1203-
1204-
Data type: `Optional[Variant[Stdlib::AbsolutePath,Array[String]]]`
1205-
1206-
DEB822: Either an absolute path to a PGP keyring file used to sign this repository OR a list of key fingerprints to trust.
1207-
1208-
Default value: `undef`
1209-
12101174
##### <a name="-apt--source--pin"></a>`pin`
12111175

12121176
Data type: `Optional[Variant[Hash, Numeric, String]]`
@@ -1218,19 +1182,12 @@ Default value: `undef`
12181182

12191183
##### <a name="-apt--source--architecture"></a>`architecture`
12201184

1221-
Data type: `Optional[String]`
1185+
Data type: `Optional[Variant[String, Array[String]]]`
12221186

12231187
Tells Apt to only download information for specified architectures. Valid options: a string containing one or more architecture names,
12241188
separated by commas (e.g., 'i386' or 'i386,alpha,powerpc').
12251189
(if unspecified, Apt downloads information for all architectures defined in the Apt::Architectures option)
1226-
1227-
Default value: `undef`
1228-
1229-
##### <a name="-apt--source--architectures"></a>`architectures`
1230-
1231-
Data type: `Optional[Array[String]]`
1232-
1233-
DEB822: A list of supported architectures for the APT source ('amd64', 'i386', etc.).
1190+
DEB822: Supports an array of values
12341191

12351192
Default value: `undef`
12361193

@@ -1242,14 +1199,6 @@ Specifies whether to authenticate packages from this release, even if the Releas
12421199

12431200
Default value: `undef`
12441201

1245-
##### <a name="-apt--source--repo_trusted"></a>`repo_trusted`
1246-
1247-
Data type: `Optional[Boolean]`
1248-
1249-
DEB822: Consider the APT source trusted, even if authentication checks fail.
1250-
1251-
Default value: `undef`
1252-
12531202
##### <a name="-apt--source--allow_insecure"></a>`allow_insecure`
12541203

12551204
Data type: `Optional[Boolean]`

manifests/source.pp

Lines changed: 79 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,21 @@
2424
# @example Install the puppetlabs apt source (deb822 format)
2525
# apt::source { 'puppetlabs':
2626
# source_format => 'sources'
27-
# uris => ['http://apt.puppetlabs.com'],
28-
# suites => [$facts['os']['distro']['codename']],
29-
# components => ['puppet8'],
30-
# signed_by => '/etc/apt/keyrings/puppetlabs.gpg',
27+
# location => ['http://apt.puppetlabs.com'],
28+
# repos => ['puppet8'],
29+
# keyring => '/etc/apt/keyrings/puppetlabs.gpg',
3130
# }
3231
#
3332
# @param source_format
3433
# The file format to use for the apt source. See https://wiki.debian.org/SourcesList
3534
#
3635
# @param location
3736
# Required, unless ensure is set to 'absent'. Specifies an Apt repository. Valid options: a string containing a repository URL.
37+
# DEB822: Supports an array of URL values
3838
#
3939
# @param types
4040
# DEB822: The package types this source manages.
4141
#
42-
# @param uris
43-
# DEB822: A list of URIs for the APT source.
44-
#
4542
# @param enabled
4643
# DEB822: Enable or Disable the APT source.
4744
#
@@ -53,15 +50,11 @@
5350
#
5451
# @param release
5552
# Specifies a distribution of the Apt repository.
56-
#
57-
# @param suites
58-
# DEB822: A list of suites for the APT source ('jammy-updates', 'bookworm', 'stable', etc.).
53+
# DEB822: Supports an array of values
5954
#
6055
# @param repos
6156
# Specifies a component of the Apt repository.
62-
#
63-
# @param components
64-
# DEB822: A list of components for the APT source ('main', 'contrib', 'non-free', etc.).
57+
# DEB822: Supports an array of values
6558
#
6659
# @param include
6760
# Configures include options. Valid options: a hash of available keys.
@@ -85,9 +78,6 @@
8578
# This is not necessary if the key is installed with `key` param above.
8679
# See https://wiki.debian.org/DebianRepository/UseThirdParty for details.
8780
#
88-
# @param signed_by
89-
# DEB822: Either an absolute path to a PGP keyring file used to sign this repository OR a list of key fingerprints to trust.
90-
#
9181
# @param pin
9282
# Creates a declaration of the apt::pin defined type. Valid options: a number or string to be passed to the `id` parameter of the
9383
# `apt::pin` defined type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters.
@@ -96,16 +86,11 @@
9686
# Tells Apt to only download information for specified architectures. Valid options: a string containing one or more architecture names,
9787
# separated by commas (e.g., 'i386' or 'i386,alpha,powerpc').
9888
# (if unspecified, Apt downloads information for all architectures defined in the Apt::Architectures option)
99-
#
100-
# @param architectures
101-
# DEB822: A list of supported architectures for the APT source ('amd64', 'i386', etc.).
89+
# DEB822: Supports an array of values
10290
#
10391
# @param allow_unsigned
10492
# Specifies whether to authenticate packages from this release, even if the Release file is not signed or the signature can't be checked.
10593
#
106-
# @param repo_trusted
107-
# DEB822: Consider the APT source trusted, even if authentication checks fail.
108-
#
10994
# @param allow_insecure
11095
# Specifies whether to allow downloads from insecure repositories.
11196
#
@@ -116,29 +101,23 @@
116101
# Specifies whether to check if the package release date is valid. Defaults to `True`.
117102
#
118103
define apt::source (
119-
Enum['list', 'sources'] $source_format = 'list',
120-
Array[Enum['deb','deb-src'], 1, 2] $types = ['deb'],
121-
Optional[String] $location = undef,
122-
Optional[Array[String]] $uris = undef, # deb822
123-
Boolean $enabled = true, # deb822
124-
String $comment = $name,
125-
String $ensure = present,
126-
Optional[String] $release = undef,
127-
Optional[Array[String]] $suites = undef, # deb822
128-
String $repos = 'main',
129-
Optional[Array[String]] $components = undef, # deb822
130-
Variant[Hash] $include = {},
131-
Optional[Variant[String, Hash]] $key = undef,
132-
Optional[Stdlib::AbsolutePath] $keyring = undef,
133-
Optional[Variant[Stdlib::AbsolutePath,Array[String]]] $signed_by = undef, # deb822
134-
Optional[Variant[Hash, Numeric, String]] $pin = undef,
135-
Optional[String] $architecture = undef,
136-
Optional[Array[String]] $architectures = undef, # deb822
137-
Optional[Boolean] $allow_unsigned = undef,
138-
Optional[Boolean] $repo_trusted = undef, # deb822
139-
Optional[Boolean] $allow_insecure = undef,
140-
Optional[Boolean] $check_valid_until = undef,
141-
Boolean $notify_update = true,
104+
Enum['list', 'sources'] $source_format = 'list',
105+
Array[Enum['deb','deb-src'], 1, 2] $types = ['deb'],
106+
Optional[Variant[String, Array[String]]] $location = undef,
107+
Boolean $enabled = true, # deb822
108+
String $comment = $name,
109+
String $ensure = present,
110+
Optional[Variant[String, Array[String]]] $release = undef,
111+
Variant[String, Array[String]] $repos = 'main',
112+
Variant[Hash] $include = {},
113+
Optional[Variant[String, Hash]] $key = undef,
114+
Optional[Stdlib::AbsolutePath] $keyring = undef,
115+
Optional[Variant[Hash, Numeric, String]] $pin = undef,
116+
Optional[Variant[String, Array[String]]] $architecture = undef,
117+
Optional[Boolean] $allow_unsigned = undef,
118+
Optional[Boolean] $allow_insecure = undef,
119+
Optional[Boolean] $check_valid_until = undef,
120+
Boolean $notify_update = true,
142121
) {
143122
include apt
144123

@@ -293,34 +272,75 @@
293272
}
294273
}
295274
'sources': {
275+
$_file_suffix = $source_format
276+
296277
if $pin {
297-
fail('apt::source::pin parameter is not supported with deb822 format')
278+
warning("'pin' parameter is not supported with deb822 format.")
298279
}
299-
if !$uris {
300-
fail('You must specify a list of URIs for the apt::source resource')
280+
if $key {
281+
warning("'key' parameter is not supported with deb822 format.")
301282
}
302-
if !$suites {
303-
fail('You must specify a list of suites for the apt::source resource')
283+
if $ensure == 'present' {
284+
if ! $location {
285+
fail('cannot create a source entry without specifying a location')
286+
}
304287
}
305-
if !$components {
306-
fail('You must specify a list of components for the apt::source resource')
288+
if (type($location, 'generalized') !~ Type[Array]) {
289+
warning('For deb822 sources, location must be specified as an array.')
290+
$_location = [$location]
291+
}
292+
else {
293+
$_location = $location
294+
}
295+
296+
if !$release {
297+
if fact('os.distro.codename') {
298+
$_release = [fact('os.distro.codename')]
299+
} else {
300+
fail('os.distro.codename fact not available: release parameter required')
301+
}
302+
} else {
303+
if (type($release, 'generalized') !~ Type[Array]) {
304+
warning("For deb822 sources, 'release' must be specified as an array. Converting to array.")
305+
$_release = [$release]
306+
} else {
307+
$_release = $release
308+
}
309+
}
310+
311+
if (type($repos, 'generalized') !~ Type[Array]) {
312+
warning("For deb822 sources, 'repos' must be specified as an array. Converting to array.")
313+
$_repos = split($repos, /\s+/)
314+
} else {
315+
$_repos = $repos
316+
}
317+
318+
if $architecture != undef {
319+
if (type($architecture, 'generalized') !~ Type[Array]) {
320+
warning("For deb822 sources, 'architecture' must be specified as an array. Converting to array.")
321+
$_architecture = split($architecture, '[,]')
322+
}
323+
else {
324+
$_architecture = $architecture
325+
}
326+
} else {
327+
$_architecture = $architecture
307328
}
308-
$_file_suffix = $source_format
309329
case $ensure {
310330
'present': {
311331
$header = epp('apt/_header.epp')
312332
$source_content = epp('apt/source_deb822.epp', delete_undef_values({
313-
'uris' => $uris,
314-
'suites' => $suites,
315-
'components' => $components,
333+
'uris' => $_location,
334+
'suites' => $_release,
335+
'components' => $_repos,
316336
'types' => $types,
317337
'comment' => $comment,
318338
'enabled' => $enabled ? { true => 'yes', false => 'no' },
319-
'architectures' => $architectures,
339+
'architectures' => $_architecture,
320340
'allow_insecure' => $allow_insecure ? { true => 'yes', false => 'no', default => undef },
321-
'repo_trusted' => $repo_trusted ? { true => 'yes', false => 'no', default => undef },
341+
'repo_trusted' => $allow_unsigned ? { true => 'yes', false => 'no', default => undef },
322342
'check_valid_until' => $check_valid_until ? { true => 'yes', false => 'no', default => undef },
323-
'signed_by' => $signed_by,
343+
'signed_by' => $keyring,
324344
}
325345
)
326346
)

spec/defines/source_deb822_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)