Skip to content
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
43 changes: 43 additions & 0 deletions manifests/auth.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @summary Manages the Apt auth conf in /etc/apt/auth.conf.d/.
#
# @example Install the puppetlabs apt auth
# apt::auth { 'puppetlabs':
# machine => 'apt.puppetlabs.com',
# login => 'apt',
# password => 'password',
# }
#
# @param ensure
# Specifies whether the Apt auth file should exist. Valid options: 'present' and 'absent'.
#
# @param machine
# The machine entry specifies the auth URI.
#
# @param login
# The username to be used.
#
# @param password
# The password to be used.
#

define apt::auth (
String $ensure = 'present',
String $machine = $name,
String $login = undef,
String $password = undef,
) {
$content = epp('apt/auth_conf.d.epp',
machine => $machine,
login => $login,
password => $password
)

file { "${apt::auth_conf_d}/${name}.conf":
ensure => $ensure,
owner => $apt::auth_conf_owner,
group => 'root',
mode => '0600',
content => Sensitive($content),
notify => Class['apt::update'],
}
}
28 changes: 28 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
# @param sources
# Hash of `apt::source` resources.
#
# @param auths
# Creates new `apt::auth` resources. Valid options: a hash to be passed to the create_resources function linked above.
#
# @param keys
# Hash of `apt::key` resources.
#
Expand Down Expand Up @@ -145,6 +148,9 @@
# @param apt_conf_d
# The path to the file `apt.conf.d`
#
# @param auth_conf_d
# The path to the file `auth_conf.d`
#
# @param source_key_defaults
# The fault `source_key` settings
#
Expand All @@ -161,6 +167,7 @@
'preferences' => false,
'preferences.d' => false,
'apt.conf.d' => false,
'auth.conf.d' => false,
},
Hash $proxy_defaults = {
'ensure' => undef,
Expand All @@ -185,6 +192,7 @@
Hash $purge = {},
Apt::Proxy $proxy = {},
Hash $sources = {},
Hash $auths = {},
Hash $keys = {},
Hash $keyrings = {},
Hash $ppas = {},
Expand All @@ -200,6 +208,7 @@
Stdlib::Absolutepath $preferences = "${root}/preferences",
Stdlib::Absolutepath $preferences_d = "${root}/preferences.d",
Stdlib::Absolutepath $apt_conf_d = "${root}/apt.conf.d",
Stdlib::Absolutepath $auth_conf_d = "${root}/auth.conf.d",
Hash $config_files = {
'conf' => {
'path' => $conf_d,
Expand Down Expand Up @@ -264,6 +273,9 @@
if $purge['apt.conf.d'] {
assert_type(Boolean, $purge['apt.conf.d'])
}
if $purge['auth.conf.d'] {
assert_type(Boolean, $purge['auth.conf.d'])
}

$_purge = $apt::purge_defaults + $purge

Expand Down Expand Up @@ -379,6 +391,16 @@
notify => Class['apt::update'],
}

file { 'auth.conf.d':
ensure => directory,
path => $apt::auth_conf_d,
owner => root,
group => root,
purge => $_purge['auth.conf.d'],
recurse => $_purge['auth.conf.d'],
notify => Class['apt::update'],
}

$confs.each |$key, $value| {
apt::conf { $key:
* => $value,
Expand All @@ -391,6 +413,12 @@
}
}

$auths.each |$key, $value| {
apt::auth { $key:
* => $value,
}
}

$keys.each |$key, $value| {
apt::key { $key:
* => $value,
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
recurse: false,
notify: 'Class[Apt::Update]' }

auth_conf_d = { ensure: 'directory',
path: '/etc/apt/auth.conf.d',
owner: 'root',
group: 'root',
purge: false,
recurse: false,
notify: 'Class[Apt::Update]' }

describe 'apt' do
let(:facts) do
{
Expand Down Expand Up @@ -77,6 +85,10 @@
expect(subject).to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
}

it {
is_expected.to contain_file('auth.conf.d').that_notifies('Class[Apt::Update]').only_with(auth_conf_d)
}

it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }

it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
Expand Down
3 changes: 3 additions & 0 deletions templates/auth_conf.d.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine <%= $machine %>
login <%= $login %>
password <%= $password %>
Loading