Skip to content

Commit

Permalink
hide other password args (#2436)
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <xw897002528@gmail.com>
  • Loading branch information
xhebox authored Jul 14, 2024
1 parent bac3c2e commit 342c767
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions pkg/environment/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,33 @@ func getLatestHistoryFile(dir string) (item historyItem) {

// HidePassword replace password with ******
func HidePassword(args []string) []string {
var record []string
redactArgs := []string{
// general
"-p",
// dumpling
"--password",
// lightning
"--tidb-password",
}
var r []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)
redacted := false
for _, ra := range redactArgs {
if strings.HasPrefix(arg, ra) && len(arg) > len(ra) {
r = append(r, ra+"******")
redacted = true
break
} else if arg == ra && i+1 < len(args) {
r = append(r, ra, "******")
i++ // skip next word that may be password
redacted = true
break
}
}
if !redacted {
r = append(r, arg)
}
}
return record
return r
}

0 comments on commit 342c767

Please sign in to comment.