From 16b06320cd3bb3121446717c05b6bc13ae2ff133 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 27 Jul 2011 18:41:27 +0200 Subject: init of trocla module --- lib/puppet/parser/functions/trocla_get.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/puppet/parser/functions/trocla_get.rb (limited to 'lib/puppet/parser/functions/trocla_get.rb') diff --git a/lib/puppet/parser/functions/trocla_get.rb b/lib/puppet/parser/functions/trocla_get.rb new file mode 100644 index 0000000..ed8eeab --- /dev/null +++ b/lib/puppet/parser/functions/trocla_get.rb @@ -0,0 +1,9 @@ +module Puppet::Parser::Functions + newfunction(:trocla_get, :type => :rvalue) do |*args| + 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!") + end + answer + end +end \ No newline at end of file -- cgit v1.2.3 From 20fdb3bcc7201bc86cfbddc269fe807a8e418963 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 3 Aug 2011 19:25:06 +0200 Subject: update doc --- lib/puppet/parser/functions/trocla_get.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions/trocla_get.rb') diff --git a/lib/puppet/parser/functions/trocla_get.rb b/lib/puppet/parser/functions/trocla_get.rb index ed8eeab..01c4e01 100644 --- a/lib/puppet/parser/functions/trocla_get.rb +++ b/lib/puppet/parser/functions/trocla_get.rb @@ -1,9 +1,28 @@ module Puppet::Parser::Functions - newfunction(:trocla_get, :type => :rvalue) do |*args| + newfunction(:trocla_get, :type => :rvalue, :doc => " + This will only get an already stored password from the trocla storage. + +Usage: + + $password_user1 = trocla_get(key,[format='plain']) + +Means: + + $password_user1 = trocla('user1') + +Get the plain text password for the key 'user1' + + $password_user2 = trocla_get('user2','mysql') + +Get the mysql style sha1 hashed password. + +It will raise a parse error if the password haven't yet been stored in trocla. +" + ) do |*args| 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!") end answer end -end \ No newline at end of file +end -- cgit v1.2.3 From 402b98284242713fbb7b0173da8aa6eff87fa595 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 12 Aug 2015 08:48:24 +0200 Subject: Fix #14 - allow trocla_get not to raise an error if nothing is found Up to now we raised an error if nothing was found while using trocla_get. The main idea was to ensure that typos in the key/format are easily spotted and not overlooked as no password being returned usually indicates that something is wrong. As outlined in #14 there are use cases where it makes sense to not have this behavior. This change allows us to suppress the error raising and just return the puppet undef if nothing is found. --- lib/puppet/parser/functions/trocla_get.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser/functions/trocla_get.rb') 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 -- cgit v1.2.3