<commit_before>const yaml = require('js-yaml')
const Joi = require('joi')
const schema = Joi.object().keys({
  juiceShopUrl: [Joi.string().uri().required(), Joi.string().ip().required()],
  ctfKey: Joi.string().required(),
  insertHints: Joi.any().valid('none', 'free', 'paid').required(),
  insertHintUrls: Joi.any().valid('none', 'free', 'paid').required()
})

const hintsMap = {'none': 0, 'free': 1, 'paid': 2}

function readConfigStream (stream) {
  return new Promise((resolve, reject) => {
    let data = ''
    stream.on('data', (chunk) => {
      data = data + chunk
    })
    stream.on('end', () => {
      try {
        yaml.safeLoadAll(data, (doc) => {
          const validation = Joi.validate(doc, schema)
          if (validation.error) {
            reject(validation.error)
          } else {
            const result = validation.value
            result.insertHints = hintsMap[result.insertHints]
            result.insertHintUrls = hintsMap[result.insertHintUrls]
            resolve(result)
          }
        })
      } catch (error) {
        reject(error)
      }
    })
  })
}

module.exports = readConfigStream
<commit_msg>Configured yml schema to be compatible with fbctf config options<commit_after>const yaml = require('js-yaml')
const Joi = require('joi')
const options = require('./options')
const schema = Joi.object().keys({
  ctfFramework: Joi.string().optional().valid(options.ctfdFramework, options.fbctfFramework),
  juiceShopUrl: [Joi.string().uri().required(), Joi.string().ip().required()],
  countryMapping: Joi.string().when('ctfFramework', {is: options.fbctfFramework, then: Joi.required(), otherwise: Joi.optional()}),
  ctfKey: Joi.string().required(),
  insertHints: Joi.any().valid('none', 'free', 'paid').required(),
  insertHintUrls: Joi.any().valid('none', 'free', 'paid').when('ctfFramework', { is: options.ctfdFramework, then: Joi.required(), otherwise: Joi.optional() })
})

const hintsMap = {'none': 0, 'free': 1, 'paid': 2}

function readConfigStream (stream) {
  return new Promise((resolve, reject) => {
    let data = ''
    stream.on('data', (chunk) => {
      data = data + chunk
    })
    stream.on('end', () => {
      try {
        yaml.safeLoadAll(data, (doc) => {
          const validation = Joi.validate(doc, schema)
          if (validation.error) {
            reject(validation.error)
          } else {
            const result = validation.value
            result.insertHints = hintsMap[result.insertHints]
            result.insertHintUrls = hintsMap[result.insertHintUrls]
            resolve(result)
          }
        })
      } catch (error) {
        reject(error)
      }
    })
  })
}

module.exports = readConfigStream

{'fraction_non_alphanumeric': 0.16826923076923078, 'fraction_numerical': 0.0022189349112426036, 'mean_word_length': 2.931686046511628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2096367', 'n_tokens_mistral': 846, 'n_tokens_neox': 830, 'n_words': 167}