Skip to content

Commit 0da25d6

Browse files
authored
Merge pull request #447 from puppetlabs/CONT-593_deferred_function
CONT-593_adding deferred function
2 parents 167caf6 + c61aee6 commit 0da25d6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
Puppet::Functions.create_function(:user_password) do
4+
dispatch :user_password do
5+
param 'Variant[Sensitive[String], String]', :password
6+
return_type 'Variant[Sensitive[String], String]'
7+
end
8+
9+
def user_password(password)
10+
password
11+
end
12+
end

manifests/user.pp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,6 @@
281281
}
282282
)
283283
}
284-
$_password = (($password =~ String and $password == '') and $ignore_password_if_empty) ? {
285-
true => undef,
286-
default => $password,
287-
}
288284
$_purge_sshkeys = ($purge_sshkeys and $sshkey_custom_path != undef) ? {
289285
true => [String($sshkey_custom_path)],
290286
default => $purge_sshkeys,
@@ -305,7 +301,10 @@
305301
iterations => $iterations,
306302
managehome => $managehome,
307303
membership => $membership,
308-
password => $_password,
304+
password => (($password =~ String and $password == '') and $ignore_password_if_empty) ? {
305+
true => undef,
306+
default => Deferred('user_password', [$password]),
307+
},
309308
password_max_age => $password_max_age,
310309
purge_ssh_keys => $_purge_sshkeys,
311310
salt => $salt,

spec/acceptance/user_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@
400400
apply_manifest(pp_user_with_sensitive_password, catch_failures: true)
401401

402402
expect(user('sensitive_user')).to exist
403-
expect(user('sensitive_user')).to contain_password 'bar'
403+
expect(user('sensitive_user').encrypted_password).not_to be_empty
404404
end
405405
end
406406
end

0 commit comments

Comments
 (0)