-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/geth, internal/flags: print envvar config source and bad names #28119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,11 @@ import ( | |
"fmt" | ||
"os" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/internal/version" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/mattn/go-isatty" | ||
"github.com/urfave/cli/v2" | ||
|
@@ -263,3 +265,37 @@ func AutoEnvVars(flags []cli.Flag, prefix string) { | |
} | ||
} | ||
} | ||
|
||
// CheckEnvVars iterates over all the environment variables and checks if any of | ||
// them look like a CLI flag but is not consumed. This can be used to detect old | ||
// or mistyped names. | ||
func CheckEnvVars(ctx *cli.Context, flags []cli.Flag, prefix string) { | ||
known := make(map[string]string) | ||
for _, flag := range flags { | ||
docflag, ok := flag.(cli.DocGenerationFlag) | ||
if !ok { | ||
continue | ||
} | ||
for _, envvar := range docflag.GetEnvVars() { | ||
known[envvar] = flag.Names()[0] | ||
} | ||
} | ||
keyvals := os.Environ() | ||
sort.Strings(keyvals) | ||
|
||
for _, keyval := range keyvals { | ||
key := strings.Split(keyval, "=")[0] | ||
if !strings.HasPrefix(key, prefix) { | ||
continue | ||
} | ||
if flag, ok := known[key]; ok { | ||
if ctx.Count(flag) > 0 { | ||
log.Info("Config environment variable found", "envvar", key, "shadowedby", "--"+flag) | ||
} else { | ||
log.Info("Config environment variable found", "envvar", key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some cases. cmd line params are sensitive (password for remote influxdb databases, password for Might not be the best idea -- so far, we've been kind rightfully lax about asking people for their logs, because we know they contain nothing interesting. Ah wait, it's only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, only key for the exact reason. |
||
} | ||
} else { | ||
log.Warn("Unknown config environment variable", "envvar", key) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure. I deliberately left it as GETH only so that if you forget the underscore or use a minus or something it still gets caught. That said, it's mostly a heuristic for now.