Skip to content

Commit

Permalink
fix: don't log certain fields (#5662)
Browse files Browse the repository at this point in the history
* fix: support longer cookie

Signed-off-by: kshamajain99 <[email protected]>

* merge conflicts

Signed-off-by: kshamajain99 <[email protected]>

* fix: don't log certain fields

Signed-off-by: kshamajain99 <[email protected]>
  • Loading branch information
kshamajain99 committed Mar 3, 2021
1 parent be72e7c commit b51ba85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions util/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ func Run(cmd *exec.Cmd) (string, error) {
}

func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string, error) {
opts := argoexec.CmdOpts{Timeout: timeout}
span := tracing.NewLoggingTracer(log.NewLogrusLogger(logrus.New())).StartSpan(fmt.Sprintf("exec %v", cmd.Args[0]))
span.SetBaggageItem("dir", fmt.Sprintf("%v", cmd.Dir))
span.SetBaggageItem("args", fmt.Sprintf("%v", cmd.Args))
defer span.Finish()
opts := argoexec.CmdOpts{Timeout: timeout}
if redactor != nil {
span.SetBaggageItem("args", redactor(fmt.Sprintf("%v", cmd.Args)))
opts.Redactor = redactor
} else {
span.SetBaggageItem("args", fmt.Sprintf("%v", cmd.Args))
}
defer span.Finish()
return argoexec.RunCommandExt(cmd, opts)
}
12 changes: 12 additions & 0 deletions util/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"os"
"os/exec"
"regexp"
"testing"
"time"

Expand All @@ -27,3 +28,14 @@ func TestRun(t *testing.T) {
assert.NoError(t, err)
assert.NotEmpty(t, out)
}

func TestHideUsernamePassword(t *testing.T) {
_, err := RunWithRedactor(exec.Command("helm registry login https://charts.bitnami.com/bitnami", "--username", "foo", "--password", "bar"), nil)
assert.NotEmpty(t, err)

var redactor = func(text string) string {
return regexp.MustCompile("(--username|--password) [^ ]*").ReplaceAllString(text, "$1 ******")
}
_, err = RunWithRedactor(exec.Command("helm registry login https://charts.bitnami.com/bitnami", "--username", "foo", "--password", "bar"), redactor)
assert.NotEmpty(t, err)
}

0 comments on commit b51ba85

Please sign in to comment.