-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (54 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
var fs = require('fs');
var Path = require('path');
var request = require('request');
var read = require("read");
var async = require("async");
var host = process.env.HEROKU_HOST || 'http://mymachine.me:5000/';
var home = process.env.HOME;
var netrc = fs.readFileSync(Path.join(home, '.netrc')).toString();
var lines = netrc.split('\n');
var key;
lines.forEach(function(line, i){
if(line.indexOf(host) != 1){
var passwordline = lines[i+2];
if(passwordline) key = passwordline.replace(' password ', '');
}
});
if(!key){
throw new Error('~/netrc does not contains OpenRuko key, Please use OpenRuko cli before.');
}
async.series([
function(cb){
read({
prompt: 'User name:'
}, cb);
},
function(cb){
read({
prompt: 'User email:'
}, cb);
},
function(cb){
read({
prompt: 'User password:',
silent: true
}, cb);
}
], function(err, arr){
request.post({
url: host + 'internal/user',
headers: {
'Content-Type': 'application/json',
'Authorization': ' Basic ' +
new Buffer(':' + key).toString('base64')
},
body: JSON.stringify({
name: arr[0][0],
email: arr[1][0],
password: arr[2][0]
})
}, function(err, resp, body){
console.log(body);
});
});