<commit_before>var config = require('./config'),
  validator = require('validator');

function validateProtocol() {
  if (config.protocol != 'https') {

    var errorObj = {
      error: 'error.fatal.config.protocol.invalid.azure',
      message: 'The config.protocol value is ' + config.protocol +
        '. When running in Azure, CommitStream must operate over HTTPS.' +
        ' Please set the protocol value to https in the App Settings configuration for the web site.'
    };
    throw new Error(JSON.stringify(errorObj));
  };
};

function validateApiKey() {
  if (!config.apiKey || config.apiKey.length < 36) {
    var errorObj = {
      error: 'error.fatal.config.apiKey.invalid',
      message: 'The config.apiKey value is either not set or is set to a value containing fewer than 36 characters.' +
        'Please set it to a string containing at least 36 characters.'
    };
    throw new Error(JSON.stringify(errorObj));
  };
};

function validateEventStorePassword() {
  if (!config.eventStorePassword || config.eventStorePassword.length < 36) {
    var errorObj = {
      error: 'error.fatal.config.eventStorePassword.invalid',
      message: 'The config.eventStorePassword value is either not set or is set to a value containing fewer than 36 characters.' +
        ' Please set it to a string containing at least 36 characters.'
    }
    throw new Error(JSON.stringify(errorObj));
  }
};

function validateEventStoreUser() {
  if (!config.eventStoreUser) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreUser.invalid',
      message: 'The config.eventStoreUser value is either not set or is an empty string.Please set it to a valid non - empty string.'
    }

    throw new Error(JSON.stringify(errorObj));
  }
};

function validateUri() {
  var options = {
    protocols: ['http', 'https'],
    require_protocol: true
  };

  if (!validator.isURL(config.eventStoreBaseUrl, options)) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreBaseUrl.invalid',
      message: 'The config.eventStoreBaseUrl value is either not set or is set to a value that is not a valid ' +
        'URI using protocol HTTP or HTTPS. Please set it to a valid URI.'
    }

    throw new Error(JSON.stringify(errorObj));
  };
}

function validateHttpsUri() {
  var options = {
    protocols: ['https'],
    require_protocol: true
  };

  if (!validator.isURL(config.eventStoreBaseUrl, options)) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreBaseUrl.invalid.azure',
      message: 'The config.eventStoreBaseUrl value is either not set or is set to a value that is not a valid URI ' +
        'using the required HTTPS protocol. When running in Azure, CommitStream\'s EventStore dependency must operate over HTTPS. ' +
        'Please set the eventStoreBaseUrl value to a valid URI using the HTTPS protocol in the App Settings configuration for the web site.'
    }

    throw new Error(JSON.stringify(errorObj));
  };
}

var validate = function() {
  if (config.production) {
    validateProtocol();
    validateApiKey();
    validateEventStorePassword();
    validateHttpsUri();
  } else {
    validateUri();
  }
  validateEventStoreUser();
};

module.exports.validate = validate;<commit_msg>S-48999 split validateApiKey into validateApiKeyIsSet and validateApiKeyLength.<commit_after>var config = require('./config'),
  validator = require('validator');

function validateProtocolIsHttps() {
  if (config.protocol != 'https') {

    var errorObj = {
      error: 'error.fatal.config.protocol.invalid.azure',
      message: 'The config.protocol value is ' + config.protocol +
        '. When running in Azure, CommitStream must operate over HTTPS.' +
        ' Please set the protocol value to https in the App Settings configuration for the web site.'
    };
    throw new Error(JSON.stringify(errorObj));
  };
};

function validateApiKeyIsSet() {
  if (!config.apiKey) {
    var errorObj = {
      error: 'error.fatal.config.apiKey.invalid',
      message: 'The config.apiKey value is not set. Please set it to a string.'
    };
    throw new Error(JSON.stringify(errorObj));
  };
};

function validateApiKeyLength() {
  if (!config.apiKey || config.apiKey.length < 36) {
    var errorObj = {
      error: 'error.fatal.config.apiKey.invalid',
      message: 'The config.apiKey value is set to a value containing fewer than 36 characters.' +
        'Please set it to a string containing at least 36 characters.'
    };
    throw new Error(JSON.stringify(errorObj));
  };

};

function validateEventStorePassword() {
  if (!config.eventStorePassword || config.eventStorePassword.length < 36) {
    var errorObj = {
      error: 'error.fatal.config.eventStorePassword.invalid',
      message: 'The config.eventStorePassword value is either not set or is set to a value containing fewer than 36 characters.' +
        ' Please set it to a string containing at least 36 characters.'
    }
    throw new Error(JSON.stringify(errorObj));
  }
};

function validateEventStoreUser() {
  if (!config.eventStoreUser) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreUser.invalid',
      message: 'The config.eventStoreUser value is either not set or is an empty string.Please set it to a valid non - empty string.'
    }

    throw new Error(JSON.stringify(errorObj));
  }
};

function validateUri() {
  var options = {
    protocols: ['http', 'https'],
    require_protocol: true
  };

  if (!validator.isURL(config.eventStoreBaseUrl, options)) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreBaseUrl.invalid',
      message: 'The config.eventStoreBaseUrl value is either not set or is set to a value that is not a valid ' +
        'URI using protocol HTTP or HTTPS. Please set it to a valid URI.'
    }

    throw new Error(JSON.stringify(errorObj));
  };
}

function validateHttpsUri() {
  var options = {
    protocols: ['https'],
    require_protocol: true
  };

  if (!validator.isURL(config.eventStoreBaseUrl, options)) {
    var errorObj = {
      error: 'error.fatal.config.eventStoreBaseUrl.invalid.azure',
      message: 'The config.eventStoreBaseUrl value is either not set or is set to a value that is not a valid URI ' +
        'using the required HTTPS protocol. When running in Azure, CommitStream\'s EventStore dependency must operate over HTTPS. ' +
        'Please set the eventStoreBaseUrl value to a valid URI using the HTTPS protocol in the App Settings configuration for the web site.'
    }

    throw new Error(JSON.stringify(errorObj));
  };
}

var validate = function() {
  if (config.production) {
    validateProtocolIsHttps();
    validateApiKeyIsSet();
    validateApiKeyLength();
    validateEventStorePassword();
    validateHttpsUri();
  } else {
    validateUri();
  }
  validateApiKeyIsSet();
  validateEventStoreUser();
};

module.exports.validate = validate;
{'fraction_non_alphanumeric': 0.10481875090988499, 'fraction_numerical': 0.00422186635609259, 'mean_word_length': 3.348101265822785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5257817', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1907, 'n_words': 640}