Skip to content

Commit

Permalink
Add forward-compatibility with deb822
Browse files Browse the repository at this point in the history
Allow array values for certain parameters to allow easy switching between .list and .sources formats.
  • Loading branch information
jps-help committed Jul 25, 2024
1 parent d977450 commit 9d88e93
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@
# Specifies whether to check if the package release date is valid. Defaults to `True`.
#
define apt::source (
Enum['list', 'sources'] $source_format = 'list',
Enum['list', 'sources'] $source_format = 'list',
Array[Enum['deb','deb-src'], 1, 2] $types = ['deb'],
Optional[String] $location = undef,
Optional[Variant[String, Array[String]]] $location = undef,
Optional[Array[String]] $uris = undef, # deb822
Boolean $enabled = true, # deb822
String $comment = $name,
String $ensure = present,
Optional[String] $release = undef,
Optional[Variant[String, Array[String]]] $release = undef,
Optional[Array[String]] $suites = undef, # deb822
String $repos = 'main',
Variant[String, Array[String]] $repos = 'main',
Optional[Array[String]] $components = undef, # deb822
Variant[Hash] $include = {},
Optional[Variant[String, Hash]] $key = undef,
Optional[Stdlib::AbsolutePath] $keyring = undef,
Optional[Variant[Stdlib::AbsolutePath,Array[String]]] $signed_by = undef, # deb822
Optional[Variant[Hash, Numeric, String]] $pin = undef,
Optional[String] $architecture = undef,
Optional[Variant[String, Array[String]]] $architecture = undef,
Optional[Array[String]] $architectures = undef, # deb822
Optional[Boolean] $allow_unsigned = undef,
Optional[Boolean] $repo_trusted = undef, # deb822
Expand All @@ -156,23 +156,40 @@
}
} else {
$_release = $release
# If the release is given as an array, use the first element only
if (type($_release) =~ Array) {
warning("Parameter, 'release', must be a string for 'list' format. Using the first array element instead.")
$_release = $_release[0]
}
}

if (type($repos =~ Array)) {
$_repos = join($repos, ' ')
}
else {
$_repos = $repos
}

if $release =~ Pattern[/\/$/] {
$_components = $_release
} else {
$_components = "${_release} ${repos}"
$_components = "${_release} ${_repos}"
}

if $ensure == 'present' {
if ! $location {
fail('cannot create a source entry without specifying a location')
}
elsif ($apt::proxy['https_acng']) and ($location =~ /(?i:^https:\/\/)/) {
$_location = regsubst($location, 'https://','http://HTTPS///')
}
else {
$_location = $location
# If the location is given as an array, use the first element only
if (type($_location) =~ Array) {
warning("Parameter, 'location', must be a string for 'list' format. Using the first array element instead.")
$_location = $_location[0]
}
if ($apt::proxy['https_acng']) and ($_location =~ /(?i:^https:\/\/)/) {
$_location = regsubst($_location, 'https://','http://HTTPS///')
}
}
} else {
$_location = undef
Expand Down Expand Up @@ -254,6 +271,9 @@

if $architecture {
$_architecture = regsubst($architecture, '\baarch64\b', 'arm64')
if (type($_architecture) =~ Array) {
$_architecture = join($_architecture, ',')
}
} else {
$_architecture = undef
}
Expand Down

0 comments on commit 9d88e93

Please sign in to comment.