Skip to content

Commit

Permalink
lightning: just don't log "received task config" in server mode
Browse files Browse the repository at this point in the history
Signed-off-by: kennytm <kennytm@gmail.com>
  • Loading branch information
kennytm committed Apr 3, 2024
1 parent 970962b commit c7d8d95
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 42 deletions.
3 changes: 1 addition & 2 deletions lightning/pkg/server/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ func (l *Lightning) handlePostTask(w http.ResponseWriter, req *http.Request) {
writeJSONError(w, http.StatusBadRequest, "cannot read request", err)
return
}
filteredData := common.HideSensitive(string(data))
log.L().Info("received task config", zap.String("content", filteredData))
log.L().Info("received task config")

cfg := config.NewConfig()
if err = cfg.LoadFromGlobal(l.globalCfg); err != nil {
Expand Down
8 changes: 0 additions & 8 deletions pkg/lightning/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,3 @@ func IsRaftKV2(ctx context.Context, db *sql.DB) (bool, error) {
}
return false, rows.Err()
}

var passwordRegexp = regexp.MustCompile(`(password[\s]*=[\s]*(\\")?)(.*?)((\\")?\\n)`)

// HideSensitive replace password with ******.
func HideSensitive(input string) string {
output := passwordRegexp.ReplaceAllString(input, "$1******$4")
return output
}
32 changes: 0 additions & 32 deletions pkg/lightning/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,35 +302,3 @@ CREATE TABLE multi_indexes (
require.Equal(t, tt.multiSQLs, multiSQLs)
}
}

func TestHideSensitive(t *testing.T) {
strs := []struct {
old string
new string
}{
{
`host = "127.0.0.1"\n user = "root"\n password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password = ""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password= "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password= ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password =""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password =******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password=""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password=******\n port = 3306\n`,
},
}
for i, str := range strs {
t.Logf("case #%d\n", i)
require.Equal(t, str.new, common.HideSensitive(str.old))
}
}

0 comments on commit c7d8d95

Please sign in to comment.