From fb7d4ebed5c070df736d78bb27cdd7333b8f3cf7 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Mon, 27 Sep 2021 12:40:38 -0400 Subject: [PATCH] Adding ability to handle debugging plugins. (#79) --- transform/binary-plugin/binary_plugin.go | 5 ++--- transform/binary-plugin/binary_plugin_test.go | 2 +- transform/cli/cli.go | 7 +++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/transform/binary-plugin/binary_plugin.go b/transform/binary-plugin/binary_plugin.go index 55086fd..13f8e8f 100644 --- a/transform/binary-plugin/binary_plugin.go +++ b/transform/binary-plugin/binary_plugin.go @@ -23,10 +23,10 @@ type BinaryPlugin struct { } // NewBinaryPlugin - -func NewBinaryPlugin(path string) (transform.Plugin, error) { +func NewBinaryPlugin(path string, logger *logrus.Logger) (transform.Plugin, error) { commandRunner := &binaryRunner{pluginPath: path} - log := logrus.New().WithField("pluginPath", path) + log := logger.WithField("pluginPath", path) out, errBytes, err := commandRunner.Metadata(log) // TODO: Create specific error for command not being run. @@ -166,6 +166,5 @@ func (b *binaryRunner) Run(u *unstructured.Unstructured, extras map[string]strin log.Errorf("unable to run the plugin binary") return nil, nil, fmt.Errorf("unable to run the plugin binary, err: %v", err) } - return out.Bytes(), errorBytes.Bytes(), nil } diff --git a/transform/binary-plugin/binary_plugin_test.go b/transform/binary-plugin/binary_plugin_test.go index 9e5d09c..b54a474 100644 --- a/transform/binary-plugin/binary_plugin_test.go +++ b/transform/binary-plugin/binary_plugin_test.go @@ -271,7 +271,7 @@ func TestNewBinaryPlugin(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cliContext = tt.cliContext - b, err := NewBinaryPlugin(tt.name) + b, err := NewBinaryPlugin(tt.name, logrus.New()) if (err != nil) != tt.wantErr { t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/transform/cli/cli.go b/transform/cli/cli.go index 8e4044c..db1f121 100644 --- a/transform/cli/cli.go +++ b/transform/cli/cli.go @@ -20,6 +20,7 @@ var ( stdOut io.Writer reader io.Reader exiter func(int) + logger *logrus.Logger ) func init() { @@ -28,6 +29,8 @@ func init() { reader = os.Stdin exiter = os.Exit + logger = logrus.New() + logger.SetOutput(stdErr) } type customPlugin struct { @@ -66,8 +69,8 @@ func WriterErrorAndExit(err error) { exiter(1) } -func Logger() logrus.FieldLogger { - return &logrus.Logger{} +func Logger() *logrus.Logger { + return logger } func RunAndExit(plugin transform.Plugin) {