lib/flagutil: do not expose sensitive info (passwords, keys and urls) at /flags page

This commit is contained in:
Aliaksandr Valialkin 2021-10-20 00:51:06 +03:00
parent 8ad95f0db7
commit 8991c8b589
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -4,12 +4,17 @@ import (
"flag"
"fmt"
"io"
"strings"
)
// WriteFlags writes all the explicitly set flags to w.
func WriteFlags(w io.Writer) {
flag.Visit(func(f *flag.Flag) {
lname := strings.ToLower(f.Name)
value := f.Value.String()
if IsSecretFlag(lname) {
value = "secret"
}
fmt.Fprintf(w, "-%s=%q\n", f.Name, value)
})
}