Skip to content

Commit 3080a0b

Browse files
Merge pull request #1087 from abacusresearch/auth
add auth.conf.d resources
2 parents 83db6ca + bcc1ec0 commit 3080a0b

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-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: 28 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
#
@@ -161,6 +167,7 @@
161167
'preferences' => false,
162168
'preferences.d' => false,
163169
'apt.conf.d' => false,
170+
'auth.conf.d' => false,
164171
},
165172
Hash $proxy_defaults = {
166173
'ensure' => undef,
@@ -185,6 +192,7 @@
185192
Hash $purge = {},
186193
Apt::Proxy $proxy = {},
187194
Hash $sources = {},
195+
Hash $auths = {},
188196
Hash $keys = {},
189197
Hash $keyrings = {},
190198
Hash $ppas = {},
@@ -200,6 +208,7 @@
200208
Stdlib::Absolutepath $preferences = "${root}/preferences",
201209
Stdlib::Absolutepath $preferences_d = "${root}/preferences.d",
202210
Stdlib::Absolutepath $apt_conf_d = "${root}/apt.conf.d",
211+
Stdlib::Absolutepath $auth_conf_d = "${root}/auth.conf.d",
203212
Hash $config_files = {
204213
'conf' => {
205214
'path' => $conf_d,
@@ -264,6 +273,9 @@
264273
if $purge['apt.conf.d'] {
265274
assert_type(Boolean, $purge['apt.conf.d'])
266275
}
276+
if $purge['auth.conf.d'] {
277+
assert_type(Boolean, $purge['auth.conf.d'])
278+
}
267279

268280
$_purge = $apt::purge_defaults + $purge
269281

@@ -379,6 +391,16 @@
379391
notify => Class['apt::update'],
380392
}
381393

394+
file { 'auth.conf.d':
395+
ensure => directory,
396+
path => $apt::auth_conf_d,
397+
owner => root,
398+
group => root,
399+
purge => $_purge['auth.conf.d'],
400+
recurse => $_purge['auth.conf.d'],
401+
notify => Class['apt::update'],
402+
}
403+
382404
$confs.each |$key, $value| {
383405
apt::conf { $key:
384406
* => $value,
@@ -391,6 +413,12 @@
391413
}
392414
}
393415

416+
$auths.each |$key, $value| {
417+
apt::auth { $key:
418+
* => $value,
419+
}
420+
}
421+
394422
$keys.each |$key, $value| {
395423
apt::key { $key:
396424
* => $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)