<commit_before>model = require '../lib/model.coffee'
util = require '../lib/util.coffee'
request = require 'request'
SECRET = process.env.CAVALRYPASS or "<PASSWORD>"

parseJSON = (str) ->
  try
    str = JSON.parse str
  catch err
  return str

Cavalry = ->
  @postJSON = (arg, slave, opts, cb) ->
    url = "http://#{model.slaves[slave].ip}:3000/#{arg}"
    request
      json: opts
      auth:
        user: "master"
        pass: SECRET
      url: url
    , (error, response, body) ->
      body = parseJSON body
      cb error, body
  @getJSON = (arg, slave, cb) ->
    url = "http://#{model.slaves[slave].ip}:3000/#{arg}"
    request.get
      url: url
      auth:
        user: "master"
        pass: SECRET
    , (error, response, body) ->
      body = parseJSON body
      cb error, body
  @spawn = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/spawn", slave, opts, cb
  @exec = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/exec", slave, opts, cb
  @stop = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/stop", slave, opts, cb
  @restart = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/restart", slave, opts, cb
  @fetch = (slave, opts, cb) =>
    @postJSON "fetch", slave, opts, cb
  @port = (slave, cb) =>
    @getJSON "port", slave, cb
  @ps = (slave, cb) ->
    @getJSON "ps", slave, cb
  @sendRouting = (slave, table, cb) =>
    @postJSON "routingTable", slave, table, cb

  return this

cavalry = new Cavalry()
module.exports = cavalry
<commit_msg>Accept cavalry port from environment variables<commit_after>model = require '../lib/model.coffee'
util = require '../lib/util.coffee'
request = require 'request'
SECRET = process.env.CAVALRYPASS or "testing<PASSWORD>"
CAVALRY_PORT = parseInt process.env.CAVALRYPORT
CAVALRY_PORT = 3000 if isNaN(CAVALRY_PORT)

parseJSON = (str) ->
  try
    str = JSON.parse str
  catch err
  return str

Cavalry = ->
  @slaveUrl = (slave) ->
   "http://#{model.slaves[slave].ip}:#{CAVALRY_PORT}"
  @postJSON = (arg, slave, opts, cb) ->
    url = "#{@slaveUrl(slave)}/#{arg}"
    request
      json: opts
      auth:
        user: "master"
        pass: <PASSWORD>
      url: url
    , (error, response, body) ->
      body = parseJSON body
      cb error, body
  @getJSON = (arg, slave, cb) ->
    url = "#{@slaveUrl(slave)}/#{arg}"
    request.get
      url: url
      auth:
        user: "master"
        pass: <PASSWORD>
    , (error, response, body) ->
      body = parseJSON body
      cb error, body
  @spawn = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/spawn", slave, opts, cb
  @exec = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/exec", slave, opts, cb
  @stop = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/stop", slave, opts, cb
  @restart = (slave, opts, cb) =>
    @postJSON "#{util.apiVersion}/restart", slave, opts, cb
  @fetch = (slave, opts, cb) =>
    @postJSON "fetch", slave, opts, cb
  @port = (slave, cb) =>
    @getJSON "port", slave, cb
  @ps = (slave, cb) ->
    @getJSON "ps", slave, cb
  @sendRouting = (slave, table, cb) =>
    @postJSON "routingTable", slave, table, cb

  return this

cavalry = new Cavalry()
module.exports = cavalry

{'fraction_non_alphanumeric': 0.16865953429830083, 'fraction_numerical': 0.003775959723096287, 'mean_word_length': 2.8117505995203835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 36, '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': '5242504', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1118, 'n_words': 311}