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" "flag"
"fmt" "fmt"
"io" "io"
"strings"
) )
// WriteFlags writes all the explicitly set flags to w. // WriteFlags writes all the explicitly set flags to w.
func WriteFlags(w io.Writer) { func WriteFlags(w io.Writer) {
flag.Visit(func(f *flag.Flag) { flag.Visit(func(f *flag.Flag) {
lname := strings.ToLower(f.Name)
value := f.Value.String() value := f.Value.String()
if IsSecretFlag(lname) {
value = "secret"
}
fmt.Fprintf(w, "-%s=%q\n", f.Name, value) fmt.Fprintf(w, "-%s=%q\n", f.Name, value)
}) })
} }