<commit_before>http = require 'http'
crypto = require 'crypto'

apiGet = (method, arguments, callback) ->
  options =
    host: 'web0.dev.system.aws.koding.com'
    port: 15672
    auth: 'kite-manager:Zwh4IGCDHfqE1MQ'
    path: '/api/' + method
    method: 'GET'

  req = http.request options, (res) ->
    res.setEncoding 'utf8'
    res.on 'data', (chunk) ->
      callback null, chunk

  req.on 'error', (e) ->
    callback e, null

  req.end()

apiSet = (method, arguments, callback) ->
  options =
    host: 'web0.dev.system.aws.koding.com'
    port: 15672
    auth: 'kite-manager:Zwh4IGCDHfqE1MQ'
    path: '/api/' + method
    method: 'PUT'
    headers: {'content-type': 'application/json'}

  req = http.request options, (res) ->
    res.setEncoding 'utf8'
    callback null, {}

  req.on 'error', (e) ->
    console.log e
    callback e, null

  req.write JSON.stringify arguments
  req.end()

newUser = (key, secret, callback) ->
  crypto.randomBytes 12, (ex1, buf1) ->
    crypto.randomBytes 12, (ex2, buf2) ->
      username = "kite-api-" + buf1.toString 'hex'
      password = buf2.toString 'hex'

      args =
        password: password
        tags: ''

      apiSet "users/#{username}", args, (err, data) ->
        if err
          callback err, {}
        else
          callback null, {username: username, password: password}<commit_msg>Set permissions<commit_after>http = require 'http'
crypto = require 'crypto'

apiGet = (method, arguments, callback) ->
  options =
    host: 'web0.dev.system.aws.koding.com'
    port: 15672
    auth: 'kite-manager:Zwh4IGCDHfqE1MQ'
    path: '/api/' + method
    method: 'GET'

  req = http.request options, (res) ->
    res.setEncoding 'utf8'
    res.on 'data', (chunk) ->
      callback null, chunk

  req.on 'error', (e) ->
    callback e, null

  req.end()

apiSet = (method, arguments, callback) ->
  options =
    host: 'web0.dev.system.aws.koding.com'
    port: 15672
    auth: 'kite-manager:Zwh4IGCDHfqE1MQ'
    path: '/api/' + method
    method: 'PUT'
    headers: {'content-type': 'application/json'}

  req = http.request options, (res) ->
    res.setEncoding 'utf8'
    callback null, {}

  req.on 'error', (e) ->
    console.log e
    callback e, null

  req.write JSON.stringify arguments
  req.end()

newUser = (key, secret, callback) ->
  crypto.randomBytes 12, (ex1, buf1) ->
    crypto.randomBytes 12, (ex2, buf2) ->
      username = "kite-api-" + buf1.toString 'hex'
      password = <PASSWORD> '<PASSWORD>'
      vhost    = '%2F'

      args =
        password : password
        tags     : ''

      apiSet "users/#{username}", args, (err, data) ->
        if err
          callback err, {}
        else
          args2 =
            configure : '.*'
            write     : '.*'
            read      : '.*'
          apiSet "permissions/#{vhost}/#{username}", args2, (err2, data2) ->
            if err2
              callback err2, {}
            else
              callback null, {username: username, password: password}
{'fraction_non_alphanumeric': 0.14833333333333334, 'fraction_numerical': 0.020666666666666667, 'mean_word_length': 2.2513542795232935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '5529173', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1004, 'n_words': 254}