Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and fix DEB822-style template #1212

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,31 +435,51 @@
end

it { is_expected.to contain_apt__setting("sources-#{title}").with_notify_update(true) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(<<~SOURCE) }
# This file is managed by Puppet. DO NOT EDIT.
# my_source
Enabled: yes
Types: deb
URIs: http://debian.mirror.iweb.ca/debian/
Suites: stretch
Components: main contrib non-free
SOURCE
end

context 'complex deb822 source' do
let :params do
super().merge(
{
enabled: false,
types: ['deb', 'deb-src'],
location: ['http://fr.debian.org/debian', 'http://de.debian.org/debian'],
release: ['stable', 'stable-updates', 'stable-backports'],
repos: ['main', 'contrib', 'non-free'],
architecture: ['amd64', 'i386'],
allow_unsigned: true,
notify_update: false
allow_insecure: true,
notify_update: false,
check_valid_until: false,
keyring: '/foo'
},
)
end

it { is_expected.to contain_apt__setting("sources-#{title}").with_notify_update(false) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Enabled: yes}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Types: deb deb-src}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{URIs: http://fr.debian.org/debian http://de.debian.org/debian}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: stable stable-updates stable-backports}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Components: main contrib non-free}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Architectures: amd64 i386}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Trusted: yes}) }
it { is_expected.to contain_apt__setting("sources-#{title}").with_content(<<~SOURCE) }
# This file is managed by Puppet. DO NOT EDIT.
# my_source
Enabled: no
Types: deb deb-src
URIs: http://fr.debian.org/debian http://de.debian.org/debian
Suites: stable stable-updates stable-backports
Components: main contrib non-free
Architectures: amd64 i386
Allow-Insecure: yes
Trusted: yes
Check-Valid-Until: no
Signed-By: /foo
SOURCE
end

context '.list backwards compatibility' do
Expand Down
32 changes: 15 additions & 17 deletions templates/source_deb822.epp
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<% | String $comment,
<%- |
String[1] $comment,
Enum['yes','no'] $enabled,
Array[String] $types,
Array[String] $uris,
Array[String] $suites,
Array[String] $components,
Optional[Array] $architectures = undef,
Array[String[1]] $types,
Array[String[1]] $uris,
Array[String[1]] $suites,
Array[String[1]] $components,
Optional[Array[String[1]]] $architectures = undef,
Optional[Enum['yes','no']] $allow_insecure = undef,
Optional[Enum['yes','no']] $repo_trusted = undef,
Optional[Enum['yes','no']] $check_valid_until = undef,
Optional[Variant[Stdlib::AbsolutePath,Array[String]]] $signed_by = undef,
Optional[Variant[Stdlib::AbsolutePath,Array[String[1]]]] $signed_by = undef,
| -%>
# <%= $comment %>
Enabled: <%= $enabled %>
Types: <% $types.each |String $type| { -%> <%= $type %> <% } %>
URIs: <% $uris.each | String $uri | { -%> <%= $uri %> <% } %>
Suites: <% $suites.each | String $suite | { -%> <%= $suite %> <% } %>
Components: <% $components.each | String $component | { -%> <%= $component %> <% } %>
Types: <%= $types.join(' ') %>
URIs: <%= $uris.join(' ') %>
Suites: <%= $suites.join(' ') %>
Components: <%= $components.join(' ') %>
<% if $architectures { -%>
Architectures:<% $architectures.each | String $arch | { %> <%= $arch %><% } %>
Architectures: <%= $architectures.join(' ') %>
<%- } -%>
<% if $allow_insecure { -%>
Allow-Insecure: <%= $allow_insecure %>
Expand All @@ -29,8 +30,5 @@ Trusted: <%= $repo_trusted %>
Check-Valid-Until: <%= $check_valid_until %>
<% } -%>
<% if $signed_by { -%>
Signed-By: <% if type($signed_by) =~ Type[Array] { -%><%- $signed_by.each |String $keyring| { -%><%= $keyring %> <% } -%>
<%- } -%>
<%- elsif type($signed_by) =~ Type[String] { -%>
<%= $signed_by -%>
<%- }} %>
Signed-By: <%= [$signed_by].flatten.join(' ') %>
<% } -%>
Loading