source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/validate_email_address.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 1.1 KB
Line 
1module Puppet::Parser::Functions
2 newfunction(:validate_email_address, :doc => <<-ENDHEREDOC
3 Validate that all values passed are valid email addresses.
4 Fail compilation if any value fails this check.
5 The following values will pass:
6 $my_email = "[email protected]"
7 validate_email_address($my_email)
8 validate_email_address("[email protected]", "[email protected]", $my_email)
9
10 The following values will fail, causing compilation to abort:
11 $some_array = [ 'bad_email@/d/efdf.com' ]
12 validate_email_address($some_array)
13 ENDHEREDOC
14 ) do |args|
15 rescuable_exceptions = [ArgumentError]
16
17 if args.empty?
18 raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)"
19 end
20
21 args.each do |arg|
22 raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
23
24 begin
25 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg])
26 rescue *rescuable_exceptions
27 raise Puppet::ParseError, "#{arg.inspect} is not a valid email address"
28 end
29 end
30 end
31end
Note: See TracBrowser for help on using the repository browser.