mirror of
https://github.com/safing/portbase
synced 2025-09-04 11:40:23 +00:00
Add api for injecting events
This commit is contained in:
parent
400f4c12ed
commit
a41ea62d2d
1 changed files with 36 additions and 0 deletions
36
api/endpoints_modules.go
Normal file
36
api/endpoints_modules.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func registerModulesEndpoints() error {
|
||||||
|
if err := RegisterEndpoint(Endpoint{
|
||||||
|
Path: "modules/{moduleName:.+}/trigger/{eventName:.+}",
|
||||||
|
Write: PermitSelf,
|
||||||
|
ActionFunc: triggerEvent,
|
||||||
|
Name: "Export Configuration Options",
|
||||||
|
Description: "Returns a list of all registered configuration options and their metadata. This does not include the current active or default settings.",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func triggerEvent(ar *Request) (msg string, err error) {
|
||||||
|
// Get parameters.
|
||||||
|
moduleName := ar.URLVars["moduleName"]
|
||||||
|
eventName := ar.URLVars["eventName"]
|
||||||
|
if moduleName == "" || eventName == "" {
|
||||||
|
return "", errors.New("invalid parameters")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject event.
|
||||||
|
if err := module.InjectEvent("api event injection", moduleName, eventName, nil); err != nil {
|
||||||
|
return "", fmt.Errorf("failed to inject event: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "event successfully injected", nil
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue