GoRESTCmd is a straightforward web application that enables remote execution of shell commands through HTTP API requests. This web service offers multiple API endpoints for executing, monitoring the status, and retrieving output from executed commands.
- Execute shell commands remotely via HTTP API
- Retrieve the command output (stdout and stderr)
- Check the status of executed commands
- Limit concurrent command executions
- API key authentication
Create a config.json file in the root of the project with the following contents:
api_key: "your-api-key",
concurrent_limit: 5,
port: 8080,
server_tls: false
server_cert_path: server.cert
server_key_path: server.key
allowed_commands: ["echo", "ping", "ls", "mkdir"]
Replace your-api-key with the actual API key you want to use. You can also adjust the concurrent_limit and port settings.
- Go (1.20 or later)
To build and run the Remote Executor, execute the following commands in the project root:
go build -o gorestcmd main.go
./gorestcmd
The Remote Executor service will start and listen on the configured port (default: 8080).
Execute a shell command.
Request body:
{
"command": "your-command",
"args": ["arg1", "arg2", "arg3"]
}
Response:
Execution ID
Get the result of an executed command.
Response:
{
"stdout": "Command output",
"stderr": "Command error output",
"returnCode": 0,
"startTime": "2023-04-01T00:00:00Z",
"endTime": "2023-04-01T00:00:05Z",
"elapsed": "5s",
"status": "completed"
}
Get the stdout output of an executed command.
Response:
Command output
Get the stderr output of an executed command.
Response:
Command error output
Get a list of executed commands and their statuses.
Response:
{
"1": "completed",
"2": "running",
"3": "canceled"
}
Cancel a running command.
Response:
Execution canceled
To run the tests, execute the following command in the project root:
go test -v
This project is licensed under the MIT License