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

add auth.conf.d resources #1087

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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'],
}
}
30 changes: 30 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 Down Expand Up @@ -185,6 +191,7 @@
Hash $purge = {},
Apt::Proxy $proxy = {},
Hash $sources = {},
Hash $auths = {},
Hash $keys = {},
Hash $keyrings = {},
Hash $ppas = {},
Expand All @@ -200,6 +207,7 @@
String $preferences = "${root}/preferences",
String $preferences_d = "${root}/preferences.d",
String $apt_conf_d = "${root}/apt.conf.d",
String $auth_conf_d = "${root}/auth.conf.d",
Hash $config_files = {
'conf' => {
'path' => $conf_d,
Expand Down Expand Up @@ -375,6 +383,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 @@ -387,6 +405,18 @@
}
}

$sources.each |$key, $value| {
apt::source { $key:
* => $value,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look like a duplicate of the above block.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I removed the block


$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 %>