Log environment variable keys at startup (#18125)
* Log environment variable keys at startup * run make fmt * change name * add changelog * fix changelog nubmer * fix title * add test * fix message * Update changelog/18125.txt Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> * add trace test * remove check for >= debug, trace * Update changelog/18125.txt Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
This commit is contained in:
parent
80d2caee9e
commit
695fe367c9
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
command/server: Environment variable keys are now logged at startup.
|
||||
```
|
|
@ -1168,6 +1168,21 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
info := make(map[string]string)
|
||||
info["log level"] = config.LogLevel
|
||||
infoKeys = append(infoKeys, "log level")
|
||||
|
||||
// returns a slice of env vars formatted as "key=value"
|
||||
envVars := os.Environ()
|
||||
var envVarKeys []string
|
||||
for _, v := range envVars {
|
||||
splitEnvVars := strings.Split(v, "=")
|
||||
envVarKeys = append(envVarKeys, splitEnvVars[0])
|
||||
}
|
||||
|
||||
sort.Strings(envVarKeys)
|
||||
|
||||
key := "environment variables"
|
||||
info[key] = strings.Join(envVarKeys, ", ")
|
||||
infoKeys = append(infoKeys, key)
|
||||
|
||||
barrierSeal, barrierWrapper, unwrapSeal, seals, sealConfigError, err := setSeal(c, config, infoKeys, info)
|
||||
// Check error here
|
||||
if err != nil {
|
||||
|
|
|
@ -203,63 +203,70 @@ func TestServer(t *testing.T) {
|
|||
contents string
|
||||
exp string
|
||||
code int
|
||||
flag string
|
||||
args []string
|
||||
}{
|
||||
{
|
||||
"common_ha",
|
||||
testBaseHCL(t, "") + inmemHCL,
|
||||
"(HA available)",
|
||||
0,
|
||||
"-test-verify-only",
|
||||
[]string{"-test-verify-only"},
|
||||
},
|
||||
{
|
||||
"separate_ha",
|
||||
testBaseHCL(t, "") + inmemHCL + haInmemHCL,
|
||||
"HA Storage:",
|
||||
0,
|
||||
"-test-verify-only",
|
||||
[]string{"-test-verify-only"},
|
||||
},
|
||||
{
|
||||
"bad_separate_ha",
|
||||
testBaseHCL(t, "") + inmemHCL + badHAInmemHCL,
|
||||
"Specified HA storage does not support HA",
|
||||
1,
|
||||
"-test-verify-only",
|
||||
[]string{"-test-verify-only"},
|
||||
},
|
||||
{
|
||||
"good_listener_timeout_config",
|
||||
testBaseHCL(t, goodListenerTimeouts) + inmemHCL,
|
||||
"",
|
||||
0,
|
||||
"-test-server-config",
|
||||
[]string{"-test-server-config"},
|
||||
},
|
||||
{
|
||||
"bad_listener_read_header_timeout_config",
|
||||
testBaseHCL(t, badListenerReadHeaderTimeout) + inmemHCL,
|
||||
"unknown unit \"km\" in duration \"12km\"",
|
||||
1,
|
||||
"-test-server-config",
|
||||
[]string{"-test-server-config"},
|
||||
},
|
||||
{
|
||||
"bad_listener_read_timeout_config",
|
||||
testBaseHCL(t, badListenerReadTimeout) + inmemHCL,
|
||||
"unknown unit \"\\xe6\\x97\\xa5\" in duration",
|
||||
1,
|
||||
"-test-server-config",
|
||||
[]string{"-test-server-config"},
|
||||
},
|
||||
{
|
||||
"bad_listener_write_timeout_config",
|
||||
testBaseHCL(t, badListenerWriteTimeout) + inmemHCL,
|
||||
"unknown unit \"lbs\" in duration \"56lbs\"",
|
||||
1,
|
||||
"-test-server-config",
|
||||
[]string{"-test-server-config"},
|
||||
},
|
||||
{
|
||||
"bad_listener_idle_timeout_config",
|
||||
testBaseHCL(t, badListenerIdleTimeout) + inmemHCL,
|
||||
"unknown unit \"gophers\" in duration \"78gophers\"",
|
||||
1,
|
||||
"-test-server-config",
|
||||
[]string{"-test-server-config"},
|
||||
},
|
||||
{
|
||||
"environment_variables_logged",
|
||||
testBaseHCL(t, "") + inmemHCL,
|
||||
"Environment Variables",
|
||||
0,
|
||||
[]string{"-test-verify-only"},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -278,11 +285,11 @@ func TestServer(t *testing.T) {
|
|||
f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
code := cmd.Run([]string{
|
||||
"-config", f.Name(),
|
||||
tc.flag,
|
||||
})
|
||||
args := append(tc.args, "-config", f.Name())
|
||||
|
||||
code := cmd.Run(args)
|
||||
output := ui.ErrorWriter.String() + ui.OutputWriter.String()
|
||||
|
||||
if code != tc.code {
|
||||
t.Errorf("expected %d to be %d: %s", code, tc.code, output)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue