Puppet Function: validate_ldap_sub_dn

Defined in:
lib/puppet/parser/functions/validate_ldap_sub_dn.rb
Function type:
Ruby 3.x API

Overview

validate_ldap_sub_dn()Any

Returns:

  • (Any)


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
35
36
37
38
39
40
41
42
# File 'lib/puppet/parser/functions/validate_ldap_sub_dn.rb', line 6

newfunction(:validate_ldap_sub_dn, :doc => <<-EOS
  EOS
) do |arguments|

  raise Puppet::ParseError, 'validate_ldap_sub_dn(): Wrong number of ' +
    "arguments given (#{arguments.size} for 2)" if arguments.size != 2

  base = arguments[0]
  item = arguments[1]

  function_validate_ldap_dn([base])

  unless item.is_a?(Array)
    item = [item]
  end

  if item.size == 0
    raise Puppet::ParseError, 'validate_ldap_sub_dn(): Requires an array ' +
      'with at least 1 element'
  end

  item.each do |i|
    unless i.is_a?(String)
      raise Puppet::ParseError, 'validate_ldap_sub_dn(): Requires either ' +
        'an array or string to work with'
    end

    begin
      function_validate_ldap_dn([i])
      # Crude, but it should work
      raise unless i =~ /(?:^|,)#{Regexp.escape(base)}$/
    rescue
      raise Puppet::ParseError, 'validate_ldap_sub_dn(): ' +
        "#{i.inspect} is not a valid LDAP subtree distinguished name"
    end
  end
end