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