<commit_before>const superagent = require('superagent');
const url = require('url');
const config = require('../config');
const generateApiGatewayToken = require('../apiGateway');
const { logger: log } = require('./logger');

function signIn(username, password) {
  log.info(`Signing in user: ${username}`);
  return new Promise((resolve, reject) => {
    superagent
      .post(url.resolve(`${config.elite2.url}`, 'users/login'))
      .set('Authorization', `Bearer ${generateApiGatewayToken()}`)
      .send({ username, password })
      .timeout({
        response: 2000,
        deadline: 2500,
      })
      .end((error, res) => {
        try {
          if (error) {
            log.error(`Sign in to Elite 2 failed for [${username}] with error:`);
            log.error(error);
            reject(error);
          }

          const eliteAuthorisationToken = res.body.token;
          superagent.get(url.resolve(`${config.elite2.url}`, 'users/me'))
          .set('Authorization', `Bearer ${generateApiGatewayToken()}`)
          .set('Elite-Authorization', eliteAuthorisationToken)
          .end((error2, res2) => {
            if (error2) {
              log.error(error2);
            }
            log.info(`Sign in to Elite 2 for [${username}] successful`);
            resolve({
              forename: res2.body.firstName,
              surname: res2.body.lastName,
              eliteAuthorisationToken });
          });
        } catch (exception) {
          log.error(`Sign in to Elite 2 failed for [${username}] with exception:`);
          log.error(exception);
          reject(exception);
        }
      });
  });
}

function signInFor(username, password) {
  return signIn(username, password);
}

module.exports = function createSignInService() {
  return { signIn: (username, password) => signInFor(username, password) };
};<commit_msg>CSRA-680: Converts signin service to async / await<commit_after>const superagent = require('superagent');
const url = require('url');
const config = require('../config');
const generateApiGatewayToken = require('../apiGateway');
const { logger: log } = require('./logger');

async function signIn(username, password) {
  log.info(`Signing in user: ${username}`);
  const result = await superagent
    .post(url.resolve(`${config.elite2.url}`, 'users/login'))
    .set('Authorization', `Bearer ${generateApiGatewayToken()}`)
    .send({
      username,
      password,
    })
    .timeout({
      response: 2000,
      deadline: 2500,
    });

  const eliteAuthorisationToken = result.body.token;
  const userDetailsResult = await superagent
    .get(url.resolve(`${config.elite2.url}`, 'users/me'))
    .set('Authorization', `Bearer ${generateApiGatewayToken()}`)
    .set('Elite-Authorization', eliteAuthorisationToken);

  log.info(`Sign in to Elite 2 for [${username}] successful`);

  return {
    forename: userDetailsResult.body.firstName,
    surname: userDetailsResult.body.lastName,
    eliteAuthorisationToken,
  };
}

function signInFor(username, password) {
  return signIn(username, password);
}

module.exports = function createSignInService() {
  return { signIn: (username, password) => signInFor(username, password) };
};
{'fraction_non_alphanumeric': 0.15271705184259837, 'fraction_numerical': 0.010306058713304185, 'mean_word_length': 3.0595690747782003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5799577', 'n_tokens_mistral': 935, 'n_tokens_neox': 922, 'n_words': 206}