Last change
on this file since 30960 was 30960, checked in by davidb, 7 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
1.1 KB
|
Line | |
---|
1 | module 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
|
---|
31 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.