Documentation ¶
Index ¶
- Constants
- Variables
- func SetDefaultScriptOutput()
- type Config
- type Error
- type GctScriptManager
- func (g *GctScriptManager) Autoload(name string, remove bool) error
- func (g *GctScriptManager) GetMaxVirtualMachines() uint8
- func (g *GctScriptManager) IsRunning() bool
- func (g *GctScriptManager) New() *VM
- func (g *GctScriptManager) NewVM() (vm *VM)
- func (g *GctScriptManager) RemoveVM(id uuid.UUID) error
- func (g *GctScriptManager) ShutdownAll() (err error)
- func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error)
- func (g *GctScriptManager) Stop() error
- func (g *GctScriptManager) Validate(file string) (err error)
- type VM
Constants ¶
const ( // DefaultTimeoutValue default timeout value for virtual machines DefaultTimeoutValue = 30 * time.Second // DefaultMaxVirtualMachines max number of virtual machines that can be loaded at one time DefaultMaxVirtualMachines uint8 = 10 // TypeLoad text to display in script_event table when a VM is loaded TypeLoad = "load" // TypeCreate text to display in script_event table when a VM is created TypeCreate = "create" // TypeExecute text to display in script_event table when a script is executed TypeExecute = "execute" // TypeStop text to display in script_event table when a running script is stopped TypeStop = "stop" // TypeRead text to display in script_event table when a script contents is read TypeRead = "read" // StatusSuccess text to display in script_event table on successful execution StatusSuccess = "success" // StatusFailure text to display in script_event table when script execution fails StatusFailure = "failure" )
const (
// ErrNoVMFound error returned when no virtual machine is found
ErrNoVMFound = "VM %v not found"
)
const (
// ErrScriptFailedValidation message to display when a script fails its validation
ErrScriptFailedValidation = "validation failed"
)
const (
// Name is an exported subsystem name
Name = "gctscript"
)
Variables ¶
var ( // ErrScriptingDisabled error message displayed when gctscript is disabled ErrScriptingDisabled = errors.New("scripting is disabled") // ErrNoVMLoaded error message displayed if a virtual machine has not been initialised ErrNoVMLoaded = errors.New("no virtual machine loaded") )
var ( // AllVMSync stores all current Virtual Machine instances AllVMSync = &sync.Map{} // VMSCount running total count of Virtual Machines VMSCount vmscount )
var ErrNilSubsystem = errors.New("gct script has not been set up")
var ( // ScriptPath path to load/save scripts ScriptPath string )
Functions ¶
func SetDefaultScriptOutput ¶
func SetDefaultScriptOutput()
SetDefaultScriptOutput sets default output file for scripts
Types ¶
type Config ¶
type Config struct { Enabled bool `json:"enabled"` ScriptTimeout time.Duration `json:"timeout"` MaxVirtualMachines uint8 `json:"max_virtual_machines"` AllowImports bool `json:"allow_imports"` AutoLoad []string `json:"auto_load"` Verbose bool `json:"verbose"` }
Config user configurable options for gctscript
type GctScriptManager ¶
type GctScriptManager struct { // Optional values to override stored config ('nil' if not overridden) MaxVirtualMachines *uint8 // contains filtered or unexported fields }
GctScriptManager loads and runs GCT Tengo scripts
func NewManager ¶
func NewManager(config *Config) (*GctScriptManager, error)
NewManager creates a new instance of script manager
func (*GctScriptManager) Autoload ¶
func (g *GctScriptManager) Autoload(name string, remove bool) error
Autoload remove entry from autoload slice
func (*GctScriptManager) GetMaxVirtualMachines ¶
func (g *GctScriptManager) GetMaxVirtualMachines() uint8
GetMaxVirtualMachines returns the max number of VMs to create
func (*GctScriptManager) IsRunning ¶
func (g *GctScriptManager) IsRunning() bool
IsRunning returns if gctscript manager subsystem is started
func (*GctScriptManager) New ¶
func (g *GctScriptManager) New() *VM
New returns a new instance of VM
func (*GctScriptManager) NewVM ¶
func (g *GctScriptManager) NewVM() (vm *VM)
NewVM attempts to create a new Virtual Machine firstly from pool
func (*GctScriptManager) RemoveVM ¶
func (g *GctScriptManager) RemoveVM(id uuid.UUID) error
RemoveVM remove VM from list
func (*GctScriptManager) ShutdownAll ¶
func (g *GctScriptManager) ShutdownAll() (err error)
ShutdownAll shutdown all
func (*GctScriptManager) Start ¶
func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error)
Start starts gctscript subsystem and creates shutdown channel
func (*GctScriptManager) Stop ¶
func (g *GctScriptManager) Stop() error
Stop stops gctscript subsystem along with all running Virtual Machines
func (*GctScriptManager) Validate ¶
func (g *GctScriptManager) Validate(file string) (err error)
Validate will attempt to execute a script in a test/non-live environment to confirm it passes requirements for execution
type VM ¶
type VM struct { ID uuid.UUID Hash string File string Path string Script *tengo.Script Compiled *tengo.Compiled T time.Duration NextRun time.Time S chan struct{} // contains filtered or unexported fields }
VM contains a pointer to "script" (precompiled source) and "compiled" (compiled byte code) instances
func (*VM) CompileAndRun ¶
func (vm *VM) CompileAndRun()
CompileAndRun Compile and Run script with support for task running