Puppet Function: validate_ldap_uri

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

Overview

validate_ldap_uri()Any

Validate that all passed values are LDAP URI’s. Abort catalog compilation if any value fails this check.

Returns:

  • (Any)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/puppet/parser/functions/validate_ldap_uri.rb', line 49

newfunction(:validate_ldap_uri, :doc => <<-EOS
  Validate that all passed values are LDAP URI's. Abort catalog
  compilation if any value fails this check.
  EOS
) do |arguments|

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

  item = arguments[0]

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

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

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

    begin
      u = URI(i)
      case u.scheme
      when 'ldap', 'ldaps'
        # Do nothing
      when 'ldapi'
        if not u.host.nil?
          raise if not Pathname.new(URI.unescape(u.host)).absolute?
        end
      else
        raise
      end
      function_validate_ldap_dn([u.dn]) if u.dn and u.dn.length > 0
      # FIXME validate attributes
      if u.scope
        raise unless ['sub', 'one', 'base'].include?(u.scope)
      end
      function_validate_ldap_filter([u.filter]) if u.filter
      # FIXME validate extensions
    rescue
      raise(Puppet::ParseError, "#{i.inspect} is not a valid LDAP URI")
    end
  end
end