renable parseCli

This commit is contained in:
AJ ONeal 2018-06-29 15:53:55 -06:00
parent 59baac2d2e
commit a928decbd8
2 changed files with 19 additions and 13 deletions

View File

@ -335,7 +335,7 @@ var utils = {
request: function request(opts, fn) {
if (!opts) { opts = {}; }
var service = opts.service || 'config';
var req = http.get({
var req = http.request({
socketPath: state._ipc.path
, method: opts.method || 'GET'
, path: '/rpc/' + service
@ -395,11 +395,10 @@ var utils = {
console.error(err);
return;
});
req.end();
}
, putConfig: function putConfig(service, args, fn) {
//console.log('debug path:');
//console.log('/rpc/' + service + '?_body=' + JSON.stringify(args));
var req = http.get({
var req = http.request({
socketPath: state._ipc.path
, method: 'POST'
, path: '/rpc/' + service + '?_body=' + JSON.stringify(args)
@ -458,6 +457,7 @@ var utils = {
console.error(err);
return;
});
req.end();
}
};
@ -546,7 +546,7 @@ function getToken(err, state) {
console.error(err);
return;
}
console.log("waiting...");
console.info("waiting...");
next();
});
}
@ -557,10 +557,9 @@ function getToken(err, state) {
return;
}
state._connecting = true;
console.log("Token Offered:");
console.log(token);
try {
console.log(require('jsonwebtoken').decode(token));
require('jsonwebtoken').decode(token);
//console.log(require('jsonwebtoken').decode(token));
} catch(e) {
console.warn("[warning] could not decode token");
}
@ -603,6 +602,8 @@ function getToken(err, state) {
}
function parseCli(/*state*/) {
//console.log(parseCli);
//console.log(argv);
if (-1 !== argv.indexOf('init')) {
utils.putConfig('list', []/*, function (err) {
}*/);
@ -619,8 +620,7 @@ function parseCli(/*state*/) {
}
return true;
})) {
help();
process.exit(13);
process.exit(0);
return;
}

View File

@ -459,13 +459,19 @@ function serveControlsHelper() {
require('mkdirp').sync(path.resolve(state._ipc.path, '..'));
controlServer.listen({
path: state._ipc.path
, host: 'localhost'
//, port: 0
, writableAll: true
, readableAll: true
, exclusive: false
}, function () {
process.umask(oldUmask);
var address = this.address();
if (address.port) {
common.setPort(state.config, address.port);
}
//console.log(this.address());
console.info("[info] Listening for commands on " + state._ipc.path);
console.info("[info] Listening for commands on " + address);
});
}
@ -689,7 +695,7 @@ state.handlers = {
state.config.token = opts.jwt || opts.access_token;
console.info("Updating '" + tokenpath + "' with new token:");
try {
require('fs').writeFileSync(tokenpath, opts.jwt);
fs.writeFileSync(tokenpath, opts.jwt);
fs.writeFileSync(confpath, YAML.safeDump(snakeCopy(state.config)));
} catch (e) {
console.error("Token not saved:");
@ -728,6 +734,6 @@ state.net = state.net || {
}
};
require('fs').readFile(confpath, 'utf8', parseConfig);
fs.readFile(confpath, 'utf8', parseConfig);
}());