2011-04-30 04:16:12 +02:00
|
|
|
#
|
2011-06-29 22:21:55 +02:00
|
|
|
# is_valid_domain_name.rb
|
2011-04-30 04:16:12 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
2011-06-29 22:21:55 +02:00
|
|
|
newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS
|
2011-07-30 00:09:30 +02:00
|
|
|
Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included.
|
2011-04-30 04:16:12 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
if (arguments.size != 1) then
|
|
|
|
raise(Puppet::ParseError, "is_valid_domain_name(): Wrong number of arguments "+
|
|
|
|
"given #{arguments.size} for 1")
|
|
|
|
end
|
|
|
|
|
2011-07-29 21:08:31 +02:00
|
|
|
domain = arguments[0]
|
|
|
|
|
|
|
|
if domain =~ /^(([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/ then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2011-04-30 04:16:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|