Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gatewayd-io/gatewayd/logging"
"github.com/gatewayd-io/gatewayd/network"
"github.com/gatewayd-io/gatewayd/plugin"
"github.com/gatewayd-io/gatewayd/plugin/hook"
"github.com/gatewayd-io/gatewayd/pool"
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/yaml"
Expand All @@ -28,7 +29,7 @@ var (
)

var (
hooksConfig = plugin.NewHookConfig()
hooksConfig = hook.NewHookConfig()
DefaultLogger = logging.NewLogger(
logging.LoggerConfig{
Level: zerolog.DebugLevel,
Expand Down Expand Up @@ -108,7 +109,7 @@ var runCmd = &cobra.Command{
updatedGlobalConfig, err := hooksConfig.Run(
context.Background(),
globalConfig.All(),
plugin.OnConfigLoaded,
hook.OnConfigLoaded,
hooksConfig.Verification)
if err != nil {
DefaultLogger.Error().Err(err).Msg("Failed to run OnConfigLoaded hooks")
Expand Down Expand Up @@ -154,7 +155,7 @@ var runCmd = &cobra.Command{
}
// TODO: Use a context with a timeout
_, err = hooksConfig.Run(
context.Background(), data, plugin.OnNewLogger, hooksConfig.Verification)
context.Background(), data, hook.OnNewLogger, hooksConfig.Verification)
if err != nil {
logger.Error().Err(err).Msg("Failed to run OnNewLogger hooks")
}
Expand Down Expand Up @@ -185,7 +186,7 @@ var runCmd = &cobra.Command{
_, err := hooksConfig.Run(
context.Background(),
clientCfg,
plugin.OnNewClient,
hook.OnNewClient,
hooksConfig.Verification)
if err != nil {
logger.Error().Err(err).Msg("Failed to run OnNewClient hooks")
Expand Down Expand Up @@ -213,7 +214,7 @@ var runCmd = &cobra.Command{
_, err = hooksConfig.Run(
context.Background(),
map[string]interface{}{"size": poolSize},
plugin.OnNewPool,
hook.OnNewPool,
hooksConfig.Verification)
if err != nil {
logger.Error().Err(err).Msg("Failed to run OnNewPool hooks")
Expand All @@ -240,7 +241,7 @@ var runCmd = &cobra.Command{
},
}
_, err = hooksConfig.Run(
context.Background(), proxyCfg, plugin.OnNewProxy, hooksConfig.Verification)
context.Background(), proxyCfg, hook.OnNewProxy, hooksConfig.Verification)
if err != nil {
logger.Error().Err(err).Msg("Failed to run OnNewProxy hooks")
}
Expand Down Expand Up @@ -302,7 +303,7 @@ var runCmd = &cobra.Command{
"tcpNoDelay": gConfig.Server.TCPNoDelay,
}
_, err = hooksConfig.Run(
context.Background(), serverCfg, plugin.OnNewServer, hooksConfig.Verification)
context.Background(), serverCfg, hook.OnNewServer, hooksConfig.Verification)
if err != nil {
logger.Error().Err(err).Msg("Failed to run OnNewServer hooks")
}
Expand All @@ -320,15 +321,15 @@ var runCmd = &cobra.Command{
)
signalsCh := make(chan os.Signal, 1)
signal.Notify(signalsCh, signals...)
go func(hooksConfig *plugin.HookConfig) {
go func(hooksConfig *hook.Config) {
for sig := range signalsCh {
for _, s := range signals {
if sig != s {
// Notify the hooks that the server is shutting down.
_, err := hooksConfig.Run(
context.Background(),
map[string]interface{}{"signal": sig.String()},
plugin.OnSignal,
hook.OnSignal,
hooksConfig.Verification,
)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
ErrCodeCastFailed
ErrCodeHookVerificationFailed
ErrCodeHookReturnedError
ErrCodeHookTerminatedConnection
ErrCodeFileNotFound
ErrCodeFileOpenFailed
ErrCodeFileReadFailed
Expand Down Expand Up @@ -77,6 +78,8 @@ var (
ErrCodeHookVerificationFailed, "failed to verify hook", nil)
ErrHookReturnedError = NewGatewayDError(
ErrCodeHookReturnedError, "hook returned error", nil)
ErrHookTerminatedConnection = NewGatewayDError(
ErrCodeHookTerminatedConnection, "hook terminated connection", nil)

ErrFileNotFound = NewGatewayDError(
ErrCodeFileNotFound, "file not found", nil)
Expand Down
2 changes: 1 addition & 1 deletion gatewayd_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ plugins:
- MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN
- MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872
# Checksum hash to verify the binary before loading
checksum: 911cbab556bd3b14b60c088d786ae7c3ecf0a2aa2958406c3214ea64073cde36
checksum: 477dcbb41a27ff4431a5a9bc50754ef8c5a477b62d45d43e3b801b121aa96651
1 change: 1 addition & 0 deletions logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/rs/zerolog"
)

// TODO: Remove this once we have a proper hooks package.
// This is duplicated from the network package, because import cycles are not allowed.
type (
Signature map[string]interface{}
Expand Down
Loading