diff --git a/ee/tables/dataflattentable/exec.go b/ee/tables/dataflattentable/exec.go index 4fa18c915..a37e9f7f2 100644 --- a/ee/tables/dataflattentable/exec.go +++ b/ee/tables/dataflattentable/exec.go @@ -1,13 +1,10 @@ package dataflattentable import ( - "bytes" "context" - "fmt" "os" "strings" - "time" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" @@ -64,7 +61,7 @@ func TablePluginExec(logger log.Logger, tableName string, dataSourceType DataSou func (t *Table) generateExec(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) { var results []map[string]string - execBytes, err := t.exec(ctx) + execBytes, err := tablehelpers.Exec(ctx, t.logger, 50, t.cmdGen, t.execArgs, false) if err != nil { // exec will error if there's no binary, so we never want to record that if os.IsNotExist(errors.Cause(err)) { @@ -94,30 +91,3 @@ func (t *Table) generateExec(ctx context.Context, queryContext table.QueryContex return results, nil } - -func (t *Table) exec(ctx context.Context) ([]byte, error) { - ctx, cancel := context.WithTimeout(ctx, 50*time.Second) - defer cancel() - - var stdout bytes.Buffer - var stderr bytes.Buffer - - cmd, err := t.cmdGen(ctx, t.execArgs...) - if err != nil { - return nil, fmt.Errorf("creating command: %w", err) - } - - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - level.Debug(t.logger).Log("msg", "calling %s", "args", cmd.String()) - - if err := cmd.Run(); os.IsNotExist(err) { - return nil, fmt.Errorf("command %s not found: %w", cmd.Path, err) - } else if err != nil { - return nil, fmt.Errorf("calling %s. Got: %s: %w", cmd.Path, stderr.String(), err) - } - - // success! - return stdout.Bytes(), nil -} diff --git a/ee/tables/secedit/secedit.go b/ee/tables/secedit/secedit.go index c9bb7d278..0cf99a62f 100644 --- a/ee/tables/secedit/secedit.go +++ b/ee/tables/secedit/secedit.go @@ -4,7 +4,6 @@ package secedit import ( - "bytes" "context" "fmt" "io" @@ -12,7 +11,6 @@ import ( "path/filepath" "strconv" "strings" - "time" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" @@ -96,28 +94,14 @@ func (t *Table) execSecedit(ctx context.Context, mergedPolicy bool) ([]byte, err defer os.RemoveAll(dir) dst := filepath.Join(dir, "tmpfile.ini") - var stdout bytes.Buffer - var stderr bytes.Buffer - - ctx, cancel := context.WithTimeout(ctx, 30*time.Second) - defer cancel() args := []string{"/export", "/cfg", dst} if mergedPolicy { args = append(args, "/mergedpolicy") } - cmd, err := allowedcmd.Secedit(ctx, args...) - if err != nil { - return nil, fmt.Errorf("creating secedit command: %w", err) - } - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - level.Debug(t.logger).Log("msg", "calling secedit", "args", cmd.Args) - - if err := cmd.Run(); err != nil { - return nil, fmt.Errorf("calling secedit. Got: %s: %w", stderr.String(), err) + if out, err := tablehelpers.Exec(ctx, t.logger, 30, allowedcmd.Secedit, args, true); err != nil { + return nil, fmt.Errorf("calling secedit. Got: %s: %w", string(out), err) } file, err := os.Open(dst)