2 # validate_domain_name.rb
4 module Puppet::Parser::Functions
5 newfunction(:validate_domain_name, :doc => <<-DOC
6 Validate that all values passed are syntactically correct domain names.
7 Fail compilation if any value fails this check.
9 The following values will pass:
11 $my_domain_name = 'server.domain.tld'
12 validate_domain_name($my_domain_name)
13 validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
15 The following values will fail, causing compilation to abort:
17 validate_domain_name(1)
18 validate_domain_name(true)
19 validate_domain_name('invalid domain')
20 validate_domain_name('-foo.example.com')
21 validate_domain_name('www.example.2com')
26 rescuable_exceptions = [ArgumentError]
29 raise Puppet::ParseError, "validate_domain_name(): wrong number of arguments (#{args.length}; must be > 0)"
33 raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
36 raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name" unless function_is_domain_name([arg])
37 rescue *rescuable_exceptions
38 raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name"