Skip to content

Commit a2ba353

Browse files
aba-rechsteinerwolfaba
authored andcommitted
add auth.conf.d resources
1 parent 83db6ca commit a2ba353

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

manifests/auth.pp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# @summary Manages the Apt auth conf in /etc/apt/auth.conf.d/.
2+
#
3+
# @example Install the puppetlabs apt auth
4+
# apt::auth { 'puppetlabs':
5+
# machine => 'apt.puppetlabs.com',
6+
# login => 'apt',
7+
# password => 'password',
8+
# }
9+
#
10+
# @param ensure
11+
# Specifies whether the Apt auth file should exist. Valid options: 'present' and 'absent'.
12+
#
13+
# @param machine
14+
# The machine entry specifies the auth URI.
15+
#
16+
# @param login
17+
# The username to be used.
18+
#
19+
# @param password
20+
# The password to be used.
21+
#
22+
23+
define apt::auth (
24+
String $ensure = 'present',
25+
String $machine = $name,
26+
String $login = undef,
27+
String $password = undef,
28+
) {
29+
$content = epp('apt/auth_conf.d.epp',
30+
machine => $machine,
31+
login => $login,
32+
password => $password
33+
)
34+
35+
file { "${apt::auth_conf_d}/${name}.conf":
36+
ensure => $ensure,
37+
owner => $apt::auth_conf_owner,
38+
group => 'root',
39+
mode => '0600',
40+
content => Sensitive($content),
41+
notify => Class['apt::update'],
42+
}
43+
}

manifests/init.pp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
# @param sources
8888
# Hash of `apt::source` resources.
8989
#
90+
# @param auths
91+
# Creates new `apt::auth` resources. Valid options: a hash to be passed to the create_resources function linked above.
92+
#
9093
# @param keys
9194
# Hash of `apt::key` resources.
9295
#
@@ -145,6 +148,9 @@
145148
# @param apt_conf_d
146149
# The path to the file `apt.conf.d`
147150
#
151+
# @param auth_conf_d
152+
# The path to the file `auth_conf.d`
153+
#
148154
# @param source_key_defaults
149155
# The fault `source_key` settings
150156
#
@@ -185,6 +191,7 @@
185191
Hash $purge = {},
186192
Apt::Proxy $proxy = {},
187193
Hash $sources = {},
194+
Hash $auths = {},
188195
Hash $keys = {},
189196
Hash $keyrings = {},
190197
Hash $ppas = {},
@@ -200,6 +207,7 @@
200207
Stdlib::Absolutepath $preferences = "${root}/preferences",
201208
Stdlib::Absolutepath $preferences_d = "${root}/preferences.d",
202209
Stdlib::Absolutepath $apt_conf_d = "${root}/apt.conf.d",
210+
Stdlib::Absolutepath $auth_conf_d = "${root}/auth.conf.d",
203211
Hash $config_files = {
204212
'conf' => {
205213
'path' => $conf_d,
@@ -264,6 +272,9 @@
264272
if $purge['apt.conf.d'] {
265273
assert_type(Boolean, $purge['apt.conf.d'])
266274
}
275+
if $purge['auth.conf.d'] {
276+
assert_type(Boolean, $purge['auth.conf.d'])
277+
}
267278

268279
$_purge = $apt::purge_defaults + $purge
269280

@@ -379,6 +390,16 @@
379390
notify => Class['apt::update'],
380391
}
381392

393+
file { 'auth.conf.d':
394+
ensure => directory,
395+
path => $apt::auth_conf_d,
396+
owner => root,
397+
group => root,
398+
purge => $_purge['auth.conf.d'],
399+
recurse => $_purge['auth.conf.d'],
400+
notify => Class['apt::update'],
401+
}
402+
382403
$confs.each |$key, $value| {
383404
apt::conf { $key:
384405
* => $value,
@@ -391,6 +412,12 @@
391412
}
392413
}
393414

415+
$auths.each |$key, $value| {
416+
apt::auth { $key:
417+
* => $value,
418+
}
419+
}
420+
394421
$keys.each |$key, $value| {
395422
apt::key { $key:
396423
* => $value,

spec/classes/apt_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
recurse: false,
3939
notify: 'Class[Apt::Update]' }
4040

41+
auth_conf_d = { ensure: 'directory',
42+
path: '/etc/apt/auth.conf.d',
43+
owner: 'root',
44+
group: 'root',
45+
purge: false,
46+
recurse: false,
47+
notify: 'Class[Apt::Update]' }
48+
4149
describe 'apt' do
4250
let(:facts) do
4351
{
@@ -77,6 +85,10 @@
7785
expect(subject).to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
7886
}
7987

88+
it {
89+
is_expected.to contain_file('auth.conf.d').that_notifies('Class[Apt::Update]').only_with(auth_conf_d)
90+
}
91+
8092
it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
8193

8294
it 'lays down /etc/apt/apt.conf.d/15update-stamp' do

templates/auth_conf.d.epp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
machine <%= $machine %>
2+
login <%= $login %>
3+
password <%= $password %>

0 commit comments

Comments
 (0)