Puppet Function: stdlib::validate_domain_name

Defined in:
lib/puppet/functions/stdlib/validate_domain_name.rb
Function type:
Ruby 4.x API

Summary

Validate that all values passed are syntactically correct domain names. Fail compilation if any value fails this check.

Overview

stdlib::validate_domain_name(Variant[Stdlib::Fqdn, Stdlib::Dns::Zone] *$values)Undef

Examples:

Passing examples

$my_domain_name = 'server.domain.tld'
stdlib::validate_domain_name($my_domain_name)
stdlib::validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
stdlib::validate_domain_name('www.example.2com')

Failing examples (causing compilation to abort)

stdlib::validate_domain_name(1)
stdlib::validate_domain_name(true)
stdlib::validate_domain_name('invalid domain')
stdlib::validate_domain_name('-foo.example.com')

Parameters:

  • *values (Variant[Stdlib::Fqdn, Stdlib::Dns::Zone])

    A domain name or an array of domain names to check

Returns:

  • (Undef)

    passes when the given values are syntactically correct domain names or raise an error when they are not and fails compilation



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/functions/stdlib/validate_domain_name.rb', line 6

Puppet::Functions.create_function(:'stdlib::validate_domain_name') do
  # @param values A domain name or an array of domain names to check
  #
  # @return [Undef]
  #   passes when the given values are syntactically correct domain names or raise an error when they are not and fails compilation
  #
  # @example Passing examples
  #   $my_domain_name = 'server.domain.tld'
  #   stdlib::validate_domain_name($my_domain_name)
  #   stdlib::validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
  #   stdlib::validate_domain_name('www.example.2com')
  #
  # @example Failing examples (causing compilation to abort)
  #   stdlib::validate_domain_name(1)
  #   stdlib::validate_domain_name(true)
  #   stdlib::validate_domain_name('invalid domain')
  #   stdlib::validate_domain_name('-foo.example.com')
  dispatch :validate_domain_name do
    repeated_param 'Variant[Stdlib::Fqdn, Stdlib::Dns::Zone]', :values
  end

  def validate_domain_name(*args)
    assert_arg_count(args)
  end

  def assert_arg_count(args)
    raise(ArgumentError, 'stdlib::validate_domain_name(): Wrong number of arguments need at least one') if args.empty?
  end
end