<commit_before>/* jshint node: true  */
'use strict';

var request = require('request');
var url = require('url');

var DefaultBaseURI = 'https://api.enterprise.apigee.com';
var DefaultAsyncLimit = 4;

var DefaultDescriptor = {
  help: {
    name: 'Help',
    shortOption: 'h',
    toggle: true
  },
  username: {
    name: 'Username',
    shortOption: 'u',
    required: true
  },
  password: {
    name: 'Password',
    shortOption: 'p',
    required: true,
    secure: true
  },
  organization: {
    name: 'Organization',
    shortOption: 'o',
    required: true
  },
  baseuri: {
    name: 'Base URI',
    shortOption: 'L'
  },
  debug: {
    name: 'Debug',
    shortOption: 'D',
    toggle: true
  },
  verbose: {
    name: 'Verbose',
    shortOption: 'V',
    toggle: true
  },
  json: {
    name: 'JSON',
    shortOption: 'j',
    toggle: true
  }
};

module.exports.defaultDescriptor = function(opts) {
  var o = {};
  var n;
  for (n in DefaultDescriptor) {
    o[n] = DefaultDescriptor[n];
  }
  for (n in opts) {
    o[n] = opts[n];
  }
  return o;
};

var DefaultOptions = {
  baseuri: DefaultBaseURI,
  asyncLimit: DefaultAsyncLimit
};

module.exports.defaultOptions = function(opts) {
  for (var n in DefaultOptions) {
    if (!opts[n]) {
      opts[n] = DefaultOptions[n];
    }
  }
};

module.exports.defaultRequest = function(opts) {
  var ro = {
    auth: {
      username: opts.username,
      password: opts.password.getValue()
    },
    json: true
  };

  if (opts.baseuri) {
    var pu = url.parse(opts.baseuri);
    if ((pu.protocol === 'https:') &&
        process.env.https_proxy) {
      opts.proxy = process.env.https_proxy;

    } else if ((pu.protocol === 'http:') &&
                process.env.http_proxy) {
      opts.proxy = process.env.http_proxy;
    }
  }

  return request.defaults(ro);
};<commit_msg>added "cafile" and "insecure" command line options for handling SSL connections<commit_after>/* jshint node: true  */
'use strict';

var request = require('request');
var url = require('url');
var fs = require('fs');
var _ = require('underscore');

var DefaultBaseURI = 'https://api.enterprise.apigee.com';
var DefaultAsyncLimit = 4;

var DefaultDescriptor = {
  help: {
    name: 'Help',
    shortOption: 'h',
    toggle: true
  },
  username: {
    name: 'Username',
    shortOption: 'u',
    required: true
  },
  password: {
    name: 'Password',
    shortOption: 'p',
    required: true,
    secure: true
  },
  organization: {
    name: 'Organization',
    shortOption: 'o',
    required: true
  },
  baseuri: {
    name: 'Base URI',
    shortOption: 'L'
  },
  debug: {
    name: 'Debug',
    shortOption: 'D',
    toggle: true
  },
  verbose: {
    name: 'Verbose',
    shortOption: 'V',
    toggle: true
  },
  json: {
    name: 'JSON',
    shortOption: 'j',
    toggle: true
  },
  cafile: {
    name: 'CA file',
    shortOption: 'c'
  },
  insecure: {
    name: 'insecure',
    shortOption: 'k',
    toggle: true
  }
};

module.exports.defaultDescriptor = function(opts) {
  var o = {};
  var n;
  for (n in DefaultDescriptor) {
    o[n] = DefaultDescriptor[n];
  }
  for (n in opts) {
    o[n] = opts[n];
  }
  return o;
};

var DefaultOptions = {
  baseuri: DefaultBaseURI,
  asyncLimit: DefaultAsyncLimit
};

module.exports.defaultOptions = function(opts) {
  for (var n in DefaultOptions) {
    if (!opts[n]) {
      opts[n] = DefaultOptions[n];
    }
  }
};

module.exports.defaultRequest = function(opts) {
  var ro = {
    auth: {
      username: opts.username,
      password: <PASSWORD>()
    },
    json: true,
    agentOptions: {}
  };

  if (opts.baseuri) {
    var pu = url.parse(opts.baseuri);
    if ((pu.protocol === 'https:') &&
        process.env.https_proxy) {
      opts.proxy = process.env.https_proxy;

    } else if ((pu.protocol === 'http:') &&
                process.env.http_proxy) {
      opts.proxy = process.env.http_proxy;
    }
  }


  if (opts.cafile) {
    var files = opts.cafile.split(','),
      ca = [];

    _.each(files, function(file) {
        ca.push(fs.readFileSync(file))
    });

    ro.agentOptions.ca = ca;
  }

  if (opts.insecure) {
    ro.agentOptions.rejectUnauthorized = false;
  }

  return request.defaults(ro);
};
{'fraction_non_alphanumeric': 0.15967780146884625, 'fraction_numerical': 0.00047382136934375743, 'mean_word_length': 2.5901360544217686, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '2705940', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1475, 'n_words': 334}