diff options
Diffstat (limited to 'lib/puppet/parser/functions/trocla_get.rb')
-rw-r--r-- | lib/puppet/parser/functions/trocla_get.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/puppet/parser/functions/trocla_get.rb b/lib/puppet/parser/functions/trocla_get.rb index 01c4e01..fb5cd5a 100644 --- a/lib/puppet/parser/functions/trocla_get.rb +++ b/lib/puppet/parser/functions/trocla_get.rb @@ -4,7 +4,7 @@ module Puppet::Parser::Functions Usage: - $password_user1 = trocla_get(key,[format='plain']) + $password_user1 = trocla_get(key,[format='plain'[,raise_error=true]]) Means: @@ -16,13 +16,23 @@ Get the plain text password for the key 'user1' Get the mysql style sha1 hashed password. -It will raise a parse error if the password haven't yet been stored in trocla. +By default puppet will raise a parse error if the password haven't yet been +stored in trocla. This can be turned off by setting false as a third argument: + + $password_user3 = trocla_get('user2','mysql',false) + +the return value will be undef if the key & format pair is not found. " ) do |*args| + if args[0].is_a?(Array) + args = args[0] + end require File.dirname(__FILE__) + '/../../util/trocla_helper' - if (answer=Puppet::Util::TroclaHelper.trocla(:get_password,false,*args)).nil? - raise(Puppet::ParseError, "No password for key,format #{args.flatten.inspect} found!") + args[1] ||= 'plain' + raise_error = args[2].nil? ? true : args[2] + if (answer=Puppet::Util::TroclaHelper.trocla(:get_password,false,[args[0],args[1]])).nil? && raise_error + raise(Puppet::ParseError, "No password for key,format #{args[0..1].flatten.inspect} found!") end - answer + answer.nil? ? :undef : answer end end |