revert console to only show cockpit results in cockpit

This commit is contained in:
Jonathan Rainville 2019-03-06 10:53:03 -05:00
parent 6662731898
commit fac29e1601
2 changed files with 14 additions and 4 deletions

View File

@ -1,3 +1,6 @@
import {EMBARK_PROCESS_NAME} from '../constants';
import {ansiToHtml} from '../utils/utils';
export const REQUEST = 'REQUEST';
export const SUCCESS = 'SUCCESS';
export const FAILURE = 'FAILURE';
@ -118,7 +121,17 @@ export const COMMANDS = createRequestTypes('COMMANDS');
export const commands = {
post: (command) => action(COMMANDS[REQUEST], {command}),
success: (command, payload) => {
return action(COMMANDS[SUCCESS], {});
return action(COMMANDS[SUCCESS], {
processLogs: [
{
timestamp: new Date().getTime(),
name: EMBARK_PROCESS_NAME,
msg: `${ansiToHtml(command.result || '')}`,
command: `console> ${payload.command}<br>`,
result: command.result
}
]
});
},
failure: (error) => action(COMMANDS[FAILURE], {error})
};

View File

@ -96,7 +96,6 @@ class Console {
private registerApi() {
const plugin = this.plugins.createPlugin("consoleApi", {});
plugin.registerAPICall("post", "/embark-api/command", (req: any, res: any) => {
this.logger.info(`Cockpit> ${req.body.command}`.cyan);
this.executeCmd(req.body.command, (err: any, result: any) => {
if (err) {
return res.send({ result: err.message || err });
@ -104,10 +103,8 @@ class Console {
let response = result;
if (typeof result !== "string") {
response = stringify(result, utils.jsonFunctionReplacer, 2);
this.logger.info(response);
} else {
// Avoid HTML injection in the Cockpit
this.logger.info(response);
response = escapeHtml(response);
}
return res.send({ result: response });