From c29ea7bf0e82cd7f3640a701df2c357d81b612db Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 8 Jan 2023 17:19:19 +0100 Subject: [PATCH 01/15] Move hook types to a nested package under plugin to avoid cyclic imports --- plugin/hook/types.go | 18 +++++++++++ plugin/hooks.go | 68 +++++++++++++++++---------------------- plugin/hooks_test.go | 3 +- plugin/plugin.go | 5 +-- plugin/plugin_registry.go | 15 +++++---- 5 files changed, 61 insertions(+), 48 deletions(-) create mode 100644 plugin/hook/types.go diff --git a/plugin/hook/types.go b/plugin/hook/types.go new file mode 100644 index 00000000..eb157db4 --- /dev/null +++ b/plugin/hook/types.go @@ -0,0 +1,18 @@ +package hook + +import ( + "context" + + "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/structpb" +) + +type ( + // Priority is the priority of a hook. + // Smaller values are executed first (higher priority). + Priority uint + HookType string + HookDef func( + context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error) + Component string +) diff --git a/plugin/hooks.go b/plugin/hooks.go index d5301dfb..9ac7a1e8 100644 --- a/plugin/hooks.go +++ b/plugin/hooks.go @@ -6,47 +6,39 @@ import ( "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/rs/zerolog" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/structpb" ) -type ( - // Priority is the priority of a hook. - // Smaller values are executed first (higher priority). - Priority uint - HookType string - HookDef func( - context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error) -) - const ( // Run command hooks (cmd/run.go). - OnConfigLoaded HookType = "onConfigLoaded" - OnNewLogger HookType = "onNewLogger" - OnNewPool HookType = "onNewPool" - OnNewProxy HookType = "onNewProxy" - OnNewServer HookType = "onNewServer" - OnSignal HookType = "onSignal" + OnConfigLoaded hook.HookType = "onConfigLoaded" + OnNewLogger hook.HookType = "onNewLogger" + OnNewPool hook.HookType = "onNewPool" + OnNewProxy hook.HookType = "onNewProxy" + OnNewServer hook.HookType = "onNewServer" + OnSignal hook.HookType = "onSignal" // Server hooks (network/server.go). - OnRun HookType = "onRun" - OnBooting HookType = "onBooting" - OnBooted HookType = "onBooted" - OnOpening HookType = "onOpening" - OnOpened HookType = "onOpened" - OnClosing HookType = "onClosing" - OnClosed HookType = "onClosed" - OnTraffic HookType = "onTraffic" - OnIngressTraffic HookType = "onIngressTraffic" - OnEgressTraffic HookType = "onEgressTraffic" - OnShutdown HookType = "onShutdown" - OnTick HookType = "onTick" + OnRun hook.HookType = "onRun" + OnBooting hook.HookType = "onBooting" + OnBooted hook.HookType = "onBooted" + OnOpening hook.HookType = "onOpening" + OnOpened hook.HookType = "onOpened" + OnClosing hook.HookType = "onClosing" + OnClosed hook.HookType = "onClosed" + OnTraffic hook.HookType = "onTraffic" + OnIngressTraffic hook.HookType = "onIngressTraffic" + OnEgressTraffic hook.HookType = "onEgressTraffic" + OnShutdown hook.HookType = "onShutdown" + OnTick hook.HookType = "onTick" // Pool hooks (network/pool.go). - OnNewClient HookType = "onNewClient" + OnNewClient hook.HookType = "onNewClient" ) type HookConfig struct { - hooks map[HookType]map[Priority]HookDef + hooks map[hook.HookType]map[hook.Priority]hook.HookDef Logger zerolog.Logger Verification config.Policy } @@ -54,19 +46,19 @@ type HookConfig struct { // NewHookConfig returns a new HookConfig. func NewHookConfig() *HookConfig { return &HookConfig{ - hooks: map[HookType]map[Priority]HookDef{}, + hooks: map[hook.HookType]map[hook.Priority]hook.HookDef{}, } } // Hooks returns the hooks. -func (h *HookConfig) Hooks() map[HookType]map[Priority]HookDef { +func (h *HookConfig) Hooks() map[hook.HookType]map[hook.Priority]hook.HookDef { return h.hooks } // Add adds a hook with a priority to the hooks map. -func (h *HookConfig) Add(hookType HookType, prio Priority, hook HookDef) { +func (h *HookConfig) Add(hookType hook.HookType, prio hook.Priority, hookFunc hook.HookDef) { if len(h.hooks[hookType]) == 0 { - h.hooks[hookType] = map[Priority]HookDef{prio: hook} + h.hooks[hookType] = map[hook.Priority]hook.HookDef{prio: hookFunc} } else { if _, ok := h.hooks[hookType][prio]; ok { h.Logger.Warn().Fields( @@ -76,12 +68,12 @@ func (h *HookConfig) Add(hookType HookType, prio Priority, hook HookDef) { }, ).Msg("Hook is replaced") } - h.hooks[hookType][prio] = hook + h.hooks[hookType][prio] = hookFunc } } // Get returns the hooks of a specific type. -func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef { +func (h *HookConfig) Get(hookType hook.HookType) map[hook.Priority]hook.HookDef { return h.hooks[hookType] } @@ -102,7 +94,7 @@ func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef { func (h *HookConfig) Run( ctx context.Context, args map[string]interface{}, - hookType HookType, + hookType hook.HookType, verification config.Policy, opts ...grpc.CallOption, ) (map[string]interface{}, *gerr.GatewayDError) { @@ -128,7 +120,7 @@ func (h *HookConfig) Run( } // Sort hooks by priority. - priorities := make([]Priority, 0, len(h.hooks[hookType])) + priorities := make([]hook.Priority, 0, len(h.hooks[hookType])) for prio := range h.hooks[hookType] { priorities = append(priorities, prio) } @@ -138,7 +130,7 @@ func (h *HookConfig) Run( // Run hooks, passing the result of the previous hook to the next one. returnVal := &structpb.Struct{} - var removeList []Priority + var removeList []hook.Priority // The signature of parameters and args MUST be the same for this to work. for idx, prio := range priorities { var result *structpb.Struct diff --git a/plugin/hooks_test.go b/plugin/hooks_test.go index 65149c67..79c00ae0 100644 --- a/plugin/hooks_test.go +++ b/plugin/hooks_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/gatewayd-io/gatewayd/config" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/structpb" @@ -62,7 +63,7 @@ func Test_HookConfig_Get(t *testing.T) { ) (*structpb.Struct, error) { return args, nil } - prio := Priority(0) + prio := hook.Priority(0) hooks.Add(OnNewLogger, prio, testFunc) assert.NotNil(t, hooks.Get(OnNewLogger)) assert.ObjectsAreEqual(testFunc, hooks.Get(OnNewLogger)[prio]) diff --git a/plugin/plugin.go b/plugin/plugin.go index 97a78906..6df7b78c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -4,6 +4,7 @@ import ( "net" gerr "github.com/gatewayd-io/gatewayd/errors" + "github.com/gatewayd-io/gatewayd/plugin/hook" pluginV1 "github.com/gatewayd-io/gatewayd/plugin/v1" goplugin "github.com/hashicorp/go-plugin" ) @@ -39,8 +40,8 @@ type Plugin struct { // internal and external config options Config map[string]string // hooks it attaches to - Hooks []HookType - Priority Priority + Hooks []hook.HookType + Priority hook.Priority // required plugins to be loaded before this one // Built-in plugins are always loaded first Requires []Identifier diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 4e5afce2..2878bc34 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -7,6 +7,7 @@ import ( "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" "github.com/gatewayd-io/gatewayd/logging" + "github.com/gatewayd-io/gatewayd/plugin/hook" pluginV1 "github.com/gatewayd-io/gatewayd/plugin/v1" "github.com/gatewayd-io/gatewayd/pool" goplugin "github.com/hashicorp/go-plugin" @@ -191,7 +192,7 @@ func (reg *PluginRegistry) LoadPlugins(plugins []config.Plugin) { // in the config file. Built-in plugins are loaded first, followed by user-defined // plugins. Built-in plugins have a priority of 0 to 999, and user-defined plugins // have a priority of 1000 or greater. - plugin.Priority = Priority(config.PluginPriorityStart + uint(priority)) + plugin.Priority = hook.Priority(config.PluginPriorityStart + uint(priority)) logAdapter := logging.NewHcLogAdapter(®.hooksConfig.Logger, config.LoggerName) @@ -326,9 +327,9 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { return } - for _, hook := range pluginImpl.Hooks { - var hookFunc HookDef - switch hook { + for _, hookType := range pluginImpl.Hooks { + var hookFunc hook.HookDef + switch hookType { case OnConfigLoaded: hookFunc = pluginV1.OnConfigLoaded case OnNewLogger: @@ -368,10 +369,10 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { case OnNewClient: hookFunc = pluginV1.OnNewClient default: - reg.hooksConfig.Logger.Warn().Str("hook", string(hook)).Msg("Unknown hook type") + reg.hooksConfig.Logger.Warn().Str("hook", string(hookType)).Msg("Unknown hook type") continue } - reg.hooksConfig.Logger.Debug().Str("hook", string(hook)).Msg("Registering hook") - reg.hooksConfig.Add(hook, pluginImpl.Priority, hookFunc) + reg.hooksConfig.Logger.Debug().Str("hook", string(hookType)).Msg("Registering hook") + reg.hooksConfig.Add(hookType, pluginImpl.Priority, hookFunc) } } From de1509f203bb6d41f88d25c25e724ed66bde15b3 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 8 Jan 2023 17:43:13 +0100 Subject: [PATCH 02/15] Move hooks* and utils to a nested package under plugin/hook --- cmd/run.go | 19 ++--- logging/logger.go | 1 + network/proxy.go | 10 +-- network/proxy_test.go | 6 +- network/server.go | 26 +++---- network/server_test.go | 8 +-- plugin/{ => hook}/hooks.go | 72 +++++++++---------- plugin/{ => hook}/hooks_test.go | 11 ++- plugin/hook/types.go | 1 - plugin/plugin_registry.go | 47 ++++++------ plugin/plugin_registry_test.go | 3 +- plugin/{utils.go => utils/functions.go} | 6 +- .../functions_test.go} | 6 +- 13 files changed, 109 insertions(+), 107 deletions(-) rename plugin/{ => hook}/hooks.go (74%) rename plugin/{ => hook}/hooks_test.go (98%) rename plugin/{utils.go => utils/functions.go} (93%) rename plugin/{utils_test.go => utils/functions_test.go} (94%) diff --git a/cmd/run.go b/cmd/run.go index 49edee4f..2acc29f8 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -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" @@ -28,7 +29,7 @@ var ( ) var ( - hooksConfig = plugin.NewHookConfig() + hooksConfig = hook.NewHookConfig() DefaultLogger = logging.NewLogger( logging.LoggerConfig{ Level: zerolog.DebugLevel, @@ -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") @@ -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") } @@ -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") @@ -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") @@ -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") } @@ -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") } @@ -320,7 +321,7 @@ var runCmd = &cobra.Command{ ) signalsCh := make(chan os.Signal, 1) signal.Notify(signalsCh, signals...) - go func(hooksConfig *plugin.HookConfig) { + go func(hooksConfig *hook.HookConfig) { for sig := range signalsCh { for _, s := range signals { if sig != s { @@ -328,7 +329,7 @@ var runCmd = &cobra.Command{ _, err := hooksConfig.Run( context.Background(), map[string]interface{}{"signal": sig.String()}, - plugin.OnSignal, + hook.OnSignal, hooksConfig.Verification, ) if err != nil { diff --git a/logging/logger.go b/logging/logger.go index 2d1953a9..c3dd9c91 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -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{} diff --git a/network/proxy.go b/network/proxy.go index 286a7153..f9dbfba2 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -5,7 +5,7 @@ import ( "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" - "github.com/gatewayd-io/gatewayd/plugin" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/gatewayd-io/gatewayd/pool" "github.com/panjf2000/gnet/v2" "github.com/rs/zerolog" @@ -24,7 +24,7 @@ type Proxy struct { availableConnections pool.IPool busyConnections pool.IPool logger zerolog.Logger - hookConfig *plugin.HookConfig + hookConfig *hook.HookConfig Elastic bool ReuseElasticClients bool @@ -37,7 +37,7 @@ var _ IProxy = &Proxy{} // NewProxy creates a new proxy. func NewProxy( - p pool.IPool, hookConfig *plugin.HookConfig, + p pool.IPool, hookConfig *hook.HookConfig, elastic, reuseElasticClients bool, clientConfig *config.Client, logger zerolog.Logger, ) *Proxy { @@ -201,7 +201,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { result, err := pr.hookConfig.Run( context.Background(), trafficData(gconn, client, "request", request, origErr), - plugin.OnIngressTraffic, + hook.OnIngressTraffic, pr.hookConfig.Verification) if err != nil { pr.logger.Error().Err(err).Msg("Error running hook") @@ -277,7 +277,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { result, err = pr.hookConfig.Run( context.Background(), trafficData(gconn, client, "response", response[:received], err), - plugin.OnEgressTraffic, + hook.OnEgressTraffic, pr.hookConfig.Verification) if err != nil { pr.logger.Error().Err(err).Msg("Error running hook") diff --git a/network/proxy_test.go b/network/proxy_test.go index 043fe7c0..639a1649 100644 --- a/network/proxy_test.go +++ b/network/proxy_test.go @@ -6,7 +6,7 @@ import ( embeddedpostgres "github.com/fergusstrange/embedded-postgres" "github.com/gatewayd-io/gatewayd/config" "github.com/gatewayd-io/gatewayd/logging" - "github.com/gatewayd-io/gatewayd/plugin" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/gatewayd-io/gatewayd/pool" "github.com/rs/zerolog" "github.com/stretchr/testify/assert" @@ -52,7 +52,7 @@ func TestNewProxy(t *testing.T) { assert.Nil(t, err) // Create a proxy with a fixed buffer pool - proxy := NewProxy(pool, plugin.NewHookConfig(), false, false, nil, logger) + proxy := NewProxy(pool, hook.NewHookConfig(), false, false, nil, logger) assert.NotNil(t, proxy) assert.Equal(t, 0, proxy.busyConnections.Size(), "Proxy should have no connected clients") @@ -81,7 +81,7 @@ func TestNewProxyElastic(t *testing.T) { pool := pool.NewPool(config.EmptyPoolCapacity) // Create a proxy with an elastic buffer pool - proxy := NewProxy(pool, plugin.NewHookConfig(), true, false, &config.Client{ + proxy := NewProxy(pool, hook.NewHookConfig(), true, false, &config.Client{ Network: "tcp", Address: "localhost:5432", ReceiveBufferSize: config.DefaultBufferSize, diff --git a/network/server.go b/network/server.go index b3b2d950..59ba1044 100644 --- a/network/server.go +++ b/network/server.go @@ -10,7 +10,7 @@ import ( "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" - "github.com/gatewayd-io/gatewayd/plugin" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/panjf2000/gnet/v2" "github.com/rs/zerolog" ) @@ -20,7 +20,7 @@ type Server struct { engine gnet.Engine proxy IProxy logger zerolog.Logger - hooksConfig *plugin.HookConfig + hooksConfig *hook.HookConfig Network string // tcp/udp/unix Address string @@ -41,7 +41,7 @@ func (s *Server) OnBoot(engine gnet.Engine) gnet.Action { _, err := s.hooksConfig.Run( context.Background(), map[string]interface{}{"status": fmt.Sprint(s.Status)}, - plugin.OnBooting, + hook.OnBooting, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnBooting hook") @@ -56,7 +56,7 @@ func (s *Server) OnBoot(engine gnet.Engine) gnet.Action { _, err = s.hooksConfig.Run( context.Background(), map[string]interface{}{"status": fmt.Sprint(s.Status)}, - plugin.OnBooted, + hook.OnBooted, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnBooted hook") @@ -81,7 +81,7 @@ func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action) { }, } _, err := s.hooksConfig.Run( - context.Background(), onOpeningData, plugin.OnOpening, s.hooksConfig.Verification) + context.Background(), onOpeningData, hook.OnOpening, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnOpening hook") } @@ -122,7 +122,7 @@ func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action) { }, } _, err = s.hooksConfig.Run( - context.Background(), onOpenedData, plugin.OnOpened, s.hooksConfig.Verification) + context.Background(), onOpenedData, hook.OnOpened, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnOpened hook") } @@ -149,7 +149,7 @@ func (s *Server) OnClose(gconn gnet.Conn, err error) gnet.Action { data["error"] = err.Error() } _, gatewaydErr := s.hooksConfig.Run( - context.Background(), data, plugin.OnClosing, s.hooksConfig.Verification) + context.Background(), data, hook.OnClosing, s.hooksConfig.Verification) if gatewaydErr != nil { s.logger.Error().Err(gatewaydErr).Msg("Failed to run OnClosing hook") } @@ -180,7 +180,7 @@ func (s *Server) OnClose(gconn gnet.Conn, err error) gnet.Action { data["error"] = err.Error() } _, gatewaydErr = s.hooksConfig.Run( - context.Background(), data, plugin.OnClosed, s.hooksConfig.Verification) + context.Background(), data, hook.OnClosed, s.hooksConfig.Verification) if gatewaydErr != nil { s.logger.Error().Err(gatewaydErr).Msg("Failed to run OnClosed hook") } @@ -199,7 +199,7 @@ func (s *Server) OnTraffic(gconn gnet.Conn) gnet.Action { }, } _, err := s.hooksConfig.Run( - context.Background(), onTrafficData, plugin.OnTraffic, s.hooksConfig.Verification) + context.Background(), onTrafficData, hook.OnTraffic, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnTraffic hook") } @@ -233,7 +233,7 @@ func (s *Server) OnShutdown(engine gnet.Engine) { _, err := s.hooksConfig.Run( context.Background(), map[string]interface{}{"connections": s.engine.CountConnections()}, - plugin.OnShutdown, + hook.OnShutdown, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnShutdown hook") @@ -256,7 +256,7 @@ func (s *Server) OnTick() (time.Duration, gnet.Action) { _, err := s.hooksConfig.Run( context.Background(), map[string]interface{}{"connections": s.engine.CountConnections()}, - plugin.OnTick, + hook.OnTick, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run OnTick hook") @@ -284,7 +284,7 @@ func (s *Server) Run() error { onRunData["error"] = err.OriginalError.Error() } result, err := s.hooksConfig.Run( - context.Background(), onRunData, plugin.OnRun, s.hooksConfig.Verification) + context.Background(), onRunData, hook.OnRun, s.hooksConfig.Verification) if err != nil { s.logger.Error().Err(err).Msg("Failed to run the hook") } @@ -333,7 +333,7 @@ func NewServer( options []gnet.Option, proxy IProxy, logger zerolog.Logger, - hooksConfig *plugin.HookConfig, + hooksConfig *hook.HookConfig, ) *Server { // Create the server. server := Server{ diff --git a/network/server_test.go b/network/server_test.go index 535db499..5028527f 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -9,7 +9,7 @@ import ( embeddedpostgres "github.com/fergusstrange/embedded-postgres" "github.com/gatewayd-io/gatewayd/config" "github.com/gatewayd-io/gatewayd/logging" - "github.com/gatewayd-io/gatewayd/plugin" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/gatewayd-io/gatewayd/pool" "github.com/panjf2000/gnet/v2" "github.com/rs/zerolog" @@ -39,7 +39,7 @@ func TestRunServer(t *testing.T) { logger := logging.NewLogger(cfg) - hooksConfig := plugin.NewHookConfig() + hooksConfig := hook.NewHookConfig() onIngressTraffic := func( ctx context.Context, @@ -67,7 +67,7 @@ func TestRunServer(t *testing.T) { assert.Empty(t, paramsMap["error"]) return params, nil } - hooksConfig.Add(plugin.OnIngressTraffic, 1, onIngressTraffic) + hooksConfig.Add(hook.OnIngressTraffic, 1, onIngressTraffic) onEgressTraffic := func( ctx context.Context, @@ -92,7 +92,7 @@ func TestRunServer(t *testing.T) { assert.Empty(t, paramsMap["error"]) return params, nil } - hooksConfig.Add(plugin.OnEgressTraffic, 1, onEgressTraffic) + hooksConfig.Add(hook.OnEgressTraffic, 1, onEgressTraffic) clientConfig := config.Client{ Network: "tcp", diff --git a/plugin/hooks.go b/plugin/hook/hooks.go similarity index 74% rename from plugin/hooks.go rename to plugin/hook/hooks.go index 9ac7a1e8..c1b935c1 100644 --- a/plugin/hooks.go +++ b/plugin/hook/hooks.go @@ -1,4 +1,4 @@ -package plugin +package hook import ( "context" @@ -6,7 +6,7 @@ import ( "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" - "github.com/gatewayd-io/gatewayd/plugin/hook" + "github.com/gatewayd-io/gatewayd/plugin/utils" "github.com/rs/zerolog" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/structpb" @@ -14,31 +14,31 @@ import ( const ( // Run command hooks (cmd/run.go). - OnConfigLoaded hook.HookType = "onConfigLoaded" - OnNewLogger hook.HookType = "onNewLogger" - OnNewPool hook.HookType = "onNewPool" - OnNewProxy hook.HookType = "onNewProxy" - OnNewServer hook.HookType = "onNewServer" - OnSignal hook.HookType = "onSignal" + OnConfigLoaded HookType = "onConfigLoaded" + OnNewLogger HookType = "onNewLogger" + OnNewPool HookType = "onNewPool" + OnNewProxy HookType = "onNewProxy" + OnNewServer HookType = "onNewServer" + OnSignal HookType = "onSignal" // Server hooks (network/server.go). - OnRun hook.HookType = "onRun" - OnBooting hook.HookType = "onBooting" - OnBooted hook.HookType = "onBooted" - OnOpening hook.HookType = "onOpening" - OnOpened hook.HookType = "onOpened" - OnClosing hook.HookType = "onClosing" - OnClosed hook.HookType = "onClosed" - OnTraffic hook.HookType = "onTraffic" - OnIngressTraffic hook.HookType = "onIngressTraffic" - OnEgressTraffic hook.HookType = "onEgressTraffic" - OnShutdown hook.HookType = "onShutdown" - OnTick hook.HookType = "onTick" + OnRun HookType = "onRun" + OnBooting HookType = "onBooting" + OnBooted HookType = "onBooted" + OnOpening HookType = "onOpening" + OnOpened HookType = "onOpened" + OnClosing HookType = "onClosing" + OnClosed HookType = "onClosed" + OnTraffic HookType = "onTraffic" + OnIngressTraffic HookType = "onIngressTraffic" + OnEgressTraffic HookType = "onEgressTraffic" + OnShutdown HookType = "onShutdown" + OnTick HookType = "onTick" // Pool hooks (network/pool.go). - OnNewClient hook.HookType = "onNewClient" + OnNewClient HookType = "onNewClient" ) type HookConfig struct { - hooks map[hook.HookType]map[hook.Priority]hook.HookDef + hooks map[HookType]map[Priority]HookDef Logger zerolog.Logger Verification config.Policy } @@ -46,19 +46,19 @@ type HookConfig struct { // NewHookConfig returns a new HookConfig. func NewHookConfig() *HookConfig { return &HookConfig{ - hooks: map[hook.HookType]map[hook.Priority]hook.HookDef{}, + hooks: map[HookType]map[Priority]HookDef{}, } } // Hooks returns the hooks. -func (h *HookConfig) Hooks() map[hook.HookType]map[hook.Priority]hook.HookDef { +func (h *HookConfig) Hooks() map[HookType]map[Priority]HookDef { return h.hooks } // Add adds a hook with a priority to the hooks map. -func (h *HookConfig) Add(hookType hook.HookType, prio hook.Priority, hookFunc hook.HookDef) { +func (h *HookConfig) Add(hookType HookType, prio Priority, hookFunc HookDef) { if len(h.hooks[hookType]) == 0 { - h.hooks[hookType] = map[hook.Priority]hook.HookDef{prio: hookFunc} + h.hooks[hookType] = map[Priority]HookDef{prio: hookFunc} } else { if _, ok := h.hooks[hookType][prio]; ok { h.Logger.Warn().Fields( @@ -73,7 +73,7 @@ func (h *HookConfig) Add(hookType hook.HookType, prio hook.Priority, hookFunc ho } // Get returns the hooks of a specific type. -func (h *HookConfig) Get(hookType hook.HookType) map[hook.Priority]hook.HookDef { +func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef { return h.hooks[hookType] } @@ -87,14 +87,14 @@ func (h *HookConfig) Get(hookType hook.HookType) map[hook.Priority]hook.HookDef // to Remove, the hook is removed from the list of hooks on the first error. If the // verification mode is set to Ignore, the error is ignored and the execution continues. // If the verification mode is set to PassDown, the extra keys/values in the result -// are passed down to the next hook. The verification mode is set to PassDown by default. +// are passed down to the next The verification mode is set to PassDown by default. // The opts are passed to the hooks as well to allow them to use the grpc.CallOption. // //nolint:funlen func (h *HookConfig) Run( ctx context.Context, args map[string]interface{}, - hookType hook.HookType, + hookType HookType, verification config.Policy, opts ...grpc.CallOption, ) (map[string]interface{}, *gerr.GatewayDError) { @@ -107,7 +107,7 @@ func (h *HookConfig) Run( defer cancel() // Cast custom fields to their primitive types, like time.Duration to float64. - args = CastToPrimitiveTypes(args) + args = utils.CastToPrimitiveTypes(args) // Create structpb.Struct from args. var params *structpb.Struct @@ -120,7 +120,7 @@ func (h *HookConfig) Run( } // Sort hooks by priority. - priorities := make([]hook.Priority, 0, len(h.hooks[hookType])) + priorities := make([]Priority, 0, len(h.hooks[hookType])) for prio := range h.hooks[hookType] { priorities = append(priorities, prio) } @@ -130,7 +130,7 @@ func (h *HookConfig) Run( // Run hooks, passing the result of the previous hook to the next one. returnVal := &structpb.Struct{} - var removeList []hook.Priority + var removeList []Priority // The signature of parameters and args MUST be the same for this to work. for idx, prio := range priorities { var result *structpb.Struct @@ -145,7 +145,7 @@ func (h *HookConfig) Run( // and that the hook does not return any unexpected values. // If the verification mode is non-strict (permissive), let the plugin pass // extra keys/values to the next plugin in chain. - if Verify(params, result) || verification == config.PassDown { + if utils.Verify(params, result) || verification == config.PassDown { // Update the last return value with the current result returnVal = result continue @@ -154,7 +154,7 @@ func (h *HookConfig) Run( // At this point, the hook returned an invalid value, so we need to handle it. // The result of the current hook will be ignored, regardless of the policy. switch verification { - // Ignore the result of this plugin, log an error and execute the next hook. + // Ignore the result of this plugin, log an error and execute the next case config.Ignore: h.Logger.Error().Err(err).Fields( map[string]interface{}{ @@ -165,7 +165,7 @@ func (h *HookConfig) Run( if idx == 0 { returnVal = params } - // Abort execution of the plugins, log the error and return the result of the last hook. + // Abort execution of the plugins, log the error and return the result of the last case config.Abort: h.Logger.Error().Err(err).Fields( map[string]interface{}{ @@ -177,7 +177,7 @@ func (h *HookConfig) Run( return args, nil } return returnVal.AsMap(), nil - // Remove the hook from the registry, log the error and execute the next hook. + // Remove the hook from the registry, log the error and execute the next case config.Remove: h.Logger.Error().Err(err).Fields( map[string]interface{}{ diff --git a/plugin/hooks_test.go b/plugin/hook/hooks_test.go similarity index 98% rename from plugin/hooks_test.go rename to plugin/hook/hooks_test.go index 79c00ae0..61ff4891 100644 --- a/plugin/hooks_test.go +++ b/plugin/hook/hooks_test.go @@ -1,11 +1,10 @@ -package plugin +package hook import ( "context" "testing" "github.com/gatewayd-io/gatewayd/config" - "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/structpb" @@ -63,7 +62,7 @@ func Test_HookConfig_Get(t *testing.T) { ) (*structpb.Struct, error) { return args, nil } - prio := hook.Priority(0) + prio := Priority(0) hooks.Add(OnNewLogger, prio, testFunc) assert.NotNil(t, hooks.Get(OnNewLogger)) assert.ObjectsAreEqual(testFunc, hooks.Get(OnNewLogger)[prio]) @@ -88,7 +87,7 @@ func Test_HookConfig_Run(t *testing.T) { // Test_HookConfig_Run_PassDown tests the Run function with the PassDown option. func Test_HookConfig_Run_PassDown(t *testing.T) { hooks := NewHookConfig() - // The result of the hook will be nil and will be passed down to the next hook. + // The result of the hook will be nil and will be passed down to the next hooks.Add(OnNewLogger, 0, func( ctx context.Context, args *structpb.Struct, @@ -124,7 +123,7 @@ func Test_HookConfig_Run_PassDown(t *testing.T) { // Test_HookConfig_Run_PassDown_2 tests the Run function with the PassDown option. func Test_HookConfig_Run_PassDown_2(t *testing.T) { hooks := NewHookConfig() - // The result of the hook will be nil and will be passed down to the next hook. + // The result of the hook will be nil and will be passed down to the next hooks.Add(OnNewLogger, 0, func( ctx context.Context, args *structpb.Struct, @@ -221,7 +220,7 @@ func Test_HookConfig_Run_Abort(t *testing.T) { assert.Nil(t, err) return output, nil }) - // The first hook returns nil, and it aborts the execution of the rest of the hook. + // The first hook returns nil, and it aborts the execution of the rest of the result, err := hooks.Run( context.Background(), map[string]interface{}{}, OnNewLogger, config.Abort) assert.Nil(t, err) diff --git a/plugin/hook/types.go b/plugin/hook/types.go index eb157db4..1d867ce5 100644 --- a/plugin/hook/types.go +++ b/plugin/hook/types.go @@ -14,5 +14,4 @@ type ( HookType string HookDef func( context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error) - Component string ) diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 2878bc34..332f9359 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -8,6 +8,7 @@ import ( gerr "github.com/gatewayd-io/gatewayd/errors" "github.com/gatewayd-io/gatewayd/logging" "github.com/gatewayd-io/gatewayd/plugin/hook" + "github.com/gatewayd-io/gatewayd/plugin/utils" pluginV1 "github.com/gatewayd-io/gatewayd/plugin/v1" "github.com/gatewayd-io/gatewayd/pool" goplugin "github.com/hashicorp/go-plugin" @@ -28,14 +29,14 @@ type IPluginRegistry interface { type PluginRegistry struct { //nolint:golint,revive plugins pool.IPool - hooksConfig *HookConfig + hooksConfig *hook.HookConfig CompatPolicy config.CompatPolicy } var _ IPluginRegistry = &PluginRegistry{} // NewRegistry creates a new plugin registry. -func NewRegistry(hooksConfig *HookConfig) *PluginRegistry { +func NewRegistry(hooksConfig *hook.HookConfig) *PluginRegistry { return &PluginRegistry{ plugins: pool.NewPool(config.EmptyPoolCapacity), hooksConfig: hooksConfig, @@ -175,7 +176,7 @@ func (reg *PluginRegistry) LoadPlugins(plugins []config.Plugin) { // Verify the checksum. // TODO: Load the plugin from a remote location if the checksum didn't match? - if sum, err := sha256sum(plugin.LocalPath); err != nil { + if sum, err := utils.SHA256SUM(plugin.LocalPath); err != nil { reg.hooksConfig.Logger.Debug().Err(err).Msg("Failed to calculate checksum") continue } else if sum != plugin.ID.Checksum { @@ -200,7 +201,7 @@ func (reg *PluginRegistry) LoadPlugins(plugins []config.Plugin) { &goplugin.ClientConfig{ HandshakeConfig: pluginV1.Handshake, Plugins: pluginV1.GetPluginMap(plugin.ID.Name), - Cmd: NewCommand(plugin.LocalPath, plugin.Args, plugin.Env), + Cmd: utils.NewCommand(plugin.LocalPath, plugin.Args, plugin.Env), AllowedProtocols: []goplugin.Protocol{ goplugin.ProtocolGRPC, }, @@ -330,43 +331,43 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { for _, hookType := range pluginImpl.Hooks { var hookFunc hook.HookDef switch hookType { - case OnConfigLoaded: + case hook.OnConfigLoaded: hookFunc = pluginV1.OnConfigLoaded - case OnNewLogger: + case hook.OnNewLogger: hookFunc = pluginV1.OnNewLogger - case OnNewPool: + case hook.OnNewPool: hookFunc = pluginV1.OnNewPool - case OnNewProxy: + case hook.OnNewProxy: hookFunc = pluginV1.OnNewProxy - case OnNewServer: + case hook.OnNewServer: hookFunc = pluginV1.OnNewServer - case OnSignal: + case hook.OnSignal: hookFunc = pluginV1.OnSignal - case OnRun: + case hook.OnRun: hookFunc = pluginV1.OnRun - case OnBooting: + case hook.OnBooting: hookFunc = pluginV1.OnBooting - case OnBooted: + case hook.OnBooted: hookFunc = pluginV1.OnBooted - case OnOpening: + case hook.OnOpening: hookFunc = pluginV1.OnOpening - case OnOpened: + case hook.OnOpened: hookFunc = pluginV1.OnOpened - case OnClosing: + case hook.OnClosing: hookFunc = pluginV1.OnClosing - case OnClosed: + case hook.OnClosed: hookFunc = pluginV1.OnClosed - case OnTraffic: + case hook.OnTraffic: hookFunc = pluginV1.OnTraffic - case OnIngressTraffic: + case hook.OnIngressTraffic: hookFunc = pluginV1.OnIngressTraffic - case OnEgressTraffic: + case hook.OnEgressTraffic: hookFunc = pluginV1.OnEgressTraffic - case OnShutdown: + case hook.OnShutdown: hookFunc = pluginV1.OnShutdown - case OnTick: + case hook.OnTick: hookFunc = pluginV1.OnTick - case OnNewClient: + case hook.OnNewClient: hookFunc = pluginV1.OnNewClient default: reg.hooksConfig.Logger.Warn().Str("hook", string(hookType)).Msg("Unknown hook type") diff --git a/plugin/plugin_registry_test.go b/plugin/plugin_registry_test.go index bfc48f7f..c1aaa7b1 100644 --- a/plugin/plugin_registry_test.go +++ b/plugin/plugin_registry_test.go @@ -3,12 +3,13 @@ package plugin import ( "testing" + "github.com/gatewayd-io/gatewayd/plugin/hook" "github.com/stretchr/testify/assert" ) // TestPluginRegistry tests the PluginRegistry. func TestPluginRegistry(t *testing.T) { - hooksConfig := NewHookConfig() + hooksConfig := hook.NewHookConfig() assert.NotNil(t, hooksConfig) reg := NewRegistry(hooksConfig) assert.NotNil(t, reg) diff --git a/plugin/utils.go b/plugin/utils/functions.go similarity index 93% rename from plugin/utils.go rename to plugin/utils/functions.go index 61ea2d89..bf06f57c 100644 --- a/plugin/utils.go +++ b/plugin/utils/functions.go @@ -1,4 +1,4 @@ -package plugin +package utils import ( "bufio" @@ -17,10 +17,10 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) -// sha256sum returns the sha256 checksum of a file. +// SHA256SUM returns the sha256 checksum of a file. // Ref: https://github.com/codingsince1985/checksum // A little copying is better than a little dependency. -func sha256sum(filename string) (string, *gerr.GatewayDError) { +func SHA256SUM(filename string) (string, *gerr.GatewayDError) { if info, err := os.Stat(filename); err != nil || info.IsDir() { return "", gerr.ErrFileNotFound.Wrap(err) } diff --git a/plugin/utils_test.go b/plugin/utils/functions_test.go similarity index 94% rename from plugin/utils_test.go rename to plugin/utils/functions_test.go index 2bd3f58c..5f338b84 100644 --- a/plugin/utils_test.go +++ b/plugin/utils/functions_test.go @@ -1,4 +1,4 @@ -package plugin +package utils import ( "testing" @@ -9,7 +9,7 @@ import ( // Test_sha256sum tests the sha256sum function. func Test_sha256sum(t *testing.T) { - checksum, err := sha256sum("../LICENSE") + checksum, err := SHA256SUM("../LICENSE") assert.Nil(t, err) assert.Equal(t, "8486a10c4393cee1c25392769ddd3b2d6c242d6ec7928e1414efff7dfb2f07ef", @@ -19,7 +19,7 @@ func Test_sha256sum(t *testing.T) { // Test_sha256sum_fail tests the sha256sum function with a file that does not exist. func Test_sha256sum_fail(t *testing.T) { - _, err := sha256sum("not_a_file") + _, err := SHA256SUM("not_a_file") assert.NotNil(t, err) } From 69042c3a740b80b94591c2ccbb3714c2196c9109 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 9 Jan 2023 23:18:59 +0100 Subject: [PATCH 03/15] Rename hook.HookConfig to hook.Config --- cmd/run.go | 2 +- network/proxy.go | 4 ++-- network/server.go | 4 ++-- plugin/hook/hooks.go | 16 ++++++++-------- plugin/plugin_registry.go | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 2acc29f8..4c5e77dd 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -321,7 +321,7 @@ var runCmd = &cobra.Command{ ) signalsCh := make(chan os.Signal, 1) signal.Notify(signalsCh, signals...) - go func(hooksConfig *hook.HookConfig) { + go func(hooksConfig *hook.Config) { for sig := range signalsCh { for _, s := range signals { if sig != s { diff --git a/network/proxy.go b/network/proxy.go index f9dbfba2..2f3503fa 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -24,7 +24,7 @@ type Proxy struct { availableConnections pool.IPool busyConnections pool.IPool logger zerolog.Logger - hookConfig *hook.HookConfig + hookConfig *hook.Config Elastic bool ReuseElasticClients bool @@ -37,7 +37,7 @@ var _ IProxy = &Proxy{} // NewProxy creates a new proxy. func NewProxy( - p pool.IPool, hookConfig *hook.HookConfig, + p pool.IPool, hookConfig *hook.Config, elastic, reuseElasticClients bool, clientConfig *config.Client, logger zerolog.Logger, ) *Proxy { diff --git a/network/server.go b/network/server.go index 59ba1044..2188b5df 100644 --- a/network/server.go +++ b/network/server.go @@ -20,7 +20,7 @@ type Server struct { engine gnet.Engine proxy IProxy logger zerolog.Logger - hooksConfig *hook.HookConfig + hooksConfig *hook.Config Network string // tcp/udp/unix Address string @@ -333,7 +333,7 @@ func NewServer( options []gnet.Option, proxy IProxy, logger zerolog.Logger, - hooksConfig *hook.HookConfig, + hooksConfig *hook.Config, ) *Server { // Create the server. server := Server{ diff --git a/plugin/hook/hooks.go b/plugin/hook/hooks.go index c1b935c1..d1108002 100644 --- a/plugin/hook/hooks.go +++ b/plugin/hook/hooks.go @@ -37,26 +37,26 @@ const ( OnNewClient HookType = "onNewClient" ) -type HookConfig struct { +type Config struct { hooks map[HookType]map[Priority]HookDef Logger zerolog.Logger Verification config.Policy } -// NewHookConfig returns a new HookConfig. -func NewHookConfig() *HookConfig { - return &HookConfig{ +// NewHookConfig returns a new Config. +func NewHookConfig() *Config { + return &Config{ hooks: map[HookType]map[Priority]HookDef{}, } } // Hooks returns the hooks. -func (h *HookConfig) Hooks() map[HookType]map[Priority]HookDef { +func (h *Config) Hooks() map[HookType]map[Priority]HookDef { return h.hooks } // Add adds a hook with a priority to the hooks map. -func (h *HookConfig) Add(hookType HookType, prio Priority, hookFunc HookDef) { +func (h *Config) Add(hookType HookType, prio Priority, hookFunc HookDef) { if len(h.hooks[hookType]) == 0 { h.hooks[hookType] = map[Priority]HookDef{prio: hookFunc} } else { @@ -73,7 +73,7 @@ func (h *HookConfig) Add(hookType HookType, prio Priority, hookFunc HookDef) { } // Get returns the hooks of a specific type. -func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef { +func (h *Config) Get(hookType HookType) map[Priority]HookDef { return h.hooks[hookType] } @@ -91,7 +91,7 @@ func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef { // The opts are passed to the hooks as well to allow them to use the grpc.CallOption. // //nolint:funlen -func (h *HookConfig) Run( +func (h *Config) Run( ctx context.Context, args map[string]interface{}, hookType HookType, diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 332f9359..27440c00 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -29,14 +29,14 @@ type IPluginRegistry interface { type PluginRegistry struct { //nolint:golint,revive plugins pool.IPool - hooksConfig *hook.HookConfig + hooksConfig *hook.Config CompatPolicy config.CompatPolicy } var _ IPluginRegistry = &PluginRegistry{} // NewRegistry creates a new plugin registry. -func NewRegistry(hooksConfig *hook.HookConfig) *PluginRegistry { +func NewRegistry(hooksConfig *hook.Config) *PluginRegistry { return &PluginRegistry{ plugins: pool.NewPool(config.EmptyPoolCapacity), hooksConfig: hooksConfig, From 4b23927eec4db82529e3fa387fcabfecb169b99f Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 9 Jan 2023 23:20:09 +0100 Subject: [PATCH 04/15] Rename hook.HookType to hook.Type --- plugin/hook/hooks.go | 50 ++++++++++++++++++++++---------------------- plugin/hook/types.go | 2 +- plugin/plugin.go | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/plugin/hook/hooks.go b/plugin/hook/hooks.go index d1108002..f69978fc 100644 --- a/plugin/hook/hooks.go +++ b/plugin/hook/hooks.go @@ -14,31 +14,31 @@ import ( const ( // Run command hooks (cmd/run.go). - OnConfigLoaded HookType = "onConfigLoaded" - OnNewLogger HookType = "onNewLogger" - OnNewPool HookType = "onNewPool" - OnNewProxy HookType = "onNewProxy" - OnNewServer HookType = "onNewServer" - OnSignal HookType = "onSignal" + OnConfigLoaded Type = "onConfigLoaded" + OnNewLogger Type = "onNewLogger" + OnNewPool Type = "onNewPool" + OnNewProxy Type = "onNewProxy" + OnNewServer Type = "onNewServer" + OnSignal Type = "onSignal" // Server hooks (network/server.go). - OnRun HookType = "onRun" - OnBooting HookType = "onBooting" - OnBooted HookType = "onBooted" - OnOpening HookType = "onOpening" - OnOpened HookType = "onOpened" - OnClosing HookType = "onClosing" - OnClosed HookType = "onClosed" - OnTraffic HookType = "onTraffic" - OnIngressTraffic HookType = "onIngressTraffic" - OnEgressTraffic HookType = "onEgressTraffic" - OnShutdown HookType = "onShutdown" - OnTick HookType = "onTick" + OnRun Type = "onRun" + OnBooting Type = "onBooting" + OnBooted Type = "onBooted" + OnOpening Type = "onOpening" + OnOpened Type = "onOpened" + OnClosing Type = "onClosing" + OnClosed Type = "onClosed" + OnTraffic Type = "onTraffic" + OnIngressTraffic Type = "onIngressTraffic" + OnEgressTraffic Type = "onEgressTraffic" + OnShutdown Type = "onShutdown" + OnTick Type = "onTick" // Pool hooks (network/pool.go). - OnNewClient HookType = "onNewClient" + OnNewClient Type = "onNewClient" ) type Config struct { - hooks map[HookType]map[Priority]HookDef + hooks map[Type]map[Priority]HookDef Logger zerolog.Logger Verification config.Policy } @@ -46,17 +46,17 @@ type Config struct { // NewHookConfig returns a new Config. func NewHookConfig() *Config { return &Config{ - hooks: map[HookType]map[Priority]HookDef{}, + hooks: map[Type]map[Priority]HookDef{}, } } // Hooks returns the hooks. -func (h *Config) Hooks() map[HookType]map[Priority]HookDef { +func (h *Config) Hooks() map[Type]map[Priority]HookDef { return h.hooks } // Add adds a hook with a priority to the hooks map. -func (h *Config) Add(hookType HookType, prio Priority, hookFunc HookDef) { +func (h *Config) Add(hookType Type, prio Priority, hookFunc HookDef) { if len(h.hooks[hookType]) == 0 { h.hooks[hookType] = map[Priority]HookDef{prio: hookFunc} } else { @@ -73,7 +73,7 @@ func (h *Config) Add(hookType HookType, prio Priority, hookFunc HookDef) { } // Get returns the hooks of a specific type. -func (h *Config) Get(hookType HookType) map[Priority]HookDef { +func (h *Config) Get(hookType Type) map[Priority]HookDef { return h.hooks[hookType] } @@ -94,7 +94,7 @@ func (h *Config) Get(hookType HookType) map[Priority]HookDef { func (h *Config) Run( ctx context.Context, args map[string]interface{}, - hookType HookType, + hookType Type, verification config.Policy, opts ...grpc.CallOption, ) (map[string]interface{}, *gerr.GatewayDError) { diff --git a/plugin/hook/types.go b/plugin/hook/types.go index 1d867ce5..440f9449 100644 --- a/plugin/hook/types.go +++ b/plugin/hook/types.go @@ -11,7 +11,7 @@ type ( // Priority is the priority of a hook. // Smaller values are executed first (higher priority). Priority uint - HookType string + Type string HookDef func( context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error) ) diff --git a/plugin/plugin.go b/plugin/plugin.go index 6df7b78c..2ae76915 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -40,7 +40,7 @@ type Plugin struct { // internal and external config options Config map[string]string // hooks it attaches to - Hooks []hook.HookType + Hooks []hook.Type Priority hook.Priority // required plugins to be loaded before this one // Built-in plugins are always loaded first From 78465e25939dadd4ee1e1fb5f7610745f4f2e0f1 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 9 Jan 2023 23:21:33 +0100 Subject: [PATCH 05/15] Rename hook.HookDef to hook.FunctionType --- plugin/hook/hooks.go | 12 ++++++------ plugin/hook/types.go | 6 +++--- plugin/plugin_registry.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin/hook/hooks.go b/plugin/hook/hooks.go index f69978fc..235a2ea8 100644 --- a/plugin/hook/hooks.go +++ b/plugin/hook/hooks.go @@ -38,7 +38,7 @@ const ( ) type Config struct { - hooks map[Type]map[Priority]HookDef + hooks map[Type]map[Priority]FunctionType Logger zerolog.Logger Verification config.Policy } @@ -46,19 +46,19 @@ type Config struct { // NewHookConfig returns a new Config. func NewHookConfig() *Config { return &Config{ - hooks: map[Type]map[Priority]HookDef{}, + hooks: map[Type]map[Priority]FunctionType{}, } } // Hooks returns the hooks. -func (h *Config) Hooks() map[Type]map[Priority]HookDef { +func (h *Config) Hooks() map[Type]map[Priority]FunctionType { return h.hooks } // Add adds a hook with a priority to the hooks map. -func (h *Config) Add(hookType Type, prio Priority, hookFunc HookDef) { +func (h *Config) Add(hookType Type, prio Priority, hookFunc FunctionType) { if len(h.hooks[hookType]) == 0 { - h.hooks[hookType] = map[Priority]HookDef{prio: hookFunc} + h.hooks[hookType] = map[Priority]FunctionType{prio: hookFunc} } else { if _, ok := h.hooks[hookType][prio]; ok { h.Logger.Warn().Fields( @@ -73,7 +73,7 @@ func (h *Config) Add(hookType Type, prio Priority, hookFunc HookDef) { } // Get returns the hooks of a specific type. -func (h *Config) Get(hookType Type) map[Priority]HookDef { +func (h *Config) Get(hookType Type) map[Priority]FunctionType { return h.hooks[hookType] } diff --git a/plugin/hook/types.go b/plugin/hook/types.go index 440f9449..c32e0467 100644 --- a/plugin/hook/types.go +++ b/plugin/hook/types.go @@ -10,8 +10,8 @@ import ( type ( // Priority is the priority of a hook. // Smaller values are executed first (higher priority). - Priority uint - Type string - HookDef func( + Priority uint + Type string + FunctionType func( context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error) ) diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 27440c00..34e0f2de 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -329,7 +329,7 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { } for _, hookType := range pluginImpl.Hooks { - var hookFunc hook.HookDef + var hookFunc hook.FunctionType switch hookType { case hook.OnConfigLoaded: hookFunc = pluginV1.OnConfigLoaded From 496c041014f7e52d2c765f33aec6ddba593ef2fb Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 9 Jan 2023 23:34:07 +0100 Subject: [PATCH 06/15] Fix test for the nested package --- plugin/utils/functions_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/utils/functions_test.go b/plugin/utils/functions_test.go index 5f338b84..6d9578f1 100644 --- a/plugin/utils/functions_test.go +++ b/plugin/utils/functions_test.go @@ -9,7 +9,7 @@ import ( // Test_sha256sum tests the sha256sum function. func Test_sha256sum(t *testing.T) { - checksum, err := SHA256SUM("../LICENSE") + checksum, err := SHA256SUM("../../LICENSE") assert.Nil(t, err) assert.Equal(t, "8486a10c4393cee1c25392769ddd3b2d6c242d6ec7928e1414efff7dfb2f07ef", From 6e514e31a6779eaeea475f28f5d21e7d37591cd0 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 9 Jan 2023 23:36:50 +0100 Subject: [PATCH 07/15] Add hook constants to a separate file --- plugin/hook/constants.go | 26 ++++++++++++++++++++++++++ plugin/hook/hooks.go | 25 ------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 plugin/hook/constants.go diff --git a/plugin/hook/constants.go b/plugin/hook/constants.go new file mode 100644 index 00000000..1d78dacf --- /dev/null +++ b/plugin/hook/constants.go @@ -0,0 +1,26 @@ +package hook + +const ( + // Run command hooks (cmd/run.go). + OnConfigLoaded Type = "onConfigLoaded" + OnNewLogger Type = "onNewLogger" + OnNewPool Type = "onNewPool" + OnNewProxy Type = "onNewProxy" + OnNewServer Type = "onNewServer" + OnSignal Type = "onSignal" + // Server hooks (network/server.go). + OnRun Type = "onRun" + OnBooting Type = "onBooting" + OnBooted Type = "onBooted" + OnOpening Type = "onOpening" + OnOpened Type = "onOpened" + OnClosing Type = "onClosing" + OnClosed Type = "onClosed" + OnTraffic Type = "onTraffic" + OnIngressTraffic Type = "onIngressTraffic" + OnEgressTraffic Type = "onEgressTraffic" + OnShutdown Type = "onShutdown" + OnTick Type = "onTick" + // Pool hooks (network/pool.go). + OnNewClient Type = "onNewClient" +) diff --git a/plugin/hook/hooks.go b/plugin/hook/hooks.go index 235a2ea8..20784cf8 100644 --- a/plugin/hook/hooks.go +++ b/plugin/hook/hooks.go @@ -12,31 +12,6 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) -const ( - // Run command hooks (cmd/run.go). - OnConfigLoaded Type = "onConfigLoaded" - OnNewLogger Type = "onNewLogger" - OnNewPool Type = "onNewPool" - OnNewProxy Type = "onNewProxy" - OnNewServer Type = "onNewServer" - OnSignal Type = "onSignal" - // Server hooks (network/server.go). - OnRun Type = "onRun" - OnBooting Type = "onBooting" - OnBooted Type = "onBooted" - OnOpening Type = "onOpening" - OnOpened Type = "onOpened" - OnClosing Type = "onClosing" - OnClosed Type = "onClosed" - OnTraffic Type = "onTraffic" - OnIngressTraffic Type = "onIngressTraffic" - OnEgressTraffic Type = "onEgressTraffic" - OnShutdown Type = "onShutdown" - OnTick Type = "onTick" - // Pool hooks (network/pool.go). - OnNewClient Type = "onNewClient" -) - type Config struct { hooks map[Type]map[Priority]FunctionType Logger zerolog.Logger From 9b174f7dd065795b4d5a68ac403d488a0fabc87c Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 00:59:46 +0100 Subject: [PATCH 08/15] Add two new traffic hooks and renamed old ones to match the new naming convention --- plugin/hook/constants.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugin/hook/constants.go b/plugin/hook/constants.go index 1d78dacf..b9c4e3e6 100644 --- a/plugin/hook/constants.go +++ b/plugin/hook/constants.go @@ -9,18 +9,20 @@ const ( OnNewServer Type = "onNewServer" OnSignal Type = "onSignal" // Server hooks (network/server.go). - OnRun Type = "onRun" - OnBooting Type = "onBooting" - OnBooted Type = "onBooted" - OnOpening Type = "onOpening" - OnOpened Type = "onOpened" - OnClosing Type = "onClosing" - OnClosed Type = "onClosed" - OnTraffic Type = "onTraffic" - OnIngressTraffic Type = "onIngressTraffic" - OnEgressTraffic Type = "onEgressTraffic" - OnShutdown Type = "onShutdown" - OnTick Type = "onTick" + OnRun Type = "onRun" + OnBooting Type = "onBooting" + OnBooted Type = "onBooted" + OnOpening Type = "onOpening" + OnOpened Type = "onOpened" + OnClosing Type = "onClosing" + OnClosed Type = "onClosed" + OnTraffic Type = "onTraffic" + OnTrafficFromClient Type = "onTrafficFromClient" + OnTrafficToServer Type = "onTrafficToServer" + OnTrafficFromServer Type = "onTrafficFromServer" + OnTrafficToClient Type = "onTrafficToClient" + OnShutdown Type = "onShutdown" + OnTick Type = "onTick" // Pool hooks (network/pool.go). OnNewClient Type = "onNewClient" ) From 0dc3582dbf76eef431d9783ba754f8358ba42cc7 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:00:48 +0100 Subject: [PATCH 09/15] Map new hooks with the plugins --- plugin/plugin_registry.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 34e0f2de..8dbe4e0a 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -359,10 +359,14 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { hookFunc = pluginV1.OnClosed case hook.OnTraffic: hookFunc = pluginV1.OnTraffic - case hook.OnIngressTraffic: - hookFunc = pluginV1.OnIngressTraffic - case hook.OnEgressTraffic: - hookFunc = pluginV1.OnEgressTraffic + case hook.OnTrafficFromClient: + hookFunc = pluginV1.OnTrafficFromClient + case hook.OnTrafficToServer: + hookFunc = pluginV1.OnTrafficToServer + case hook.OnTrafficFromServer: + hookFunc = pluginV1.OnTrafficFromServer + case hook.OnTrafficToClient: + hookFunc = pluginV1.OnTrafficToClient case hook.OnShutdown: hookFunc = pluginV1.OnShutdown case hook.OnTick: @@ -370,7 +374,8 @@ func (reg *PluginRegistry) RegisterHooks(id Identifier) { case hook.OnNewClient: hookFunc = pluginV1.OnNewClient default: - reg.hooksConfig.Logger.Warn().Str("hook", string(hookType)).Msg("Unknown hook type") + reg.hooksConfig.Logger.Warn().Str("hook", string(hookType)).Msg( + "Unknown hook, skipping") continue } reg.hooksConfig.Logger.Debug().Str("hook", string(hookType)).Msg("Registering hook") From 4116d406e03c8ae5611be061323a1f591c9f4ae8 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:01:34 +0100 Subject: [PATCH 10/15] Update protocol and regenerate stubs --- plugin/v1/plugin.pb.go | 454 ++++++++++++++---------------------- plugin/v1/plugin.proto | 15 +- plugin/v1/plugin_grpc.pb.go | 120 ++++++++-- 3 files changed, 279 insertions(+), 310 deletions(-) diff --git a/plugin/v1/plugin.pb.go b/plugin/v1/plugin.pb.go index e8e83776..e7c71a4a 100644 --- a/plugin/v1/plugin.pb.go +++ b/plugin/v1/plugin.pb.go @@ -21,93 +21,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Version struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Major uint64 `protobuf:"varint,1,opt,name=major,proto3" json:"major,omitempty"` - Minor uint64 `protobuf:"varint,2,opt,name=minor,proto3" json:"minor,omitempty"` - Patch uint64 `protobuf:"varint,3,opt,name=patch,proto3" json:"patch,omitempty"` - Pre string `protobuf:"bytes,4,opt,name=pre,proto3" json:"pre,omitempty"` - Metadata string `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"` - Original string `protobuf:"bytes,6,opt,name=original,proto3" json:"original,omitempty"` -} - -func (x *Version) Reset() { - *x = Version{} - if protoimpl.UnsafeEnabled { - mi := &file_plugin_v1_plugin_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Version) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Version) ProtoMessage() {} - -func (x *Version) ProtoReflect() protoreflect.Message { - mi := &file_plugin_v1_plugin_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Version.ProtoReflect.Descriptor instead. -func (*Version) Descriptor() ([]byte, []int) { - return file_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} -} - -func (x *Version) GetMajor() uint64 { - if x != nil { - return x.Major - } - return 0 -} - -func (x *Version) GetMinor() uint64 { - if x != nil { - return x.Minor - } - return 0 -} - -func (x *Version) GetPatch() uint64 { - if x != nil { - return x.Patch - } - return 0 -} - -func (x *Version) GetPre() string { - if x != nil { - return x.Pre - } - return "" -} - -func (x *Version) GetMetadata() string { - if x != nil { - return x.Metadata - } - return "" -} - -func (x *Version) GetOriginal() string { - if x != nil { - return x.Original - } - return "" -} - type PluginID struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -122,7 +35,7 @@ type PluginID struct { func (x *PluginID) Reset() { *x = PluginID{} if protoimpl.UnsafeEnabled { - mi := &file_plugin_v1_plugin_proto_msgTypes[1] + mi := &file_plugin_v1_plugin_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -135,7 +48,7 @@ func (x *PluginID) String() string { func (*PluginID) ProtoMessage() {} func (x *PluginID) ProtoReflect() protoreflect.Message { - mi := &file_plugin_v1_plugin_proto_msgTypes[1] + mi := &file_plugin_v1_plugin_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -148,7 +61,7 @@ func (x *PluginID) ProtoReflect() protoreflect.Message { // Deprecated: Use PluginID.ProtoReflect.Descriptor instead. func (*PluginID) Descriptor() ([]byte, []int) { - return file_plugin_v1_plugin_proto_rawDescGZIP(), []int{1} + return file_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} } func (x *PluginID) GetName() string { @@ -202,7 +115,7 @@ type PluginConfig struct { func (x *PluginConfig) Reset() { *x = PluginConfig{} if protoimpl.UnsafeEnabled { - mi := &file_plugin_v1_plugin_proto_msgTypes[2] + mi := &file_plugin_v1_plugin_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -215,7 +128,7 @@ func (x *PluginConfig) String() string { func (*PluginConfig) ProtoMessage() {} func (x *PluginConfig) ProtoReflect() protoreflect.Message { - mi := &file_plugin_v1_plugin_proto_msgTypes[2] + mi := &file_plugin_v1_plugin_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -228,7 +141,7 @@ func (x *PluginConfig) ProtoReflect() protoreflect.Message { // Deprecated: Use PluginConfig.ProtoReflect.Descriptor instead. func (*PluginConfig) Descriptor() ([]byte, []int) { - return file_plugin_v1_plugin_proto_rawDescGZIP(), []int{2} + return file_plugin_v1_plugin_proto_rawDescGZIP(), []int{1} } func (x *PluginConfig) GetId() *PluginID { @@ -308,140 +221,140 @@ var file_plugin_v1_plugin_proto_rawDesc = []byte{ 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x95, 0x01, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, - 0x05, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x6d, 0x61, - 0x6a, 0x6f, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x05, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x61, 0x74, - 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x70, 0x61, 0x74, 0x63, 0x68, 0x12, - 0x10, 0x0a, 0x03, 0x70, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x70, 0x72, - 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, - 0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x73, 0x0a, 0x08, 0x50, 0x6c, 0x75, - 0x67, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f, 0x75, 0x72, - 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x55, - 0x72, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x22, 0xec, - 0x03, 0x0a, 0x0c, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, - 0x23, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x6c, - 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x44, - 0x52, 0x02, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, - 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, - 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, - 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x12, 0x3b, 0x0a, 0x06, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x70, 0x6c, - 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x68, 0x6f, 0x6f, 0x6b, - 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x12, 0x41, - 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x25, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x75, - 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, - 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, - 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, - 0x69, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, - 0x6f, 0x72, 0x69, 0x65, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x1a, 0x3b, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0x98, 0x0a, - 0x0a, 0x15, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x44, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x43, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x6c, - 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x42, 0x0a, 0x0e, - 0x4f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x12, 0x17, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x6f, 0x22, 0x73, 0x0a, 0x08, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x72, + 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x55, 0x72, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x22, 0xec, 0x03, 0x0a, 0x0c, 0x50, 0x6c, 0x75, 0x67, 0x69, + 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x23, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x44, 0x52, 0x02, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, + 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, + 0x0a, 0x07, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x07, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x69, 0x63, 0x65, + 0x6e, 0x73, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x72, + 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, + 0x55, 0x72, 0x6c, 0x12, 0x3b, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x12, 0x14, 0x0a, 0x05, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x05, 0x68, 0x6f, 0x6f, 0x6b, 0x73, 0x12, 0x41, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, + 0x65, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, + 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, + 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, + 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x1e, 0x0a, + 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x1a, 0x39, 0x0a, + 0x0b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3b, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xad, 0x0b, 0x0a, 0x15, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x44, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x43, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x12, 0x42, 0x0a, 0x0e, 0x4f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x4c, 0x6f, 0x61, 0x64, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, + 0x77, 0x4c, 0x6f, 0x67, 0x67, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, 0x77, 0x4c, 0x6f, 0x67, 0x67, 0x65, 0x72, 0x12, + 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x4e, + 0x65, 0x77, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x4e, 0x65, 0x77, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x17, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3e, 0x0a, 0x0a, 0x4f, 0x6e, 0x4e, 0x65, + 0x77, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, + 0x77, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x12, 0x3e, 0x0a, 0x0a, 0x4f, 0x6e, 0x4e, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x17, + 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x53, + 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, 0x77, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x39, 0x0a, 0x05, 0x4f, 0x6e, 0x52, 0x75, 0x6e, + 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x12, 0x17, 0x2e, + 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, - 0x39, 0x0a, 0x05, 0x4f, 0x6e, 0x52, 0x75, 0x6e, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, - 0x42, 0x6f, 0x6f, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x4f, 0x70, 0x65, 0x6e, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3c, + 0x0a, 0x08, 0x4f, 0x6e, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, + 0x4f, 0x6e, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, + 0x6e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x42, - 0x6f, 0x6f, 0x74, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x4f, 0x70, 0x65, - 0x6e, 0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x4f, 0x70, 0x65, 0x6e, - 0x65, 0x64, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, - 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, - 0x67, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, - 0x75, 0x63, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x4f, 0x6e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, + 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x54, + 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x47, 0x0a, 0x13, 0x4f, 0x6e, 0x54, 0x72, + 0x61, 0x66, 0x66, 0x69, 0x63, 0x46, 0x72, 0x6f, 0x6d, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x12, 0x3d, 0x0a, 0x09, 0x4f, 0x6e, 0x54, 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x12, 0x17, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, - 0x12, 0x44, 0x0a, 0x10, 0x4f, 0x6e, 0x49, 0x6e, 0x67, 0x72, 0x65, 0x73, 0x73, 0x54, 0x72, 0x61, - 0x66, 0x66, 0x69, 0x63, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x43, 0x0a, 0x0f, 0x4f, 0x6e, 0x45, 0x67, 0x72, 0x65, - 0x73, 0x73, 0x54, 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, - 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3e, 0x0a, 0x0a, 0x4f, - 0x6e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, - 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3a, 0x0a, 0x06, 0x4f, - 0x6e, 0x54, 0x69, 0x63, 0x6b, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, 0x77, + 0x74, 0x12, 0x45, 0x0a, 0x11, 0x4f, 0x6e, 0x54, 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x54, 0x6f, + 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x47, 0x0a, 0x13, 0x4f, 0x6e, 0x54, 0x72, + 0x61, 0x66, 0x66, 0x69, 0x63, 0x46, 0x72, 0x6f, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x12, 0x45, 0x0a, 0x11, 0x4f, 0x6e, 0x54, 0x72, 0x61, 0x66, 0x66, 0x69, 0x63, 0x54, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x64, 0x2d, - 0x69, 0x6f, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x64, 0x2f, 0x70, 0x6c, 0x75, 0x67, - 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, - 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3e, 0x0a, 0x0a, 0x4f, 0x6e, 0x53, 0x68, + 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, + 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x12, 0x3a, 0x0a, 0x06, 0x4f, 0x6e, 0x54, 0x69, + 0x63, 0x6b, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, + 0x72, 0x75, 0x63, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x4f, 0x6e, 0x4e, 0x65, 0x77, 0x43, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x12, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1a, 0x17, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x64, 0x2d, 0x69, 0x6f, 0x2f, + 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x64, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x76, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -456,61 +369,64 @@ func file_plugin_v1_plugin_proto_rawDescGZIP() []byte { return file_plugin_v1_plugin_proto_rawDescData } -var file_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_plugin_v1_plugin_proto_goTypes = []interface{}{ - (*Version)(nil), // 0: plugin.v1.Version - (*PluginID)(nil), // 1: plugin.v1.PluginID - (*PluginConfig)(nil), // 2: plugin.v1.PluginConfig - nil, // 3: plugin.v1.PluginConfig.ConfigEntry - nil, // 4: plugin.v1.PluginConfig.RequiresEntry - (*structpb.Struct)(nil), // 5: google.protobuf.Struct + (*PluginID)(nil), // 0: plugin.v1.PluginID + (*PluginConfig)(nil), // 1: plugin.v1.PluginConfig + nil, // 2: plugin.v1.PluginConfig.ConfigEntry + nil, // 3: plugin.v1.PluginConfig.RequiresEntry + (*structpb.Struct)(nil), // 4: google.protobuf.Struct } var file_plugin_v1_plugin_proto_depIdxs = []int32{ - 1, // 0: plugin.v1.PluginConfig.id:type_name -> plugin.v1.PluginID - 3, // 1: plugin.v1.PluginConfig.config:type_name -> plugin.v1.PluginConfig.ConfigEntry - 4, // 2: plugin.v1.PluginConfig.requires:type_name -> plugin.v1.PluginConfig.RequiresEntry - 5, // 3: plugin.v1.GatewayDPluginService.GetPluginConfig:input_type -> google.protobuf.Struct - 5, // 4: plugin.v1.GatewayDPluginService.OnConfigLoaded:input_type -> google.protobuf.Struct - 5, // 5: plugin.v1.GatewayDPluginService.OnNewLogger:input_type -> google.protobuf.Struct - 5, // 6: plugin.v1.GatewayDPluginService.OnNewPool:input_type -> google.protobuf.Struct - 5, // 7: plugin.v1.GatewayDPluginService.OnNewProxy:input_type -> google.protobuf.Struct - 5, // 8: plugin.v1.GatewayDPluginService.OnNewServer:input_type -> google.protobuf.Struct - 5, // 9: plugin.v1.GatewayDPluginService.OnSignal:input_type -> google.protobuf.Struct - 5, // 10: plugin.v1.GatewayDPluginService.OnRun:input_type -> google.protobuf.Struct - 5, // 11: plugin.v1.GatewayDPluginService.OnBooting:input_type -> google.protobuf.Struct - 5, // 12: plugin.v1.GatewayDPluginService.OnBooted:input_type -> google.protobuf.Struct - 5, // 13: plugin.v1.GatewayDPluginService.OnOpening:input_type -> google.protobuf.Struct - 5, // 14: plugin.v1.GatewayDPluginService.OnOpened:input_type -> google.protobuf.Struct - 5, // 15: plugin.v1.GatewayDPluginService.OnClosing:input_type -> google.protobuf.Struct - 5, // 16: plugin.v1.GatewayDPluginService.OnClosed:input_type -> google.protobuf.Struct - 5, // 17: plugin.v1.GatewayDPluginService.OnTraffic:input_type -> google.protobuf.Struct - 5, // 18: plugin.v1.GatewayDPluginService.OnIngressTraffic:input_type -> google.protobuf.Struct - 5, // 19: plugin.v1.GatewayDPluginService.OnEgressTraffic:input_type -> google.protobuf.Struct - 5, // 20: plugin.v1.GatewayDPluginService.OnShutdown:input_type -> google.protobuf.Struct - 5, // 21: plugin.v1.GatewayDPluginService.OnTick:input_type -> google.protobuf.Struct - 5, // 22: plugin.v1.GatewayDPluginService.OnNewClient:input_type -> google.protobuf.Struct - 5, // 23: plugin.v1.GatewayDPluginService.GetPluginConfig:output_type -> google.protobuf.Struct - 5, // 24: plugin.v1.GatewayDPluginService.OnConfigLoaded:output_type -> google.protobuf.Struct - 5, // 25: plugin.v1.GatewayDPluginService.OnNewLogger:output_type -> google.protobuf.Struct - 5, // 26: plugin.v1.GatewayDPluginService.OnNewPool:output_type -> google.protobuf.Struct - 5, // 27: plugin.v1.GatewayDPluginService.OnNewProxy:output_type -> google.protobuf.Struct - 5, // 28: plugin.v1.GatewayDPluginService.OnNewServer:output_type -> google.protobuf.Struct - 5, // 29: plugin.v1.GatewayDPluginService.OnSignal:output_type -> google.protobuf.Struct - 5, // 30: plugin.v1.GatewayDPluginService.OnRun:output_type -> google.protobuf.Struct - 5, // 31: plugin.v1.GatewayDPluginService.OnBooting:output_type -> google.protobuf.Struct - 5, // 32: plugin.v1.GatewayDPluginService.OnBooted:output_type -> google.protobuf.Struct - 5, // 33: plugin.v1.GatewayDPluginService.OnOpening:output_type -> google.protobuf.Struct - 5, // 34: plugin.v1.GatewayDPluginService.OnOpened:output_type -> google.protobuf.Struct - 5, // 35: plugin.v1.GatewayDPluginService.OnClosing:output_type -> google.protobuf.Struct - 5, // 36: plugin.v1.GatewayDPluginService.OnClosed:output_type -> google.protobuf.Struct - 5, // 37: plugin.v1.GatewayDPluginService.OnTraffic:output_type -> google.protobuf.Struct - 5, // 38: plugin.v1.GatewayDPluginService.OnIngressTraffic:output_type -> google.protobuf.Struct - 5, // 39: plugin.v1.GatewayDPluginService.OnEgressTraffic:output_type -> google.protobuf.Struct - 5, // 40: plugin.v1.GatewayDPluginService.OnShutdown:output_type -> google.protobuf.Struct - 5, // 41: plugin.v1.GatewayDPluginService.OnTick:output_type -> google.protobuf.Struct - 5, // 42: plugin.v1.GatewayDPluginService.OnNewClient:output_type -> google.protobuf.Struct - 23, // [23:43] is the sub-list for method output_type - 3, // [3:23] is the sub-list for method input_type + 0, // 0: plugin.v1.PluginConfig.id:type_name -> plugin.v1.PluginID + 2, // 1: plugin.v1.PluginConfig.config:type_name -> plugin.v1.PluginConfig.ConfigEntry + 3, // 2: plugin.v1.PluginConfig.requires:type_name -> plugin.v1.PluginConfig.RequiresEntry + 4, // 3: plugin.v1.GatewayDPluginService.GetPluginConfig:input_type -> google.protobuf.Struct + 4, // 4: plugin.v1.GatewayDPluginService.OnConfigLoaded:input_type -> google.protobuf.Struct + 4, // 5: plugin.v1.GatewayDPluginService.OnNewLogger:input_type -> google.protobuf.Struct + 4, // 6: plugin.v1.GatewayDPluginService.OnNewPool:input_type -> google.protobuf.Struct + 4, // 7: plugin.v1.GatewayDPluginService.OnNewProxy:input_type -> google.protobuf.Struct + 4, // 8: plugin.v1.GatewayDPluginService.OnNewServer:input_type -> google.protobuf.Struct + 4, // 9: plugin.v1.GatewayDPluginService.OnSignal:input_type -> google.protobuf.Struct + 4, // 10: plugin.v1.GatewayDPluginService.OnRun:input_type -> google.protobuf.Struct + 4, // 11: plugin.v1.GatewayDPluginService.OnBooting:input_type -> google.protobuf.Struct + 4, // 12: plugin.v1.GatewayDPluginService.OnBooted:input_type -> google.protobuf.Struct + 4, // 13: plugin.v1.GatewayDPluginService.OnOpening:input_type -> google.protobuf.Struct + 4, // 14: plugin.v1.GatewayDPluginService.OnOpened:input_type -> google.protobuf.Struct + 4, // 15: plugin.v1.GatewayDPluginService.OnClosing:input_type -> google.protobuf.Struct + 4, // 16: plugin.v1.GatewayDPluginService.OnClosed:input_type -> google.protobuf.Struct + 4, // 17: plugin.v1.GatewayDPluginService.OnTraffic:input_type -> google.protobuf.Struct + 4, // 18: plugin.v1.GatewayDPluginService.OnTrafficFromClient:input_type -> google.protobuf.Struct + 4, // 19: plugin.v1.GatewayDPluginService.OnTrafficToServer:input_type -> google.protobuf.Struct + 4, // 20: plugin.v1.GatewayDPluginService.OnTrafficFromServer:input_type -> google.protobuf.Struct + 4, // 21: plugin.v1.GatewayDPluginService.OnTrafficToClient:input_type -> google.protobuf.Struct + 4, // 22: plugin.v1.GatewayDPluginService.OnShutdown:input_type -> google.protobuf.Struct + 4, // 23: plugin.v1.GatewayDPluginService.OnTick:input_type -> google.protobuf.Struct + 4, // 24: plugin.v1.GatewayDPluginService.OnNewClient:input_type -> google.protobuf.Struct + 4, // 25: plugin.v1.GatewayDPluginService.GetPluginConfig:output_type -> google.protobuf.Struct + 4, // 26: plugin.v1.GatewayDPluginService.OnConfigLoaded:output_type -> google.protobuf.Struct + 4, // 27: plugin.v1.GatewayDPluginService.OnNewLogger:output_type -> google.protobuf.Struct + 4, // 28: plugin.v1.GatewayDPluginService.OnNewPool:output_type -> google.protobuf.Struct + 4, // 29: plugin.v1.GatewayDPluginService.OnNewProxy:output_type -> google.protobuf.Struct + 4, // 30: plugin.v1.GatewayDPluginService.OnNewServer:output_type -> google.protobuf.Struct + 4, // 31: plugin.v1.GatewayDPluginService.OnSignal:output_type -> google.protobuf.Struct + 4, // 32: plugin.v1.GatewayDPluginService.OnRun:output_type -> google.protobuf.Struct + 4, // 33: plugin.v1.GatewayDPluginService.OnBooting:output_type -> google.protobuf.Struct + 4, // 34: plugin.v1.GatewayDPluginService.OnBooted:output_type -> google.protobuf.Struct + 4, // 35: plugin.v1.GatewayDPluginService.OnOpening:output_type -> google.protobuf.Struct + 4, // 36: plugin.v1.GatewayDPluginService.OnOpened:output_type -> google.protobuf.Struct + 4, // 37: plugin.v1.GatewayDPluginService.OnClosing:output_type -> google.protobuf.Struct + 4, // 38: plugin.v1.GatewayDPluginService.OnClosed:output_type -> google.protobuf.Struct + 4, // 39: plugin.v1.GatewayDPluginService.OnTraffic:output_type -> google.protobuf.Struct + 4, // 40: plugin.v1.GatewayDPluginService.OnTrafficFromClient:output_type -> google.protobuf.Struct + 4, // 41: plugin.v1.GatewayDPluginService.OnTrafficToServer:output_type -> google.protobuf.Struct + 4, // 42: plugin.v1.GatewayDPluginService.OnTrafficFromServer:output_type -> google.protobuf.Struct + 4, // 43: plugin.v1.GatewayDPluginService.OnTrafficToClient:output_type -> google.protobuf.Struct + 4, // 44: plugin.v1.GatewayDPluginService.OnShutdown:output_type -> google.protobuf.Struct + 4, // 45: plugin.v1.GatewayDPluginService.OnTick:output_type -> google.protobuf.Struct + 4, // 46: plugin.v1.GatewayDPluginService.OnNewClient:output_type -> google.protobuf.Struct + 25, // [25:47] is the sub-list for method output_type + 3, // [3:25] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name @@ -523,18 +439,6 @@ func file_plugin_v1_plugin_proto_init() { } if !protoimpl.UnsafeEnabled { file_plugin_v1_plugin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Version); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_plugin_v1_plugin_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PluginID); i { case 0: return &v.state @@ -546,7 +450,7 @@ func file_plugin_v1_plugin_proto_init() { return nil } } - file_plugin_v1_plugin_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_plugin_v1_plugin_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PluginConfig); i { case 0: return &v.state @@ -565,7 +469,7 @@ func file_plugin_v1_plugin_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_plugin_v1_plugin_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/plugin/v1/plugin.proto b/plugin/v1/plugin.proto index cef887e0..5c370b62 100644 --- a/plugin/v1/plugin.proto +++ b/plugin/v1/plugin.proto @@ -25,22 +25,15 @@ service GatewayDPluginService { rpc OnClosing (google.protobuf.Struct) returns (google.protobuf.Struct); rpc OnClosed (google.protobuf.Struct) returns (google.protobuf.Struct); rpc OnTraffic (google.protobuf.Struct) returns (google.protobuf.Struct); - rpc OnIngressTraffic (google.protobuf.Struct) returns (google.protobuf.Struct); - rpc OnEgressTraffic (google.protobuf.Struct) returns (google.protobuf.Struct); + rpc OnTrafficFromClient (google.protobuf.Struct) returns (google.protobuf.Struct); + rpc OnTrafficToServer (google.protobuf.Struct) returns (google.protobuf.Struct); + rpc OnTrafficFromServer (google.protobuf.Struct) returns (google.protobuf.Struct); + rpc OnTrafficToClient (google.protobuf.Struct) returns (google.protobuf.Struct); rpc OnShutdown (google.protobuf.Struct) returns (google.protobuf.Struct); rpc OnTick (google.protobuf.Struct) returns (google.protobuf.Struct); rpc OnNewClient (google.protobuf.Struct) returns (google.protobuf.Struct); } -message Version { - uint64 major = 1; - uint64 minor = 2; - uint64 patch = 3; - string pre = 4; - string metadata = 5; - string original = 6; -} - message PluginID { string name = 1; string version = 2; diff --git a/plugin/v1/plugin_grpc.pb.go b/plugin/v1/plugin_grpc.pb.go index 3c1487ed..1a21da26 100644 --- a/plugin/v1/plugin_grpc.pb.go +++ b/plugin/v1/plugin_grpc.pb.go @@ -40,8 +40,10 @@ type GatewayDPluginServiceClient interface { OnClosing(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) OnClosed(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) OnTraffic(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) - OnIngressTraffic(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) - OnEgressTraffic(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) + OnTrafficFromClient(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) + OnTrafficToServer(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) + OnTrafficFromServer(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) + OnTrafficToClient(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) OnShutdown(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) OnTick(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) OnNewClient(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) @@ -190,18 +192,36 @@ func (c *gatewayDPluginServiceClient) OnTraffic(ctx context.Context, in *structp return out, nil } -func (c *gatewayDPluginServiceClient) OnIngressTraffic(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { +func (c *gatewayDPluginServiceClient) OnTrafficFromClient(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { out := new(structpb.Struct) - err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnIngressTraffic", in, out, opts...) + err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnTrafficFromClient", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *gatewayDPluginServiceClient) OnEgressTraffic(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { +func (c *gatewayDPluginServiceClient) OnTrafficToServer(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { out := new(structpb.Struct) - err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnEgressTraffic", in, out, opts...) + err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnTrafficToServer", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *gatewayDPluginServiceClient) OnTrafficFromServer(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { + out := new(structpb.Struct) + err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnTrafficFromServer", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *gatewayDPluginServiceClient) OnTrafficToClient(ctx context.Context, in *structpb.Struct, opts ...grpc.CallOption) (*structpb.Struct, error) { + out := new(structpb.Struct) + err := c.cc.Invoke(ctx, "/plugin.v1.GatewayDPluginService/OnTrafficToClient", in, out, opts...) if err != nil { return nil, err } @@ -256,8 +276,10 @@ type GatewayDPluginServiceServer interface { OnClosing(context.Context, *structpb.Struct) (*structpb.Struct, error) OnClosed(context.Context, *structpb.Struct) (*structpb.Struct, error) OnTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) - OnIngressTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) - OnEgressTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) + OnTrafficFromClient(context.Context, *structpb.Struct) (*structpb.Struct, error) + OnTrafficToServer(context.Context, *structpb.Struct) (*structpb.Struct, error) + OnTrafficFromServer(context.Context, *structpb.Struct) (*structpb.Struct, error) + OnTrafficToClient(context.Context, *structpb.Struct) (*structpb.Struct, error) OnShutdown(context.Context, *structpb.Struct) (*structpb.Struct, error) OnTick(context.Context, *structpb.Struct) (*structpb.Struct, error) OnNewClient(context.Context, *structpb.Struct) (*structpb.Struct, error) @@ -313,11 +335,17 @@ func (UnimplementedGatewayDPluginServiceServer) OnClosed(context.Context, *struc func (UnimplementedGatewayDPluginServiceServer) OnTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) { return nil, status.Errorf(codes.Unimplemented, "method OnTraffic not implemented") } -func (UnimplementedGatewayDPluginServiceServer) OnIngressTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) { - return nil, status.Errorf(codes.Unimplemented, "method OnIngressTraffic not implemented") +func (UnimplementedGatewayDPluginServiceServer) OnTrafficFromClient(context.Context, *structpb.Struct) (*structpb.Struct, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnTrafficFromClient not implemented") +} +func (UnimplementedGatewayDPluginServiceServer) OnTrafficToServer(context.Context, *structpb.Struct) (*structpb.Struct, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnTrafficToServer not implemented") } -func (UnimplementedGatewayDPluginServiceServer) OnEgressTraffic(context.Context, *structpb.Struct) (*structpb.Struct, error) { - return nil, status.Errorf(codes.Unimplemented, "method OnEgressTraffic not implemented") +func (UnimplementedGatewayDPluginServiceServer) OnTrafficFromServer(context.Context, *structpb.Struct) (*structpb.Struct, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnTrafficFromServer not implemented") +} +func (UnimplementedGatewayDPluginServiceServer) OnTrafficToClient(context.Context, *structpb.Struct) (*structpb.Struct, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnTrafficToClient not implemented") } func (UnimplementedGatewayDPluginServiceServer) OnShutdown(context.Context, *structpb.Struct) (*structpb.Struct, error) { return nil, status.Errorf(codes.Unimplemented, "method OnShutdown not implemented") @@ -611,38 +639,74 @@ func _GatewayDPluginService_OnTraffic_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } -func _GatewayDPluginService_OnIngressTraffic_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _GatewayDPluginService_OnTrafficFromClient_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(structpb.Struct) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GatewayDPluginServiceServer).OnTrafficFromClient(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/plugin.v1.GatewayDPluginService/OnTrafficFromClient", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GatewayDPluginServiceServer).OnTrafficFromClient(ctx, req.(*structpb.Struct)) + } + return interceptor(ctx, in, info, handler) +} + +func _GatewayDPluginService_OnTrafficToServer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(structpb.Struct) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GatewayDPluginServiceServer).OnTrafficToServer(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/plugin.v1.GatewayDPluginService/OnTrafficToServer", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GatewayDPluginServiceServer).OnTrafficToServer(ctx, req.(*structpb.Struct)) + } + return interceptor(ctx, in, info, handler) +} + +func _GatewayDPluginService_OnTrafficFromServer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(structpb.Struct) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GatewayDPluginServiceServer).OnIngressTraffic(ctx, in) + return srv.(GatewayDPluginServiceServer).OnTrafficFromServer(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/plugin.v1.GatewayDPluginService/OnIngressTraffic", + FullMethod: "/plugin.v1.GatewayDPluginService/OnTrafficFromServer", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GatewayDPluginServiceServer).OnIngressTraffic(ctx, req.(*structpb.Struct)) + return srv.(GatewayDPluginServiceServer).OnTrafficFromServer(ctx, req.(*structpb.Struct)) } return interceptor(ctx, in, info, handler) } -func _GatewayDPluginService_OnEgressTraffic_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _GatewayDPluginService_OnTrafficToClient_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(structpb.Struct) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GatewayDPluginServiceServer).OnEgressTraffic(ctx, in) + return srv.(GatewayDPluginServiceServer).OnTrafficToClient(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/plugin.v1.GatewayDPluginService/OnEgressTraffic", + FullMethod: "/plugin.v1.GatewayDPluginService/OnTrafficToClient", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GatewayDPluginServiceServer).OnEgressTraffic(ctx, req.(*structpb.Struct)) + return srv.(GatewayDPluginServiceServer).OnTrafficToClient(ctx, req.(*structpb.Struct)) } return interceptor(ctx, in, info, handler) } @@ -769,12 +833,20 @@ var GatewayDPluginService_ServiceDesc = grpc.ServiceDesc{ Handler: _GatewayDPluginService_OnTraffic_Handler, }, { - MethodName: "OnIngressTraffic", - Handler: _GatewayDPluginService_OnIngressTraffic_Handler, + MethodName: "OnTrafficFromClient", + Handler: _GatewayDPluginService_OnTrafficFromClient_Handler, + }, + { + MethodName: "OnTrafficToServer", + Handler: _GatewayDPluginService_OnTrafficToServer_Handler, + }, + { + MethodName: "OnTrafficFromServer", + Handler: _GatewayDPluginService_OnTrafficFromServer_Handler, }, { - MethodName: "OnEgressTraffic", - Handler: _GatewayDPluginService_OnEgressTraffic_Handler, + MethodName: "OnTrafficToClient", + Handler: _GatewayDPluginService_OnTrafficToClient_Handler, }, { MethodName: "OnShutdown", From b77f7a76dbc877daec5b4fb4b0b0c4d379984ea9 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:02:12 +0100 Subject: [PATCH 11/15] Update PassThrough function to accommodate for the new traffic hooks Add traffic termination logic, so that plugins can return a response before sending anything to the server Add a new error for plugins terminating the connections Created a few local functions inside the PassThrough function, which needs to be refactored --- errors/errors.go | 3 + network/proxy.go | 222 +++++++++++++++++++++++++++++++--------------- network/server.go | 1 + 3 files changed, 155 insertions(+), 71 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index 4c791de0..a84fdb67 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -23,6 +23,7 @@ const ( ErrCodeCastFailed ErrCodeHookVerificationFailed ErrCodeHookReturnedError + ErrCodeHookTerminatedConnection ErrCodeFileNotFound ErrCodeFileOpenFailed ErrCodeFileReadFailed @@ -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) diff --git a/network/proxy.go b/network/proxy.go index 2f3503fa..4799e9d1 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -2,6 +2,7 @@ package network import ( "context" + "fmt" "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" @@ -170,7 +171,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // Currently the passthrough is a one-way street from the client to the server, that is, // the client can send data to the server and receive the response back, but the server // cannot take initiative and send data to the client. So, there should be another event-loop - // that listens for data from the server and sends it to the client + // that listens for data from the server and sends it to the client. var client *Client if pr.busyConnections.Get(gconn) == nil { @@ -184,64 +185,166 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { return gerr.ErrCastFailed } - // request contains the data from the client. - request, origErr := gconn.Next(-1) - if origErr != nil { - pr.logger.Error().Err(origErr).Msg("Error reading from client") + // receiveTrafficFromClient is a function that receives data from the client. + receiveTrafficFromClient := func() ([]byte, error) { + // request contains the data from the client. + request, err := gconn.Next(-1) + if err != nil { + pr.logger.Error().Err(err).Msg("Error reading from client") + } + pr.logger.Debug().Fields( + map[string]interface{}{ + "length": len(request), + "local": gconn.LocalAddr().String(), + "remote": gconn.RemoteAddr().String(), + }, + ).Msg("Received data from client") + + return request, err } - pr.logger.Debug().Fields( - map[string]interface{}{ - "length": len(request), - "local": gconn.LocalAddr().String(), - "remote": gconn.RemoteAddr().String(), - }, - ).Msg("Received data from client") - // Run the OnIngressTraffic hooks. + // sendTrafficToServer is a function that sends data to the server. + sendTrafficToServer := func(request []byte) (int, *gerr.GatewayDError) { + // Send the request to the server. + sent, err := client.Send(request) + if err != nil { + pr.logger.Error().Err(err).Msg("Error sending request to database") + } + pr.logger.Debug().Fields( + map[string]interface{}{ + "function": "proxy.passthrough", + "length": sent, + "local": client.Conn.LocalAddr().String(), + "remote": client.Conn.RemoteAddr().String(), + }, + ).Msg("Sent data to database") + + return sent, err + } + + // receiveTrafficFromServer is a function that receives data from the server. + receiveTrafficFromServer := func() (int, []byte, *gerr.GatewayDError) { + // Receive the response from the server. + received, response, err := client.Receive() + pr.logger.Debug().Fields( + map[string]interface{}{ + "function": "proxy.passthrough", + "length": received, + "local": client.Conn.LocalAddr().String(), + "remote": client.Conn.RemoteAddr().String(), + }, + ).Msg("Received data from database") + + return received, response, err + } + + // sendTrafficToClient is a function that sends data to the client. + sendTrafficToClient := func(response []byte, received int) *gerr.GatewayDError { + // Send the response to the client async. + origErr := gconn.AsyncWrite(response[:received], func(gconn gnet.Conn, err error) error { + pr.logger.Debug().Fields( + map[string]interface{}{ + "function": "proxy.passthrough", + "length": received, + "local": gconn.LocalAddr().String(), + "remote": gconn.RemoteAddr().String(), + }, + ).Msg("Sent data to client") + return err + }) + if origErr != nil { + pr.logger.Error().Err(origErr).Msg("Error writing to client") + return gerr.ErrServerSendFailed.Wrap(origErr) + } + + return nil + } + + // shouldTerminate is a function that retrieves the terminate field from the hook result. + // Only the OnTrafficFromClient hook will terminate the connection. + shouldTerminate := func(result map[string]interface{}) bool { + fmt.Println("result", result) + // If the hook wants to terminate the connection, do it. + if result != nil { + if terminate, ok := result["terminate"].(bool); ok && terminate { + pr.logger.Debug().Str("function", "proxy.passthrough").Msg("Terminating connection") + return true + } + } + + return false + } + + // getPluginModifiedRequest is a function that retrieves the modified request + // from the hook result. + getPluginModifiedRequest := func(result map[string]interface{}) []byte { + // If the hook modified the request, use the modified request. + if modRequest, errMsg, convErr := extractFieldValue(result, "request"); errMsg != "" { + pr.logger.Error().Str("error", errMsg).Msg("Error in hook") + } else if convErr != nil { + pr.logger.Error().Err(convErr).Msg("Error in data conversion") + } else if modRequest != nil { + return modRequest + } + + return nil + } + + // getPluginModifiedResponse is a function that retrieves the modified response + // from the hook result. + getPluginModifiedResponse := func(result map[string]interface{}) ([]byte, int) { + // If the hook returns a response, use it instead of the original response. + if modResponse, errMsg, convErr := extractFieldValue(result, "response"); errMsg != "" { + pr.logger.Error().Str("error", errMsg).Msg("Error in hook") + } else if convErr != nil { + pr.logger.Error().Err(convErr).Msg("Error in data conversion") + } else if modResponse != nil { + return modResponse, len(modResponse) + } + + return nil, 0 + } + + // Receive the request from the client. + request, origErr := receiveTrafficFromClient() + + // Run the OnTrafficFromClient hooks. result, err := pr.hookConfig.Run( context.Background(), trafficData(gconn, client, "request", request, origErr), - hook.OnIngressTraffic, + hook.OnTrafficFromClient, pr.hookConfig.Verification) if err != nil { pr.logger.Error().Err(err).Msg("Error running hook") } - // If the hook modified the request, use the modified request. - modRequest, errMsg, convErr := extractFieldValue(result, "request") - if errMsg != "" { - pr.logger.Error().Str("error", errMsg).Msg("Error in hook") - } - if convErr != nil { - pr.logger.Error().Err(convErr).Msg("Error in data conversion") + // If the hook wants to terminate the connection, do it. + if shouldTerminate(result) { + if modResponse, modReceived := getPluginModifiedResponse(result); modResponse != nil { + return sendTrafficToClient(modResponse, modReceived) + } else { + return gerr.ErrHookTerminatedConnection.Wrap(err) + } } - if modRequest != nil { + // If the hook modified the request, use the modified request. + if modRequest := getPluginModifiedRequest(result); modRequest != nil { request = modRequest } // Send the request to the server. - sent, err := client.Send(request) + sendTrafficToServer(request) + + // Run the OnTrafficToServer hooks. + _, err = pr.hookConfig.Run( + context.Background(), + trafficData(gconn, client, "request", request, origErr), + hook.OnTrafficToServer, + pr.hookConfig.Verification) if err != nil { - pr.logger.Error().Err(err).Msg("Error sending request to database") + pr.logger.Error().Err(err).Msg("Error running hook") } - pr.logger.Debug().Fields( - map[string]interface{}{ - "function": "proxy.passthrough", - "length": sent, - "local": client.Conn.LocalAddr().String(), - "remote": client.Conn.RemoteAddr().String(), - }, - ).Msg("Sent data to database") // Receive the response from the server. - received, response, err := client.Receive() - pr.logger.Debug().Fields( - map[string]interface{}{ - "function": "proxy.passthrough", - "length": received, - "local": client.Conn.LocalAddr().String(), - "remote": client.Conn.RemoteAddr().String(), - }, - ).Msg("Received data from database") + received, response, err := receiveTrafficFromServer() // The connection to the server is closed, so we MUST reconnect, // otherwise the client will be stuck. @@ -273,46 +376,23 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { return err } - // Run the OnEgressTraffic hooks. + // Run the OnTrafficFromServer hooks. result, err = pr.hookConfig.Run( context.Background(), trafficData(gconn, client, "response", response[:received], err), - hook.OnEgressTraffic, + hook.OnTrafficFromServer, pr.hookConfig.Verification) if err != nil { pr.logger.Error().Err(err).Msg("Error running hook") } - // If the hook returns a response, use it instead of the original response. - modResponse, errMsg, convErr := extractFieldValue(result, "response") - if errMsg != "" { - pr.logger.Error().Str("error", errMsg).Msg("Error in hook") - } - if convErr != nil { - pr.logger.Error().Err(convErr).Msg("Error in data conversion") - } - if modResponse != nil { + // If the hook modified the response, use the modified response. + if modResponse, modReceived := getPluginModifiedResponse(result); modResponse != nil { response = modResponse - received = len(modResponse) + received = modReceived } - // Send the response to the client async. - origErr = gconn.AsyncWrite(response[:received], func(gconn gnet.Conn, err error) error { - pr.logger.Debug().Fields( - map[string]interface{}{ - "function": "proxy.passthrough", - "length": received, - "local": gconn.LocalAddr().String(), - "remote": gconn.RemoteAddr().String(), - }, - ).Msg("Sent data to client") - return err - }) - if origErr != nil { - pr.logger.Error().Err(err).Msg("Error writing to client") - return gerr.ErrServerSendFailed.Wrap(err) - } - - return nil + // Send the response to the client. + return sendTrafficToClient(response, received) } // IsHealty checks if the pool is exhausted or the client is disconnected. diff --git a/network/server.go b/network/server.go index 2188b5df..fdbb1d37 100644 --- a/network/server.go +++ b/network/server.go @@ -215,6 +215,7 @@ func (s *Server) OnTraffic(gconn gnet.Conn) gnet.Action { errors.Is(err, gerr.ErrClientNotConnected), errors.Is(err, gerr.ErrClientSendFailed), errors.Is(err, gerr.ErrClientReceiveFailed), + errors.Is(err, gerr.ErrHookTerminatedConnection), errors.Is(err.Unwrap(), io.EOF): return gnet.Close } From 26f4fbecf5e3fb4734f84e43ec1c987e2211147a Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:05:51 +0100 Subject: [PATCH 12/15] Update tests to match the new hook names --- network/server_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/network/server_test.go b/network/server_test.go index 5028527f..a72f4dd7 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -41,7 +41,7 @@ func TestRunServer(t *testing.T) { hooksConfig := hook.NewHookConfig() - onIngressTraffic := func( + onTrafficFromClient := func( ctx context.Context, params *structpb.Struct, opts ...grpc.CallOption, @@ -67,9 +67,9 @@ func TestRunServer(t *testing.T) { assert.Empty(t, paramsMap["error"]) return params, nil } - hooksConfig.Add(hook.OnIngressTraffic, 1, onIngressTraffic) + hooksConfig.Add(hook.OnTrafficFromClient, 1, onTrafficFromClient) - onEgressTraffic := func( + onTrafficFromServer := func( ctx context.Context, params *structpb.Struct, opts ...grpc.CallOption, @@ -92,7 +92,7 @@ func TestRunServer(t *testing.T) { assert.Empty(t, paramsMap["error"]) return params, nil } - hooksConfig.Add(hook.OnEgressTraffic, 1, onEgressTraffic) + hooksConfig.Add(hook.OnTrafficFromServer, 1, onTrafficFromServer) clientConfig := config.Client{ Network: "tcp", From d938be2d396997e6de8d0bdb408d67a1e8c19ba3 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:06:05 +0100 Subject: [PATCH 13/15] Update plugin checksum --- gatewayd_plugins.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayd_plugins.yaml b/gatewayd_plugins.yaml index 79da93c9..09cdcf1e 100644 --- a/gatewayd_plugins.yaml +++ b/gatewayd_plugins.yaml @@ -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 From fcb8109878242cc38839a13a754962bff5e1172c Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:15:23 +0100 Subject: [PATCH 14/15] Fix linter errors --- network/proxy.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/network/proxy.go b/network/proxy.go index 4799e9d1..7d2c477b 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -2,7 +2,6 @@ package network import ( "context" - "fmt" "github.com/gatewayd-io/gatewayd/config" gerr "github.com/gatewayd-io/gatewayd/errors" @@ -165,7 +164,9 @@ func (pr *Proxy) Disconnect(gconn gnet.Conn) *gerr.GatewayDError { // PassThrough sends the data from the client to the server and vice versa. // -//nolint:funlen +// TODO: refactor this mess! My eye burns even looking at it. +// +//nolint:funlen,maintidx func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // TODO: Handle bi-directional traffic // Currently the passthrough is a one-way street from the client to the server, that is, @@ -200,6 +201,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { }, ).Msg("Received data from client") + //nolint:wrapcheck return request, err } @@ -263,7 +265,6 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // shouldTerminate is a function that retrieves the terminate field from the hook result. // Only the OnTrafficFromClient hook will terminate the connection. shouldTerminate := func(result map[string]interface{}) bool { - fmt.Println("result", result) // If the hook wants to terminate the connection, do it. if result != nil { if terminate, ok := result["terminate"].(bool); ok && terminate { @@ -279,6 +280,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // from the hook result. getPluginModifiedRequest := func(result map[string]interface{}) []byte { // If the hook modified the request, use the modified request. + //nolint:gocritic if modRequest, errMsg, convErr := extractFieldValue(result, "request"); errMsg != "" { pr.logger.Error().Str("error", errMsg).Msg("Error in hook") } else if convErr != nil { @@ -294,6 +296,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // from the hook result. getPluginModifiedResponse := func(result map[string]interface{}) ([]byte, int) { // If the hook returns a response, use it instead of the original response. + //nolint:gocritic if modResponse, errMsg, convErr := extractFieldValue(result, "response"); errMsg != "" { pr.logger.Error().Str("error", errMsg).Msg("Error in hook") } else if convErr != nil { @@ -321,9 +324,8 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { if shouldTerminate(result) { if modResponse, modReceived := getPluginModifiedResponse(result); modResponse != nil { return sendTrafficToClient(modResponse, modReceived) - } else { - return gerr.ErrHookTerminatedConnection.Wrap(err) } + return gerr.ErrHookTerminatedConnection } // If the hook modified the request, use the modified request. if modRequest := getPluginModifiedRequest(result); modRequest != nil { @@ -331,12 +333,12 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { } // Send the request to the server. - sendTrafficToServer(request) + _, err = sendTrafficToServer(request) // Run the OnTrafficToServer hooks. _, err = pr.hookConfig.Run( context.Background(), - trafficData(gconn, client, "request", request, origErr), + trafficData(gconn, client, "request", request, err.Unwrap().Error()), hook.OnTrafficToServer, pr.hookConfig.Verification) if err != nil { From 6c7f64d66e0dcb70d88db391aa0d4d5c0b3693a5 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 10 Jan 2023 01:21:22 +0100 Subject: [PATCH 15/15] Fix nil pointer dereference error --- network/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/proxy.go b/network/proxy.go index 7d2c477b..d4070501 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -338,7 +338,7 @@ func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError { // Run the OnTrafficToServer hooks. _, err = pr.hookConfig.Run( context.Background(), - trafficData(gconn, client, "request", request, err.Unwrap().Error()), + trafficData(gconn, client, "request", request, err), hook.OnTrafficToServer, pr.hookConfig.Verification) if err != nil {