1- import {
1+ import {
2+ CommandRequestData ,
3+ CommandRequestDataSchema ,
4+ CommandRequestResponseData ,
25 IpcMessageV2 ,
36 IpcMessageV2Schema ,
47 MessageCmd ,
58 PressKeyToContinueRequestData ,
69 PressKeyToContinueRequestDataSchema ,
7- SudoRequestData ,
8- SudoRequestDataSchema
910} from 'codify-schemas' ;
1011import { ChildProcess , fork } from 'node:child_process' ;
1112import { createRequire } from 'node:module' ;
@@ -16,7 +17,7 @@ import { sendIpcMessageForResult } from './message-sender.js';
1617import { PluginMessage } from './plugin-message.js' ;
1718
1819export const ipcMessageValidator = ajv . compile ( IpcMessageV2Schema ) ;
19- export const sudoRequestValidator = ajv . compile ( SudoRequestDataSchema ) ;
20+ export const commandRequestValidator = ajv . compile ( CommandRequestDataSchema ) ;
2021export const pressKeyToContinueRequestValidator = ajv . compile ( PressKeyToContinueRequestDataSchema ) ;
2122
2223const DEFAULT_NODE_MODULES_DIR = '/usr/local/lib/codify/node_modules/'
@@ -57,6 +58,7 @@ export class PluginProcess {
5758 } ,
5859 ) ;
5960
61+ // Note: stdin is not hooked up on purpose for security purposes. Interactive commands + sudo will have to run through the parent process.
6062 _process . stdout ! . on ( 'data' , ( message ) => ctx . pluginStdout ( name , message . toString ( 'utf8' ) ) ) ;
6163 _process . stderr ! . on ( 'data' , ( message ) => ctx . pluginStderr ( name , message . toString ( 'utf8' ) ) ) ;
6264 _process . on ( 'exit' , ( code ) => {
@@ -80,24 +82,24 @@ export class PluginProcess {
8082 throw new Error ( `Invalid message from plugin. ${ JSON . stringify ( message , null , 2 ) } ` ) ;
8183 }
8284
83- if ( message . cmd === MessageCmd . SUDO_REQUEST ) {
85+ if ( message . cmd === MessageCmd . COMMAND_REQUEST ) {
8486 const { data, requestId } = message ;
85- if ( ! sudoRequestValidator ( data ) ) {
86- throw new Error ( `Invalid sudo request from plugin ${ pluginName } . ${ JSON . stringify ( sudoRequestValidator . errors , null , 2 ) } ` ) ;
87+ if ( ! commandRequestValidator ( data ) ) {
88+ throw new Error ( `Invalid command request from plugin ${ pluginName } . ${ JSON . stringify ( commandRequestValidator . errors , null , 2 ) } ` ) ;
8789 }
8890
89- // Send out sudo granted events
90- ctx . once ( Event . SUDO_REQUEST_GRANTED , ( _pluginName , data ) => {
91+ // Send out command completed
92+ ctx . once ( Event . COMMAND_REQUEST_GRANTED , ( _pluginName , data ) => {
9193 if ( _pluginName === pluginName ) {
9294 process . send ( {
93- cmd : returnMessageCmd ( MessageCmd . SUDO_REQUEST ) ,
95+ cmd : returnMessageCmd ( MessageCmd . COMMAND_REQUEST ) ,
9496 requestId,
9597 data
9698 } )
9799 }
98100 } )
99101
100- return ctx . sudoRequested ( pluginName , data as unknown as SudoRequestData ) ;
102+ return ctx . commandRequested ( pluginName , data as unknown as CommandRequestData ) ;
101103 }
102104
103105 if ( message . cmd === MessageCmd . PRESS_KEY_TO_CONTINUE_REQUEST ) {
@@ -106,7 +108,6 @@ export class PluginProcess {
106108 throw new Error ( `Invalid press key to continue request from plugin ${ pluginName } . ${ JSON . stringify ( pressKeyToContinueRequestValidator . errors , null , 2 ) } ` ) ;
107109 }
108110
109- // Send out sudo granted events
110111 ctx . once ( Event . PRESS_KEY_TO_CONTINUE_COMPLETED , ( _pluginName ) => {
111112 if ( _pluginName === pluginName ) {
112113 process . send ( {
0 commit comments