Core: interactive CLI improvement VAULT_ADDR warning message (#17076)

This commit is contained in:
aphorise
2023-10-30 16:08:55 +01:00
committed by GitHub
parent b0e8471b87
commit 40e00d812f
2 changed files with 15 additions and 0 deletions

4
changelog/17076.txt Normal file
View File

@@ -0,0 +1,4 @@
```release-note:improvement
core/cli: Warning related to VAULT_ADDR & -address not set with CLI requests.
```

View File

@@ -63,6 +63,7 @@ type BaseCommand struct {
flagOutputCurlString bool
flagOutputPolicy bool
flagNonInteractive bool
addrWarning string
flagMFA []string
@@ -81,6 +82,14 @@ func (c *BaseCommand) Client() (*api.Client, error) {
return c.client, nil
}
if c.addrWarning != "" && c.UI != nil {
if os.Getenv("VAULT_ADDR") == "" {
if !c.flagNonInteractive && isatty.IsTerminal(os.Stdin.Fd()) {
c.UI.Warn(wrapAtLength(c.addrWarning))
}
}
}
config := api.DefaultConfig()
if err := config.ReadEnvironment(); err != nil {
@@ -321,10 +330,12 @@ func (c *BaseCommand) flagSet(bit FlagSetBit) *FlagSets {
Completion: complete.PredictAnything,
Usage: "Address of the Vault server.",
}
if c.flagAddress != "" {
addrStringVar.Default = c.flagAddress
} else {
addrStringVar.Default = "https://127.0.0.1:8200"
c.addrWarning = fmt.Sprintf("WARNING! VAULT_ADDR and -address unset. Defaulting to %s.", addrStringVar.Default)
}
f.StringVar(addrStringVar)