From dd49d9c3760ebda7e5b0009d4838fcdee89a5be3 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 16:11:57 +0100 Subject: [PATCH 1/6] Add args field --- plugin/plugin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/plugin.go b/plugin/plugin.go index 7628d432..cb81d68f 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -33,6 +33,7 @@ type Impl struct { License string ProjectURL string LocalPath string + Args []string Enabled bool // internal and external config options Config map[string]string From c496789008fe28e2dff6024143d0f4d851db7ddc Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 16:12:32 +0100 Subject: [PATCH 2/6] Add loading of args from the plugin config file --- plugin/registry.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/registry.go b/plugin/registry.go index 9b4f8d6e..738c06b4 100644 --- a/plugin/registry.go +++ b/plugin/registry.go @@ -129,6 +129,13 @@ func (reg *RegistryImpl) LoadPlugins(pluginConfig *koanf.Koanf) { plugin.LocalPath = localPath } + if args, ok := pluginConfig.Get(name + ".args").([]string); !ok || args == nil { + reg.hooksConfig.Logger.Debug().Str("name", name).Msg( + "Commandline args of plugin doesn't exist or is not set") + } else { + plugin.Args = args + } + if checksum, ok := pluginConfig.Get(name + ".checksum").(string); !ok || checksum == "" { reg.hooksConfig.Logger.Debug().Str("name", name).Msg( "Checksum of plugin doesn't exist or is not set") From 3d84d76e62abc8898315af8584b8dc33b3820cb0 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 16:13:51 +0100 Subject: [PATCH 3/6] Add loading of plugin executable with cmd args --- plugin/registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/registry.go b/plugin/registry.go index 738c06b4..dac22b2d 100644 --- a/plugin/registry.go +++ b/plugin/registry.go @@ -170,7 +170,7 @@ func (reg *RegistryImpl) LoadPlugins(pluginConfig *koanf.Koanf) { &goplugin.ClientConfig{ HandshakeConfig: pluginV1.Handshake, Plugins: pluginV1.GetPluginMap(plugin.ID.Name), - Cmd: exec.Command(plugin.LocalPath), //nolint:gosec + Cmd: exec.Command(plugin.LocalPath, plugin.Args...), //nolint:gosec AllowedProtocols: []goplugin.Protocol{ goplugin.ProtocolGRPC, }, From a59e5e2d8601511eaf1bcb2d0d078ec3c7e48b30 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 22:05:19 +0100 Subject: [PATCH 4/6] Fix cast error by using koanf.Strings function --- plugin/registry.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugin/registry.go b/plugin/registry.go index dac22b2d..c0adf32f 100644 --- a/plugin/registry.go +++ b/plugin/registry.go @@ -129,10 +129,7 @@ func (reg *RegistryImpl) LoadPlugins(pluginConfig *koanf.Koanf) { plugin.LocalPath = localPath } - if args, ok := pluginConfig.Get(name + ".args").([]string); !ok || args == nil { - reg.hooksConfig.Logger.Debug().Str("name", name).Msg( - "Commandline args of plugin doesn't exist or is not set") - } else { + if args := pluginConfig.Strings(name + ".args"); len(args) > 0 { plugin.Args = args } From ade464a35c07fe90a1df6f01f452941121047367 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 22:14:37 +0100 Subject: [PATCH 5/6] Pass log-level as cmdline flag to the plugin Update plugin checksum hash --- gatewayd_plugins.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gatewayd_plugins.yaml b/gatewayd_plugins.yaml index de449aec..77467dfa 100644 --- a/gatewayd_plugins.yaml +++ b/gatewayd_plugins.yaml @@ -1,4 +1,5 @@ gatewayd-plugin-test: enabled: True localPath: ../gatewayd-plugin-test/gatewayd-plugin-test - checksum: ca3f75467f022bf0049fb26c604348bb96f97863a5c526ca2808e21daa8c2694 + args: ["--log-level", "info"] + checksum: a20e3a1529f4460ad24416a055d599f6f55f42ead836345a4bf0a17d056abb45 From ff29e6cdbf37483e5fa5aba680c37bc257564890 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 3 Jan 2023 22:21:17 +0100 Subject: [PATCH 6/6] Add comments --- gatewayd_plugins.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gatewayd_plugins.yaml b/gatewayd_plugins.yaml index 77467dfa..23453432 100644 --- a/gatewayd_plugins.yaml +++ b/gatewayd_plugins.yaml @@ -1,5 +1,12 @@ +# Plugin configuration file for GatewayD + +# Plugin name gatewayd-plugin-test: + # whether to enable or disable the plugin on the next run enabled: True + # path to the plugin's binary file localPath: ../gatewayd-plugin-test/gatewayd-plugin-test + # Pass cmdline args to the plugin args: ["--log-level", "info"] + # Checksum hash to verify the binary before loading checksum: a20e3a1529f4460ad24416a055d599f6f55f42ead836345a4bf0a17d056abb45