2 # validate_domain_name.rb
4 module Puppet::Parser::Functions
5 newfunction(:validate_domain_name, :doc => <<-DOC
7 Validate that all values passed are syntactically correct domain names.
8 Fail compilation if any value fails this check.
11 passes when the given values are syntactically correct domain names or raise an error when they are not and fails compilation
15 The following values will pass:
17 $my_domain_name = 'server.domain.tld'
18 validate_domain_name($my_domain_name)
19 validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
21 The following values will fail, causing compilation to abort:
23 validate_domain_name(1)
24 validate_domain_name(true)
25 validate_domain_name('invalid domain')
26 validate_domain_name('-foo.example.com')
27 validate_domain_name('www.example.2com')
31 rescuable_exceptions = [ArgumentError]
34 raise Puppet::ParseError, "validate_domain_name(): wrong number of arguments (#{args.length}; must be > 0)"
38 raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
41 raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name" unless function_is_domain_name([arg])
42 rescue *rescuable_exceptions
43 raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name"