Puppet Function: simplib::ldap::domain_to_dn

Defined in:
functions/ldap/domain_to_dn.pp
Function type:
Puppet Language

Overview

simplib::ldap::domain_to_dn(String $domain = $facts['domain'], Boolean $downcase_attributes = false)String

Generates a LDAP Base DN from a domain

Examples:

Generate LDAP Base DN with uppercase attributes


$ldap_dn = simplib::ldap::domain_to_dn('test.local')

returns $ldap_dn = 'DC=test,DC=local'

Generate LDAP Base DN with lowercase attributes


$ldap_dn = simplib::ldap::domain_to_dn('test.local', true)

returns $ldap_dn = 'dc=test,dc=local'

Parameters:

  • domain (String) (defaults to: $facts['domain'])

    The domain to convert, defaults to the “domain“ fact

  • downcase_attributes (Boolean) (defaults to: false)

    Whether to downcase the LDAP attributes

    * Different tools have bugs where they cannot, handle
      both upcased and downcased LDAP attribute elements
    

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'functions/ldap/domain_to_dn.pp', line 26

function simplib::ldap::domain_to_dn (
  String $domain               = $facts['domain'],
  Boolean $downcase_attributes = false
) {
  if $downcase_attributes {
    $_dc = 'dc'
  }
  else {
    $_dc = 'DC'
  }

  join(split($domain,'\.').map |$x| { "${_dc}=${x}" }, ',')
}