Documentation
¶
Index ¶
- Constants
- Variables
- func CommandFromArgv(selectedShell ShellName, argv []string) (string, error)
- func EffectiveEnv(overrides map[string]string) ([]string, error)
- func EffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
- func NormalizeBlockedCommand(s string) (string, error)
- func RejectDangerousCommand(cmd, shellPath string, shellName ShellName, ...) error
- func ValidateEnvMap(m map[string]string) error
- type SelectedShell
- type SessionStore
- type ShellCommandExecResult
- type ShellName
- type ShellSession
- func (sess *ShellSession) AddToEnv(additionalEnv map[string]string) error
- func (sess *ShellSession) GetEffectiveEnv(overrides map[string]string) ([]string, error)
- func (sess *ShellSession) GetEffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
- func (sess *ShellSession) GetEffectiveWorkdir(inputWorkDir, defaultWorkDir string) (string, error)
- func (sess *ShellSession) GetID() string
- func (sess *ShellSession) SetWorkDir(workdir string)
Constants ¶
const ( HardMaxTimeout = 10 * time.Minute HardMaxOutputBytes int64 = 4 * 1024 * 1024 // per stream HardMaxCommands = 64 HardMaxCommandLength = 64 * 1024 // bytes MinOutputBytes int64 = 1024 DefaultTimeout = 60 * time.Second DefaultMaxOutputBytes int64 = 256 * 1024 DefaultMaxCommands = 64 DefaultMaxCommandLength = 64 * 1024 )
Fixed, package-wide hard limits (single source of truth).
Variables ¶
var HardBlockedCommands = func() map[string]struct{} { hard := []string{ "sudo", "su", "rm", "mkfs", "shutdown", "reboot", "halt", "poweroff", "vim", "vi", "nano", "emacs", "less", "more", "top", "htop", "curl", "wget", "nc", "netcat", "ncat", "socat", "ssh", "scp", "sftp", "ftp", "tftp", "telnet", "invoke-webrequest", "iwr", "invoke-restmethod", "irm", "diskpart", "format.com", "del", "erase", "rmdir", "rd", "remove-item", "ri", } m := make(map[string]struct{}, len(hard)) for _, c := range hard { m[c] = struct{}{} } return m }()
Functions ¶
func CommandFromArgv ¶
CommandFromArgv builds a safely-quoted command string for ShellTool (which executes via shell "-c"/"-Command").
Why this exists: ShellTool accepts command strings; without a canonical helper, wrappers duplicate quoting and can accidentally introduce injection bugs. This keeps quoting logic centralized and consistent.
Supported dialects:
- sh-like shells (bash/zsh/sh/dash/ksh/fish): POSIX single-quote strategy
- PowerShell (pwsh/powershell): single-quote strategy + "&" call operator prefix
cmd.exe quoting is intentionally not supported here (too error-prone); pass a raw command string instead.
func EffectiveEnv ¶
EffectiveEnv returns the current process environment merged with overrides. It is equivalent to session-less ShellSession.GetEffectiveEnv.
func EffectiveEnvWithBase ¶ added in v0.14.0
EffectiveEnvWithBase returns the current process environment merged with base env and overrides.
func NormalizeBlockedCommand ¶
func RejectDangerousCommand ¶
func ValidateEnvMap ¶
Types ¶
type SelectedShell ¶
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
func NewSessionStore ¶
func NewSessionStore() *SessionStore
func (*SessionStore) Delete ¶
func (ss *SessionStore) Delete(id string)
func (*SessionStore) Get ¶
func (ss *SessionStore) Get(id string) (*ShellSession, bool)
func (*SessionStore) NewSession ¶
func (ss *SessionStore) NewSession() *ShellSession
func (*SessionStore) SetMaxSessions ¶
func (ss *SessionStore) SetMaxSessions(maxSessions int)
func (*SessionStore) SetTTL ¶
func (ss *SessionStore) SetTTL(ttl time.Duration)
func (*SessionStore) Size ¶
func (ss *SessionStore) Size() int
type ShellCommandExecResult ¶
type ShellCommandExecResult struct {
Command string `json:"command"`
WorkDir string `json:"workDir"`
Shell ShellName `json:"shell"`
ShellPath string `json:"shellPath"`
ExitCode int `json:"exitCode"`
TimedOut bool `json:"timedOut"`
DurationMS int64 `json:"durationMS"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
StdoutTruncated bool `json:"stdoutTruncated"`
StderrTruncated bool `json:"stderrTruncated"`
}
func RunOneShellCommand ¶
type ShellName ¶
type ShellName string
const ( ShellNameAuto ShellName = "auto" ShellNameBash ShellName = "bash" ShellNameZsh ShellName = "zsh" ShellNameSh ShellName = "sh" ShellNameDash ShellName = "dash" ShellNameKsh ShellName = "ksh" ShellNameFish ShellName = "fish" ShellNamePwsh ShellName = "pwsh" ShellNamePowershell ShellName = "powershell" ShellNameCmd ShellName = "cmd" )
type ShellSession ¶
type ShellSession struct {
// contains filtered or unexported fields
}
func (*ShellSession) AddToEnv ¶
func (sess *ShellSession) AddToEnv(additionalEnv map[string]string) error
func (*ShellSession) GetEffectiveEnv ¶
func (sess *ShellSession) GetEffectiveEnv(overrides map[string]string) ([]string, error)
func (*ShellSession) GetEffectiveEnvWithBase ¶ added in v0.14.0
func (sess *ShellSession) GetEffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
func (*ShellSession) GetEffectiveWorkdir ¶
func (sess *ShellSession) GetEffectiveWorkdir(inputWorkDir, defaultWorkDir string) (string, error)
func (*ShellSession) GetID ¶
func (sess *ShellSession) GetID() string
func (*ShellSession) SetWorkDir ¶
func (sess *ShellSession) SetWorkDir(workdir string)