<commit_before>'use strict';

const oauth = require('abacus-oauth');

const config = require('../config.js');

const debug = require('abacus-debug')('abacus-broker');
const edebug = require('abacus-debug')('e-abacus-broker');

const systemToken = oauth.cache(config.uris().api,
  process.env.SERVICE_BROKER_CLIENT_ID,
  process.env.SERVICE_BROKER_CLIENT_SECRET, 'clients.write clients.admin');

const init = () => {
  if(!process.env.SERVICE_BROKER_CLIENT_ID &&
    !process.env.SERVICE_BROKER_CLIENT_SECRET)
    throw new Error('SERVICE_BROKER credentials are not supplied');

  debug('Fetching OAuth system token from server %o', config.uris().cf_api);
  systemToken.start((err) => {
    if (err)
      edebug('Could not fetch OAuth token %o', err);
    else
      debug('Successfully fetched OAuth token from %s', config.uris().cf_api);
  });
  debug('Started OAuth system token from %o authentication server',
    config.uris().api);
};

const authHeader = () => {
  let token = systemToken();
  return token ? { authorization: token } : undefined;
};

module.exports.init = init;
module.exports.authHeader = authHeader;<commit_msg>Fix debug message in oauth (#21)<commit_after>'use strict';

const oauth = require('abacus-oauth');

const config = require('../config.js');

const debug = require('abacus-debug')('abacus-broker');
const edebug = require('abacus-debug')('e-abacus-broker');

const systemToken = oauth.cache(config.uris().api,
  process.env.SERVICE_BROKER_CLIENT_ID,
  process.env.SERVICE_BROKER_CLIENT_SECRET, 'clients.write clients.admin');

const init = () => {
  if(!process.env.SERVICE_BROKER_CLIENT_ID &&
    !process.env.SERVICE_BROKER_CLIENT_SECRET)
    throw new Error('SERVICE_BROKER credentials are not supplied');

  debug('Fetching OAuth system token from server %o', config.uris().api);
  systemToken.start((err) => {
    if (err)
      edebug('Could not fetch OAuth token %o', err);
    else
      debug('Successfully fetched OAuth token from %s', config.uris().api);
  });
  debug('Started OAuth system token from %o authentication server',
    config.uris().api);
};

const authHeader = () => {
  let token = systemToken();
  return token ? { authorization: token } : undefined;
};

module.exports.init = init;
module.exports.authHeader = authHeader;
{'fraction_non_alphanumeric': 0.14923413566739607, 'fraction_numerical': 0.00087527352297593, 'mean_word_length': 4.686567164179104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2207171', 'n_tokens_mistral': 763, 'n_tokens_neox': 768, 'n_words': 166}