Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConnectionClosed = errors.New("connection closed") ErrCommandNotAllowed = errors.New("command not allowed") ErrArgumentNotAllowed = errors.New("argument not allowed") )
View Source
var ErrMalformedRequest = errors.New("malformed request")
Functions ¶
Types ¶
type AllowedCommand ¶
type AllowedCommand struct{}
AllowedCommand is a command that the runner is allowed to run.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a socket client to make requests to a command socket server.
type Command ¶
type Command struct {
Path string `json:"path,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
WorkingDir string `json:"working_dir,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
}
Command to run.
type HandlerOption ¶
type HandlerOption func(*handlerConfig)
HandlerOption sets options on the handler.
func WithLogger ¶
func WithLogger(logger *slog.Logger) HandlerOption
WithLogger sets logger on the handler:
type Output ¶
type Output struct {
Type OutputType `json:"type"`
Data string `json:"data,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
Error string `json:"error,omitempty"`
}
Output from command.
type OutputType ¶
type OutputType string
OutputType is the type of output to write to the writer.
const ( OutputStdout OutputType = "stdout" OutputStderr OutputType = "stderr" OutputResult OutputType = "result" OutputError OutputType = "error" )
type Request ¶
type Request struct {
RequestID string `json:"request_id,omitempty"`
ClientID string `json:"client_id"`
Command Command `json:"command"`
}
Request for the command.
type Response ¶
type Response struct {
RequestID string `json:"request_id"`
ClientID string `json:"client_id"`
Output Output `json:"output"`
Error string `json:"error,omitempty"`
}
Response with the results from the command.
type Runner ¶
type Runner interface {
// Run command.
Run(ctx context.Context, w io.Writer, command Command) error
}
Runner runs the provided command (path to binary, arguments, etc.)
func NewRunner ¶
func NewRunner(options ...RunnerOption) Runner
NewRunner creates and returns a new runner.
type RunnerOption ¶
type RunnerOption func(r *runner)
RunnerOption sets options on the runner.
func WithAllowedCommands ¶
func WithAllowedCommands(commands map[string]AllowedCommand) RunnerOption
WithAllowedCommands sets commands that the runner are allowed to run.
func WithWorkspaceRoot ¶
func WithWorkspaceRoot(root string) RunnerOption
WithWorkspaceRoot sets the workspace root for the runner.
Click to show internal directories.
Click to hide internal directories.