def find_ou()

in ad-joining/register-computer/ad/domain.py [0:0]


    def find_ou(self, search_base_dn, name=None, includeDescendants=True):
        if name:
            search_filter = f"(&(objectClass=organizationalUnit)(name={ldap3.utils.conv.escape_filter_chars(name)}))"
        else:
            search_filter = "(objectClass=organizationalUnit)"

        if includeDescendants:
            search_scope = ldap3.SUBTREE
        else:
            search_scope = ldap3.BASE
        
        try:
            return self.__find(
                converter=self.__to_ou, 
                search_filter=search_filter,
                search_base_dn=search_base_dn, 
                search_scope=search_scope, 
                attributes=[
                    "distinguishedName", 
                    "name"
                ]
            )
        except ldap3.core.exceptions.LDAPNoSuchObjectResult:
            # In case OU was not found, return an empty array instead of raising an exception
            return []