<commit_before>const log = require('./log')
const ldap = require('ldapjs')
const settings = require('../config/serverSettings')
function getBoundClient () {
  return new Promise((resolve, reject) => {
    const options = {
      url: settings.ldap.url,
      timeout: 1000,
      connectTimeout: 2000,
      log: log
    }
    // const username = process.env.LDAP_USERNAME
    // const password = <PASSWORD>.LDAP_PASSWORD

    const username = settings.ldap.userName
    const password = <PASSWORD>

    log.info('Should get ldap client for', username, 'on', options.url)
    const ldapClient = ldap.createClient(options)
    const doReject = function (e) {
      log.debug('In ldapClient rejection callback:', e)
      reject(e)
    }
    ldapClient.on('error', doReject)
    ldapClient.on('timeout', doReject)
    ldapClient.on('connectTimeout', doReject)
    ldapClient.bind(username, password, function (err) {
      if (err) {
        reject(err)
      } else {
        log.info('Created bound ldap client')
        resolve(ldapClient)
      }
    })
  })
}

function lookupUser (ldapClient, kthid) {
  return new Promise((resolve, reject) => {
    ldapClient.search(
      settings.ldap.base,
      {
        scope: 'sub',
        filter: `(ugKthId=${kthid})`,
        timeLimit: 10,
        paging: true,
        attributes: ['givenName', 'sn', 'norEduPersonNIN'],
        paged: {
          pageSize: 1000,
          pagePause: false
        }
      },
      function (err, res) {
        if (err) {
          log.debug('Got err from search:', err)
          reject(err)
        } else {
          let user
          res.on('searchEntry', ({object}) => { user = object })
          res.on('end', () => resolve(user || {}))
          res.on('error', (e) => {
            console.log('error', e)
            reject(e)
          })
        }
      }
    )
  })
}

module.exports = {
  getBoundClient,
  lookupUser
}<commit_msg>rolled back one minor code change<commit_after>const log = require('./log')
const ldap = require('ldapjs')
const settings = require('../config/serverSettings')
function getBoundClient () {
  return new Promise((resolve, reject) => {
    const options = {
      url: settings.ldap.url,
      timeout: 1000,
      connectTimeout: 2000,
      log: log
    }
    // const username = process.env.LDAP_USERNAME
    // const password = <PASSWORD>.LDAP_PASSWORD

    const username = settings.ldap.userName
    const password = <PASSWORD>

    log.info('Should get ldap client for', username, 'on', options.url)
    const ldapClient = ldap.createClient(options)
    const doReject = function (e) {
      log.debug('In ldapClient rejection callback:', e)
      reject(e)
    }
    ldapClient.on('error', doReject)
    ldapClient.on('timeout', doReject)
    ldapClient.on('connectTimeout', doReject)
    ldapClient.bind(username, password, function (err) {
      if (err) {
        reject(err)
      } else {
        log.info('Created bound ldap client')
        resolve(ldapClient)
      }
    })
  })
}

function lookupUser (ldapClient, kthid) {
  return new Promise((resolve, reject) => {
    ldapClient.search(
      settings.ldap.base,
      {
        scope: 'sub',
        filter: `(ugKthId=${kthid})`,
        timeLimit: 10,
        paging: true,
        attributes: ['givenName', 'sn', 'norEduPersonNIN'],
        paged: {
          pageSize: 1000,
          pagePause: false
        }
      },
      function (err, res) {
        if (err) {
          log.debug('Got err from search:', err)
          reject(err)
        } else {
          let user
          res.on('searchEntry', ({object}) => { user = object })
          res.on('end', () => resolve(user || {}))
          res.on('error', reject)
        }
      }
    )
  })
}

module.exports = {
  getBoundClient,
  lookupUser
}
{'fraction_non_alphanumeric': 0.1390346274921301, 'fraction_numerical': 0.007345225603357817, 'mean_word_length': 2.2177215189873416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '567683', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1186, 'n_words': 266}