pluginhooks

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

README

Plugin Hooks

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(pl Plugin)

Server starts the plugin, it should be called in the main() function. The following environment variables are required when using this function:

MagicCookieKey and value are used as a very basic verification that a plugin is intended to be launched. This is not a security measure, just a UX feature. If the magic cookie doesn't match, we show human-friendly output.

* MAGIC_COOKIE_KEY * MAGIC_COOKIE_VAL * PLUGIN_NAME * PLUGIN_VERSION (uint)

Serve will panic for unexpected conditions where a user's fix is unknown.

Types

type Empty

type Empty struct{}

type Plugin

type Plugin interface {
	// OnSessionOpen phase will initialize the configuration in memory
	// that could be used to other phases. The response will be used to mutate
	// the session params received.
	// Return an error in case any pre-condition doesn't match
	OnSessionOpen(*SesssionParams, *SessionParamsResponse) error
	// OnReceive phase process each received packet
	// the response object should be used to mutate the request packet or
	// returning an error and stopping processing further packets
	OnReceive(*Request, *Response) error
	// OnSend phase will trigger when a packet will be sent
	// to the client. The request will contain the packet and type
	// and the response could mutate the payload or return an error
	// if a condiction is not met.
	OnSend(*Request, *Response) error
}

type RPCPluginMethod

type RPCPluginMethod string

RPCPluginMethod is the name of the RPC method to be called. It must match exactly the name of methods in the Plugin interface

const (
	RPCPluginMethodOnSessionOpen RPCPluginMethod = "OnSessionOpen"
	RPCPluginMethodOnReceive     RPCPluginMethod = "OnReceive"
	RPCPluginMethodOnSend        RPCPluginMethod = "OnSend"
)

type Request

type Request struct {
	SessionID  string
	PacketType string
	Payload    []byte
}

type Response

type Response struct {
	// mutate | stop | log (default)
	Payload []byte
	Err     error
}

type SessionParamsResponse added in v0.0.6

type SessionParamsResponse struct {
	ConnectionEnvVars map[string]any
	ConnectionCommand []string
	ClientArgs        []string
}

type SesssionParams added in v0.0.6

type SesssionParams struct {
	SessionID         string
	UserID            string
	PluginEnvVars     map[string]string
	ConnectionName    string
	ConnectionType    string
	ConnectionEnvVars map[string]any
	ConnectionConfig  map[string]any
	ConnectionCommand []string
	ClientArgs        []string
	ClientVerb        string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL