Skip to content
Closed
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
17 changes: 17 additions & 0 deletions examples/auth.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include 'apt'

apt::auth { 'example':
machine => 'apt.example.com',
login => 'insecure-username',
password => 'insecure-password',
}

apt::source { 'puppetlabs':
location => 'https://apt-enterprise.puppetlabs.com',
repos => 'main',
keyring => '/usr/share/keyrings/puppetlabs.gpg',
auth => {
login => 'insecure-username',
password => 'insecure-password',
},
}
28 changes: 28 additions & 0 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
# @option include [Boolean] :src
# Specifies whether to request the distribution's uncompiled source code.
#
# @param auth
# Creates an `apt::auth` resource using the `location` as machine scope.
# Valid hash keys include `login` and `password`. See `Apt::Auth_conf_entry`
# for more information.
#
# @param key
# Creates an `apt::keyring` in `/etc/apt/keyrings` (or anywhere on disk given `filename`) Valid options:
# * a hash of `parameter => value` pairs to be passed to `file`: `name` (title), `content`, `source`, `filename`
Expand Down Expand Up @@ -110,6 +115,7 @@
Optional[Variant[String[0], Array[String[0]]]] $release = undef,
Variant[String[1], Array[String[1]]] $repos = 'main',
Hash $include = {},
Optional[Variant[String[1], Hash]] $auth = undef,
Optional[Variant[String[1], Hash]] $key = undef,
Optional[Stdlib::AbsolutePath] $keyring = undef,
Optional[Variant[Hash, Integer, String[1]]] $pin = undef,
Expand Down Expand Up @@ -161,6 +167,28 @@

$includes = $apt::include_defaults + $include

if $auth {
$_auth_ensure = pick($auth['ensure'], $ensure)
$_auth_login = pick_default($auth['login'])
$_auth_password = pick_default($auth['password'])

if $_auth_ensure == 'present' and empty($_auth_login) {
fail('auth must provide a valid username')
}

if $_auth_ensure == 'present' and empty($_auth_password) {
fail('auth must provide a valid password')
}

apt::auth { "Add auth: ${_location} from Apt::Source ${title}":
ensure => $_auth_ensure,
name => $name,
machine => $_location,
login => $_auth_login,
password => $_auth_password,
}
}

if $keyring {
if $key {
fail('parameters key and keyring are mutually exclusive')
Expand Down
81 changes: 81 additions & 0 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,87 @@
end
end

describe 'auth parameter' do
context 'with auth set' do
let :params do
{
location: 'https://apt.spec.test/debian',
auth: {
login: 'spec',
password: 'test'
}
}
end

it {
expect(subject).to contain_apt__auth("Add auth: #{params[:location]} from Apt::Source #{title}")
.with(
ensure: 'present',
name: title,
machine: params[:location],
login: 'spec',
password: 'test',
)
}

it {
expect(subject).to contain_file("/etc/apt/auth.conf.d/#{title}.conf")
}
end

context 'with ensure set' do
let :params do
{
location: 'https://apt.spec.test/debian',
auth: {
ensure: 'absent',
}
}
end

it {
expect(subject).to contain_apt__auth("Add auth: #{params[:location]} from Apt::Source #{title}")
.with(
ensure: 'absent',
name: title,
machine: params[:location],
login: '',
password: '',
)
}
end

context 'with missing username' do
let :params do
{
location: 'https://apt.spec.test/debian',
auth: {
password: 'test',
}
}
end

it {
expect(subject).to compile.and_raise_error(%r{auth must provide a valid username})
}
end

context 'with missing password' do
let :params do
{
location: 'https://apt.spec.test/debian',
auth: {
login: 'spec',
}
}
end

it {
expect(subject).to compile.and_raise_error(%r{auth must provide a valid password})
}
end
end

describe 'deb822 sources' do
context 'suite contains a slash but does not end with slash (should require Components)' do
let :params do
Expand Down
Loading