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
6 changes: 3 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ Default value: `undef`

##### <a name="-apt--auth--password"></a>`password`

Data type: `String`
Data type: `Variant[String, Sensitive[String]]`



Expand Down Expand Up @@ -1363,7 +1363,7 @@ Alias of
Struct[{
machine => String[1],
login => String,
password => String
password => Variant[String, Sensitive[String]]
}]
```

Expand All @@ -1385,7 +1385,7 @@ Specifies the username to connect with.

##### <a name="-Apt--Auth_conf_entry--password"></a>`password`

Specifies the password to connect with.
Specifies the password to connect with. May be `Sensitive`.

### <a name="Apt--Proxy"></a>`Apt::Proxy`

Expand Down
14 changes: 8 additions & 6 deletions manifests/auth.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
# The username to be used.
#
# @param password
# The password to be used.
# The password to be used. May be `Sensitive`.
#

define apt::auth (
String $ensure = 'present',
String $machine = $name,
String $login = undef,
String $password = undef,
String $ensure = 'present',
String $machine = $name,
String $login = undef,
Variant[String, Sensitive[String]] $password = undef,
) {
$_password = if $password =~ Sensitive { $password.unwrap } else { $password }

$content = epp('apt/auth_conf.d.epp',
machine => $machine,
login => $login,
password => $password
password => $_password
)

file { "${apt::auth_conf_d}/${name}.conf":
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
{
machine: 'apt.example.com',
login: 'aptlogin',
password: 'supersecret'
password: sensitive('supersecret')
},
]
}
Expand Down
42 changes: 42 additions & 0 deletions spec/defines/auth_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'apt::auth' do
let(:pre_condition) { 'class { "apt": }' }
let(:facts) do
{
os: {
family: 'Debian',
name: 'Debian',
release: {
major: '12',
full: '12.0'
},
distro: {
codename: 'bookworm',
id: 'Debian'
}
}
}
end
let(:title) { 'example' }

auth_content = <<~CONTENT
machine apt.example.com
login aptlogin
password secret
CONTENT

context 'with password as a string' do
let(:params) { { machine: 'apt.example.com', login: 'aptlogin', password: 'secret' } }

it { is_expected.to contain_file('/etc/apt/auth.conf.d/example.conf').with(mode: '0600', content: sensitive(auth_content)) }
end

context 'with password as sensitive' do
let(:params) { { machine: 'apt.example.com', login: 'aptlogin', password: sensitive('secret') } }

it { is_expected.to contain_file('/etc/apt/auth.conf.d/example.conf').with(mode: '0600', content: sensitive(auth_content)) }
end
end
2 changes: 1 addition & 1 deletion templates/auth_conf.epp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is managed by Puppet. DO NOT EDIT.
<% if $auth_conf_entries != [] { -%>
<% $auth_conf_entries.each | $auth_conf_entry | { -%>
machine <%= $auth_conf_entry['machine'] %> login <%= $auth_conf_entry['login'] %> password <%= $auth_conf_entry['password'] %>
machine <%= $auth_conf_entry['machine'] %> login <%= $auth_conf_entry['login'] %> password <%= if $auth_conf_entry['password'] =~ Sensitive { $auth_conf_entry['password'].unwrap } else { $auth_conf_entry['password'] } %>
<% } -%>
<% } -%>
4 changes: 2 additions & 2 deletions types/auth_conf_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# Specifies the username to connect with.
#
# @param password
# Specifies the password to connect with.
# Specifies the password to connect with. May be `Sensitive`.
#
type Apt::Auth_conf_entry = Struct[
{
machine => String[1],
login => String,
password => String
password => Variant[String, Sensitive[String]]
}
]
Loading