Documentation
¶
Overview ¶
Package plugin provides the plugin functionality for the CROWler.
Package plugin provides the plugin functionality for the CROWler.
Index ¶
- Constants
- Variables
- func LoadPluginsFromConfig(pluginRegistry *JSPluginRegister, config cfg.PluginConfig, pType string) error
- func NormalizeValues(value interface{}) interface{}
- type APIMetadata
- type EventSubscription
- type JSPlugin
- type JSPluginRegister
- func (reg *JSPluginRegister) GetPlugin(name string) (JSPlugin, bool)
- func (reg *JSPluginRegister) GetPluginsByAgentName(agentName string) ([]JSPlugin, bool)
- func (reg *JSPluginRegister) GetPluginsByEventType(eventType string) ([]JSPlugin, bool)
- func (reg *JSPluginRegister) LoadPluginsFromConfig(config *cfg.Config, pType string) *JSPluginRegister
- func (reg *JSPluginRegister) Register(name string, plugin JSPlugin)
- func (reg *JSPluginRegister) Remove(name string)
- type TestFile
- type TestOptions
- type TestResult
Constants ¶
const PlgTestHarness = `` /* 6264-byte string literal not displayed */
PlgTestHarness is the JavaScript code that provides the test harness for plugin unit tests
Variables ¶
var ErrPluginShuttingDown = fmt.Errorf("plugin is shutting down")
var ( // TestMode indicates whether the system is running in test mode TestMode = false )
Functions ¶
func LoadPluginsFromConfig ¶
func LoadPluginsFromConfig(pluginRegistry *JSPluginRegister, config cfg.PluginConfig, pType string) error
LoadPluginsFromConfig loads the plugins from the specified configuration.
func NormalizeValues ¶
func NormalizeValues(value interface{}) interface{}
NormalizeValues normalizes the values to be exported to JavaScript
Types ¶
type APIMetadata ¶ added in v1.1.0
type APIMetadata struct {
EndPoint string `json:"api_endpoint" yaml:"api_endpoint"` // API endpoint for the plugin
Methods []string `json:"api_methods" yaml:"api_methods"` // API method for the plugin
Auth string `json:"api_auth" yaml:"api_auth"` // API authentication: required, optional, none
AuthType string `json:"api_auth_type" yaml:"api_auth_type"` // API authentication type for the plugin: jwt, apikey
// OpenAPI spec for the plugin's API. This is optional but can be used to generate API documentation and client code.
OpenAPIQueryJSON string `json:"api_openapi_query_json,omitempty" yaml:"api_openapi_query_json,omitempty"`
OpenAPIRequestJSON string `json:"api_openapi_request_json,omitempty" yaml:"api_openapi_request_json,omitempty"`
OpenAPIResponseJSON string `json:"api_openapi_response_json,omitempty" yaml:"api_openapi_response_json,omitempty"`
OpenAPIHeadersJSON string `json:"api_openapi_headers_json,omitempty" yaml:"api_openapi_headers_json,omitempty"` // optional
}
APIMetadata struct to hold Plugins API metadata (for api_plugin type)
type EventSubscription ¶ added in v1.1.0
EventSubscription struct to hold the event subscription information
type JSPlugin ¶
type JSPlugin struct {
Name string `json:"name" yaml:"name"` // Name of the plugin
Description string `json:"description" yaml:"description"` // Description of the plugin
Version string `json:"version" yaml:"version"` // Version of the plugin
PType string `json:"type" yaml:"type"` // Type of the plugin
Async bool `json:"async" yaml:"async"` // Is the plugin asynchronous
Script string `json:"script" yaml:"script"` // Script for the plugin
EventType string `json:"event_type" yaml:"event_type"` // Event type for the plugin. Plugins can register to handle an event.
API *APIMetadata `json:"api_metadata,omitempty" yaml:"api_metadata,omitempty"` // API metadata for api_plugin type
InRegisters []*JSPluginRegister
}
JSPlugin struct to hold the JS plugin
func BulkLoadPlugins ¶
func BulkLoadPlugins(config cfg.PluginConfig, pType string) ([]*JSPlugin, error)
BulkLoadPlugins loads the plugins from the specified file and returns a pointer to the created JSPlugin.
func LoadPluginFromLocal ¶
LoadPluginFromLocal loads the plugin from the specified file and returns a pointer to the created JSPlugin.
func LoadPluginsFromRemote ¶
func LoadPluginsFromRemote(config cfg.PluginConfig) ([]*JSPlugin, error)
LoadPluginsFromRemote loads plugins from a distribution server either on the local net or the internet.
type JSPluginRegister ¶
type JSPluginRegister struct {
Registry map[string]JSPlugin // Registry of JS plugins
Order []string // Order of the plugins in registration order
}
JSPluginRegister struct to hold the JS plugins
func NewJSPluginRegister ¶
func NewJSPluginRegister() *JSPluginRegister
NewJSPluginRegister returns a new JSPluginRegister
func (*JSPluginRegister) GetPlugin ¶
func (reg *JSPluginRegister) GetPlugin(name string) (JSPlugin, bool)
GetPlugin returns a JS plugin
func (*JSPluginRegister) GetPluginsByAgentName ¶
func (reg *JSPluginRegister) GetPluginsByAgentName(agentName string) ([]JSPlugin, bool)
GetPluginsByAgentName returns a list of JS plugins related to the specified agent name
func (*JSPluginRegister) GetPluginsByEventType ¶
func (reg *JSPluginRegister) GetPluginsByEventType(eventType string) ([]JSPlugin, bool)
GetPluginsByEventType returns a list of JS plugins to handle an event type
func (*JSPluginRegister) LoadPluginsFromConfig ¶
func (reg *JSPluginRegister) LoadPluginsFromConfig(config *cfg.Config, pType string) *JSPluginRegister
LoadPluginsFromConfig loads the plugins from the specified configuration.
func (*JSPluginRegister) Register ¶
func (reg *JSPluginRegister) Register(name string, plugin JSPlugin)
Register registers a new JS plugin
func (*JSPluginRegister) Remove ¶
func (reg *JSPluginRegister) Remove(name string)
Remove removes a registered plugin from the registry
type TestFile ¶ added in v1.1.0
type TestFile struct {
// Path is the original path to the test file, used for debugging and error messages
Path string
// Name is the test name, parsed from the first non-empty line of the file, expected to be in the format: // name: <test name>
Name string // parsed from first non-empty line: // name: ...
// Body is the content of the test file, which should be a JavaScript code string containing calls to the test harness functions (test(), assertEqual(), etc.)
Body string
}
TestFile represent a plugin's test file
func DiscoverTestsFromPlugins ¶ added in v1.1.0
func DiscoverTestsFromPlugins(reg *JSPluginRegister) []TestFile
DiscoverTestsFromPlugins discovers test functions from the registered test plugins
type TestOptions ¶ added in v1.1.0
type TestOptions struct {
// Timeout is the maximum execution time for the test in seconds. If the test exceeds this time, it will be terminated and marked as failed due to timeout.
Timeout int
// Params is a map of parameters to be passed to the plugin during test execution. These parameters will be available in the plugin's JavaScript code as a global variable named `params`.
Params map[string]any
}
TestOptions represents the options for executing a plugin test
type TestResult ¶ added in v1.1.0
type TestResult struct {
// Name is the name of the test, as defined in the test file (parsed from the first non-empty line in the format: // name: <test name>)
Name string
// Passed indicates whether the test passed or failed. A test is considered passed if all assertions in the test code succeeded without throwing exceptions and the execution completed within the specified timeout.
Passed bool
// Error contains the error message if the test failed. This could be due to an assertion failure, an uncaught exception in the test code, or a timeout. If the test passed successfully, this field will be empty.
Error string
}
TestResult represents the result of a plugin test
func ExecEnginePluginTest ¶ added in v1.1.0
func ExecEnginePluginTest( p *JSPlugin, testScript string, db *cdb.Handler, opts TestOptions, ) ([]TestResult, error)
ExecEnginePluginTest executes the specified engine plugin test script