* scripting: added service and controller for scripting * scripting: have got prompts working Scripts are now running in a separate go-routine. When a prompt is encountered, the script is paused and the user is prompted for input. This means that the script no longer needs to worry about synchronisation issues. * scripting: started working on the session methods * scripting: added methods to get items and attributes * scripting: have got loading of scripts working These act more like plugins and allow defining new commands. * scripting: have got script scheduling working Scripts are now executed on a dedicated goroutine and only one script can run at any one time. * scripting: added session.set_result_set(rs) * scripting: upgraded tamarin to 0.14 * scripting: started working on set_value * tamarin: replaced ad-hoc path with query expressions * scripting: changed value() and set_value() to attr() and set_attr() Also added 'delete_attr()' * scripting: added os.exec() This method is controlled by permissions which govern whether shellouts are allowed Also fixed a resizing bug with the status window which was not properly handling status messages with newlines * scripting: added the session.current_item() method * scripting: added placeholders to query expressions * scripting: added support for setting and deleteing items with placeholders Also refactored the dot AST type so that it support placeholders. Placeholders are not yet supported for subrefs yet, they need to be identifiers. * scripting: made setting the result-set push the current result-set to the backstack * scripting: started working on byte encoding of attribute values * scripting: finished attrcodec * scripting: integrated codec into expression * scripting: added equals and hashcode to queryexpr This finally finishes the work required to store queries in the backstack * scripting: fixed some bugs with the back-stack * scripting: upgraded Tamarin * scripting: removed some commented out code
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package scriptmanager
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
)
|
|
|
|
type Options struct {
|
|
// OSExecShell is the shell to use for calls to 'os.exec'. If not defined,
|
|
// it will use the value of the SHELL environment variable, otherwise it will
|
|
// default to '/bin/bash'
|
|
OSExecShell string
|
|
|
|
// Permissions are the permissions the script can execute in
|
|
Permissions Permissions
|
|
}
|
|
|
|
func (opts Options) configuredShell() string {
|
|
if opts.OSExecShell != "" {
|
|
return opts.OSExecShell
|
|
}
|
|
if shell, hasShell := os.LookupEnv("SHELL"); hasShell {
|
|
return shell
|
|
}
|
|
return "/bin/bash"
|
|
}
|
|
|
|
// Permissions control the set of permissions of a script
|
|
type Permissions struct {
|
|
// AllowShellCommands determines whether or not a script can execute shell commands.
|
|
AllowShellCommands bool
|
|
}
|
|
|
|
type optionCtxKeyType struct{}
|
|
|
|
var optionCtxKey = optionCtxKeyType{}
|
|
|
|
func optionFromCtx(ctx context.Context) Options {
|
|
perms, _ := ctx.Value(optionCtxKey).(Options)
|
|
return perms
|
|
}
|
|
|
|
func ctxWithOptions(ctx context.Context, perms Options) context.Context {
|
|
return context.WithValue(ctx, optionCtxKey, perms)
|
|
}
|