From 40e00d812f873c25a3b368e879a40e4db616ddcc Mon Sep 17 00:00:00 2001 From: aphorise Date: Mon, 30 Oct 2023 16:08:55 +0100 Subject: [PATCH] Core: interactive CLI improvement VAULT_ADDR warning message (#17076) --- changelog/17076.txt | 4 ++++ command/base.go | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 changelog/17076.txt diff --git a/changelog/17076.txt b/changelog/17076.txt new file mode 100644 index 0000000000..93e7c1eacb --- /dev/null +++ b/changelog/17076.txt @@ -0,0 +1,4 @@ +```release-note:improvement +core/cli: Warning related to VAULT_ADDR & -address not set with CLI requests. +``` + diff --git a/command/base.go b/command/base.go index 5905765374..10be15b636 100644 --- a/command/base.go +++ b/command/base.go @@ -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)