Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSandboxedVM ¶
NewSandboxedVM creates a new Lua VM with restricted libraries for security. Only safe libraries are loaded: base, table, string, and math. Dangerous functions like os, io, debug, loadfile, dofile are disabled. This function uses DefaultSandboxConfig() for backward compatibility.
func NewVM ¶ added in v1.11.0
func NewVM(config SandboxConfig) *lua.LState
NewVM creates a new Lua VM with the specified sandbox configuration. If config is nil, DefaultSandboxConfig() is used.
Types ¶
type ExecutionRecorder ¶
type ExecutionRecorder interface {
RecordExecution(ctx context.Context, result ExecutionResult) error
}
ExecutionRecorder allows recording execution results.
type ExecutionResult ¶
type ExecutionResult struct {
ScriptID string
ScriptName string
ScriptVersion string
Status ExecutionStatus
ErrorMessage *string
DurationMs int64
ExecutedAt time.Time
}
ExecutionResult represents the result of a script execution.
type ExecutionStatus ¶
type ExecutionStatus string
ExecutionStatus represents the status of an execution.
const ( ExecutionStatusSuccess ExecutionStatus = "success" ExecutionStatusFailure ExecutionStatus = "failure" )
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes Lua scripts with timeout, error handling, and result recording.
func NewExecutor ¶
func NewExecutor(config ExecutorConfig) *Executor
NewExecutor creates a new Lua script executor.
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, script Script, payload map[string]interface{}) ExecutionResult
Execute executes a Lua script with the given payload. The payload is converted to a Lua table and passed to the script's "handle" function. Returns an ExecutionResult with the outcome.
type ExecutorConfig ¶
type ExecutorConfig struct {
Timeout time.Duration
Logger *zap.Logger
HostFunctions HostFunctionRegistry
Recorder ExecutionRecorder
Sandbox *SandboxConfig // Optional: if nil, DefaultSandboxConfig() is used
}
ExecutorConfig holds configuration for the executor.
type HostFunctionRegistry ¶
type HostFunctionRegistry interface {
RegisterFunctions(L *lua.LState, scriptID, scriptName, scriptVersion string)
}
HostFunctionRegistry allows registering custom host functions for Lua scripts.
type SandboxConfig ¶ added in v1.11.0
type SandboxConfig struct {
// Libraries to enable/disable
EnableBase bool // Basic functions (print, type, etc.) - default: true
EnableTable bool // Table manipulation - default: true
EnableString bool // String manipulation - default: true
EnableMath bool // Math functions - default: true
EnableOS bool // OS functions (os.execute, os.exit, etc.) - default: false
EnableIO bool // IO functions (file operations) - default: false
EnableDebug bool // Debug functions - default: false
// Functions to disable (even if their library is enabled)
// These are dangerous functions that should typically be disabled
DisableDofile bool // Disable dofile() - default: true
DisableLoadfile bool // Disable loadfile() - default: true
DisableLoad bool // Disable load() - default: true
DisableLoadstring bool // Disable loadstring() - default: true
}
SandboxConfig configures which libraries and functions are available in the Lua VM. By default, only safe libraries are enabled (base, table, string, math). Dangerous functions (dofile, loadfile, load, loadstring) are disabled by default.
func DefaultSandboxConfig ¶ added in v1.11.0
func DefaultSandboxConfig() SandboxConfig
DefaultSandboxConfig returns a default sandbox configuration with strict security. Only safe libraries are enabled, and dangerous functions are disabled.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages concurrent execution with bounded concurrency.
func NewWorkerPool ¶
func NewWorkerPool(maxConcurrent int) *WorkerPool
NewWorkerPool creates a new worker pool with the specified max concurrent workers. If maxConcurrent <= 0, it defaults to 10.
func (*WorkerPool) Acquire ¶
func (p *WorkerPool) Acquire()
Acquire blocks until a worker slot is available.