Documentation
¶
Overview ¶
Package exec contains the exec node implementation.
Index ¶
- type ExecConfig
- type ExecNode
- func (n *ExecNode) Activate(ctx context.Context) error
- func (n *ExecNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)
- func (n *ExecNode) SelectPorts(input, output nodestore.MessageInterface) []string
- func (n *ExecNode) Stop() error
- func (n *ExecNode) StopKey() string
- func (n *ExecNode) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecConfig ¶
type ExecConfig struct {
// Command is the base command line (trimmed). In buffered mode it
// runs through the shell; in spawn mode it is split into argv.
Command string `json:"command"`
// AddPay is the Node-RED "append msg.X" field: boolean true means
// "msg.payload", a string names another message property, and
// false/absent appends nothing. It is normalized into
// ExecNode.addpayProp at construction.
AddPay interface{} `json:"addpay"`
// Append holds extra arguments appended after the addpay value
// (trimmed).
Append string `json:"append"`
// UseSpawn selects spawn mode (stream stdout/stderr chunks to the
// first two outputs as they arrive). Node-RED serializes it as the
// string "true"/"false" — DecodeConfig coerces.
UseSpawn bool `json:"useSpawn"`
// Timer is a kill timeout in seconds (0 = no timeout).
Timer float64 `json:"timer"`
// OldRC selects the legacy third-output payload: the bare exit
// code instead of the {code:...} object. In buffered mode a
// successful run then emits nothing on the third output
// (Node-RED parity).
OldRC bool `json:"oldrc"`
}
ExecConfig holds configuration for the exec node — the Node-RED `exec` equivalent.
type ExecNode ¶
ExecNode runs a system command — the Node-RED `exec` node.
Outputs (Node-RED wiring order):
- output_1: stdout (a message per chunk in spawn mode, the whole buffer in exec mode)
- output_2: stderr (only emitted while the command produces stderr; spawn mode streams per chunk)
- output_3: the return code — {code:N} / {code:null,signal:...} / {code:N,message:"Command failed: ..."} unless oldrc, which emits the bare code (and in buffered mode nothing on success).
SECURITY: arbitrary command execution is gated behind NodeHost.ExecAllowed() — the node fails with "exec disabled" unless the flag is set (the consuming application wires it in main). The addpay value is concatenated into the command line exactly like Node-RED does, so even an enabled exec node is only as safe as the messages routed into it.
func NewExecNode ¶
func NewExecNode(node nodestore.NodeInterface, config *ExecConfig, host nodebase.NodeHost) *ExecNode
NewExecNode creates a new exec node
func (*ExecNode) Activate ¶ added in v0.7.0
Activate implements nodebase.Activator: the exec node is a Stopper (it must kill spawned children on undeploy) but activation is not a message run — it only resolves the shared process registry so Stop() can reach it later.
func (*ExecNode) Execute ¶
func (n *ExecNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)
Execute handles a message: a "kill" property signals the active process(es) and produces no output; otherwise the command runs — buffered through the shell (exec mode) or as a streamed spawn.
func (*ExecNode) SelectPorts ¶
func (n *ExecNode) SelectPorts(input, output nodestore.MessageInterface) []string
SelectPorts always routes the returned stdout message to output_1 — the stderr and return-code messages are emitted separately on their own ports.
func (*ExecNode) Stop ¶ added in v0.7.0
Stop implements nodebase.Stopper: kill every child process this node still has running (Node-RED kills activeProcesses on close).