mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	Core: interactive CLI improvement VAULT_ADDR warning message (#17076)
This commit is contained in:
		
							
								
								
									
										4
									
								
								changelog/17076.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								changelog/17076.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| ```release-note:improvement | ||||
| core/cli: Warning related to VAULT_ADDR & -address not set with CLI requests. | ||||
| ``` | ||||
|  | ||||
| @@ -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) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 aphorise
					aphorise