X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fvalidate_augeas.rb;h=97f3127e3f7b30b9ba77255eb774bf1791d8ec69;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=2196c3e0ebda7eacd281a6b8e273962997586f87;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb index 2196c3e0e..97f3127e3 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb @@ -1,7 +1,10 @@ require 'tempfile' +# +# validate_augaes.rb +# module Puppet::Parser::Functions - newfunction(:validate_augeas, :doc => <<-'ENDHEREDOC') do |args| + newfunction(:validate_augeas, :doc => <<-'DOC') do |args| Perform validation of a string using an Augeas lens The first argument of this function should be a string to test, and the second argument should be the name of the Augeas lens to use. @@ -29,24 +32,24 @@ module Puppet::Parser::Functions validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') - ENDHEREDOC + DOC unless Puppet.features.augeas? - raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://docs.puppetlabs.com/guides/augeas.html#pre-requisites for how to activate it.") + raise Puppet::ParseError, 'validate_augeas(): this function requires the augeas feature. See http://docs.puppetlabs.com/guides/augeas.html#pre-requisites for how to activate it.' end - if (args.length < 2) or (args.length > 4) then - raise Puppet::ParseError, ("validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)") + if (args.length < 2) || (args.length > 4) + raise Puppet::ParseError, "validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)" end msg = args[3] || "validate_augeas(): Failed to validate content against #{args[1].inspect}" require 'augeas' - aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD) + aug = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD) begin content = args[0] # Test content in a temporary file - tmpfile = Tempfile.new("validate_augeas") + tmpfile = Tempfile.new('validate_augeas') begin tmpfile.write(content) ensure @@ -58,14 +61,14 @@ module Puppet::Parser::Functions aug.transform( :lens => lens, :name => 'Validate_augeas', - :incl => tmpfile.path + :incl => tmpfile.path, ) aug.load! unless aug.match("/augeas/files#{tmpfile.path}//error").empty? error = aug.get("/augeas/files#{tmpfile.path}//error/message") msg += " with error: #{error}" - raise Puppet::ParseError, (msg) + raise Puppet::ParseError, msg end # Launch unit tests @@ -73,7 +76,7 @@ module Puppet::Parser::Functions aug.defvar('file', "/files#{tmpfile.path}") tests.each do |t| msg += " testing path #{t}" - raise Puppet::ParseError, (msg) unless aug.match(t).empty? + raise Puppet::ParseError, msg unless aug.match(t).empty? end ensure aug.close