2 # validate_email_address.rb
4 module Puppet::Parser::Functions
5 newfunction(:validate_email_address, :doc => <<-DOC
6 Validate that all values passed are valid email addresses.
7 Fail compilation if any value fails this check.
8 The following values will pass:
9 $my_email = "waldo@gmail.com"
10 validate_email_address($my_email)
11 validate_email_address("bob@gmail.com", "alice@gmail.com", $my_email)
13 The following values will fail, causing compilation to abort:
14 $some_array = [ 'bad_email@/d/efdf.com' ]
15 validate_email_address($some_array)
18 rescuable_exceptions = [ArgumentError]
21 raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)"
25 raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
28 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg])
29 rescue *rescuable_exceptions
30 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address"