Skip to content

Commit

Permalink
hide password (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Jun 5, 2024
1 parent 8ee99e4 commit cd22e72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 18 additions & 1 deletion pkg/environment/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func HistoryRecord(env *Environment, command []string, date time.Time, code int)
}

h := &historyRow{
Command: strings.Join(command, " "),
Command: strings.Join(HidePassword(command), " "),
Date: date,
Code: code,
}
Expand Down Expand Up @@ -242,3 +242,20 @@ func getLatestHistoryFile(dir string) (item historyItem) {

return
}

// HidePassword replace password with ******
func HidePassword(args []string) []string {
var record []string
for i := 0; i < len(args); i++ {
arg := args[i]
if strings.HasPrefix(arg, "-p") && len(arg) > 2 {
record = append(record, "-p******")
} else if arg == "-p" && i+1 < len(args) {
record = append(record, "-p", "******")
i++ // skip next word that may be password
} else {
record = append(record, arg)
}
}
return record
}
6 changes: 4 additions & 2 deletions pkg/exec/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ func RunComponent(env *environment.Environment, tag, spec, binPath string, args
return err
}

fmt.Println("wtf")

if skip, ok := skipStartingMessages[component]; !skip || !ok {
colorstr.Fprintf(os.Stderr, "Starting component [bold]%s[reset]: %s\n", component, strings.Join(c.Args, " "))
colorstr.Fprintf(os.Stderr, "Starting component [bold]%s[reset]: %s\n", component, strings.Join(environment.HidePassword(c.Args), " "))
}

err = c.Start()
Expand Down Expand Up @@ -264,7 +266,7 @@ func saveProcessInfo(p *PrepareCommandParams, c *exec.Cmd) {
CreatedTime: time.Now().Format(time.RFC3339),
Pid: c.Process.Pid,
Exec: c.Args[0],
Args: c.Args,
Args: environment.HidePassword(c.Args),
Dir: p.InstanceDir,
Env: c.Env,
Cmd: c,
Expand Down

0 comments on commit cd22e72

Please sign in to comment.