forked from FredrikNoren/ungit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredentials-helper
executable file
·46 lines (39 loc) · 1.56 KB
/
credentials-helper
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
#!/usr/bin/env node
var config = require('../source/config');
var winston = require('winston');
var path = require('path');
var async = require('async');
winston.remove(winston.transports.Console);
var BugTracker = require('../source/bugtracker');
var bugtracker = new BugTracker('credentials-helper');
var usageStatistics = require('../source/usage-statistics');
process.on('uncaughtException', function(err) {
console.error(err.stack.toString());
async.parallel([
bugtracker.notify.bind(bugtracker, err, 'credentials-helper'),
usageStatistics.addEvent.bind(usageStatistics, 'credentials-helper-exception')
], function() {
process.exit();
});
});
if (config.logDirectory)
winston.add(winston.transports.File, { filename: path.join(config.logDirectory, 'credentials-helper.log'), maxsize: 100*1024, maxFiles: 2 });
var socketId = process.argv[2];
var port = process.argv[3];
winston.info('Credentials helper invoked; port ' + port + ', socketId ' + socketId);
var http = require('http');
if (process.argv[4] == 'get') {
winston.info('Getting credentials');
http.get('http://localhost:' + port + '/api/credentials?socketId=' + socketId, function(res) {
winston.info('Got credentials');
res.on('data', function(body) {
var data = JSON.parse(body);
console.log('username=' + data.username);
console.log('password=' + (data.password ? data.password : ''));
});
}).on('error', function(err) {
winston.error('Error getting credentials, couldn\'t query server', err);
});
} else {
winston.info('Unhandled param: ' + process.argv[4]);
}