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

View File

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