diff --git a/command/auth.go b/command/auth.go index ec1cd065c9..265f2a2b7b 100644 --- a/command/auth.go +++ b/command/auth.go @@ -66,10 +66,12 @@ func (c *AuthCommand) Run(args []string) int { for _, arg := range args { switch { case strings.HasPrefix(arg, "-methods"): - c.UI.Warn(wrapAtLength( - "WARNING! The -methods flag is deprecated. Please use "+ - "\"vault auth list\" instead. This flag will be removed in "+ - "Vault 0.11 (or later).") + "\n") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -methods flag is deprecated. Please use "+ + "\"vault auth list\" instead. This flag will be removed in "+ + "Vault 0.11 (or later).") + "\n") + } return (&AuthListCommand{ BaseCommand: &BaseCommand{ UI: c.UI, @@ -77,10 +79,12 @@ func (c *AuthCommand) Run(args []string) int { }, }).Run(nil) case strings.HasPrefix(arg, "-method-help"): - c.UI.Warn(wrapAtLength( - "WARNING! The -method-help flag is deprecated. Please use "+ - "\"vault auth help\" instead. This flag will be removed in "+ - "Vault 0.11 (or later).") + "\n") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -method-help flag is deprecated. Please use "+ + "\"vault auth help\" instead. This flag will be removed in "+ + "Vault 0.11 (or later).") + "\n") + } // Parse the args to pull out the method, suppressing any errors because // there could be other flags that we don't care about. f := flag.NewFlagSet("", flag.ContinueOnError) @@ -101,11 +105,13 @@ func (c *AuthCommand) Run(args []string) int { // If we got this far, we have an arg or a series of args that should be // passed directly to the new "vault login" command. - c.UI.Warn(wrapAtLength( - "WARNING! The \"vault auth ARG\" command is deprecated and is now a "+ - "subcommand for interacting with auth methods. To authenticate "+ - "locally to Vault, use \"vault login\" instead. This backwards "+ - "compatibility will be removed in Vault 0.11 (or later).") + "\n") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The \"vault auth ARG\" command is deprecated and is now a "+ + "subcommand for interacting with auth methods. To authenticate "+ + "locally to Vault, use \"vault login\" instead. This backwards "+ + "compatibility will be removed in Vault 0.11 (or later).") + "\n") + } return (&LoginCommand{ BaseCommand: &BaseCommand{ UI: c.UI, diff --git a/command/format.go b/command/format.go index c4c55e00e9..4af09e402c 100644 --- a/command/format.go +++ b/command/format.go @@ -75,6 +75,7 @@ func Format(ui cli.Ui) string { return ui.(*VaultUI).format } + panic("") format := os.Getenv(EnvVaultFormat) if format == "" { format = "table" diff --git a/command/lease_renew.go b/command/lease_renew.go index c12f53d2e8..07b177046a 100644 --- a/command/lease_renew.go +++ b/command/lease_renew.go @@ -94,11 +94,12 @@ func (c *LeaseRenewCommand) Run(args []string) int { case 2: // Deprecation // TODO: remove in 0.9.0 - c.UI.Warn(wrapAtLength( - "WARNING! Specifying INCREMENT as a second argument is deprecated. " + - "Please use -increment instead. This will be removed in the next " + - "major release of Vault.")) - + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! Specifying INCREMENT as a second argument is deprecated. " + + "Please use -increment instead. This will be removed in the next " + + "major release of Vault.")) + } leaseID = strings.TrimSpace(args[0]) parsed, err := time.ParseDuration(appendDurationSuffix(args[1])) if err != nil { diff --git a/command/login.go b/command/login.go index b6603e855a..d9c2a3f523 100644 --- a/command/login.go +++ b/command/login.go @@ -167,26 +167,28 @@ func (c *LoginCommand) Run(args []string) int { // TODO: remove in 0.10.0 switch { case c.flagNoVerify: - c.UI.Warn(wrapAtLength( - "WARNING! The -no-verify flag is deprecated. In the past, Vault " + - "performed a lookup on a token after authentication. This is no " + - "longer the case for all auth methods except \"token\". Vault will " + - "still attempt to perform a lookup when given a token directly " + - "because that is how it gets the list of policies, ttl, and other " + - "metadata. To disable this lookup, specify \"lookup=false\" as a " + - "configuration option to the token auth method, like this:")) - c.UI.Warn("") - c.UI.Warn(" $ vault auth token=ABCD lookup=false") - c.UI.Warn("") - c.UI.Warn("Or omit the token and Vault will prompt for it:") - c.UI.Warn("") - c.UI.Warn(" $ vault auth lookup=false") - c.UI.Warn(" Token (will be hidden): ...") - c.UI.Warn("") - c.UI.Warn(wrapAtLength( - "If you are not using token authentication, you can safely omit this " + - "flag. Vault will not perform a lookup after authentication.")) - c.UI.Warn("") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -no-verify flag is deprecated. In the past, Vault " + + "performed a lookup on a token after authentication. This is no " + + "longer the case for all auth methods except \"token\". Vault will " + + "still attempt to perform a lookup when given a token directly " + + "because that is how it gets the list of policies, ttl, and other " + + "metadata. To disable this lookup, specify \"lookup=false\" as a " + + "configuration option to the token auth method, like this:")) + c.UI.Warn("") + c.UI.Warn(" $ vault auth token=ABCD lookup=false") + c.UI.Warn("") + c.UI.Warn("Or omit the token and Vault will prompt for it:") + c.UI.Warn("") + c.UI.Warn(" $ vault auth lookup=false") + c.UI.Warn(" Token (will be hidden): ...") + c.UI.Warn("") + c.UI.Warn(wrapAtLength( + "If you are not using token authentication, you can safely omit this " + + "flag. Vault will not perform a lookup after authentication.")) + c.UI.Warn("") + } // There's no point in passing this to other auth handlers... if c.flagMethod == "token" { diff --git a/command/operator_generate_root.go b/command/operator_generate_root.go index 78fd0b9d1b..b647a6af04 100644 --- a/command/operator_generate_root.go +++ b/command/operator_generate_root.go @@ -217,9 +217,11 @@ func (c *OperatorGenerateRootCommand) Run(args []string) int { // TODO: remove in 0.9.0 switch { case c.flagGenOTP: - c.UI.Warn(wrapAtLength( - "The -gen-otp flag is deprecated. Please use the -generate-otp flag " + - "instead.")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -gen-otp flag is deprecated. Please use the -generate-otp flag " + + "instead.")) + } c.flagGenerateOTP = c.flagGenOTP } diff --git a/command/operator_init.go b/command/operator_init.go index 4503d2eae9..d5e4103ea5 100644 --- a/command/operator_init.go +++ b/command/operator_init.go @@ -244,14 +244,18 @@ func (c *OperatorInitCommand) Run(args []string) int { // Deprecations // TODO: remove in 0.9.0 if c.flagAuto { - c.UI.Warn(wrapAtLength("WARNING! -auto is deprecated. Please use " + - "-consul-auto instead. This will be removed in Vault 0.11 " + - "(or later).")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength("WARNING! -auto is deprecated. Please use " + + "-consul-auto instead. This will be removed in Vault 0.11 " + + "(or later).")) + } c.flagConsulAuto = true } if c.flagCheck { - c.UI.Warn(wrapAtLength("WARNING! -check is deprecated. Please use " + - "-status instead. This will be removed in Vault 0.11 (or later).")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength("WARNING! -check is deprecated. Please use " + + "-status instead. This will be removed in Vault 0.11 (or later).")) + } c.flagStatus = true } diff --git a/command/operator_rekey.go b/command/operator_rekey.go index 4cc23fadc7..c82b44706b 100644 --- a/command/operator_rekey.go +++ b/command/operator_rekey.go @@ -269,21 +269,27 @@ func (c *OperatorRekeyCommand) Run(args []string) int { // Deprecations // TODO: remove in 0.9.0 if c.flagDelete { - c.UI.Warn(wrapAtLength( - "WARNING! The -delete flag is deprecated. Please use -backup-delete " + - "instead. This flag will be removed in Vault 0.11 (or later).")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -delete flag is deprecated. Please use -backup-delete " + + "instead. This flag will be removed in Vault 0.11 (or later).")) + } c.flagBackupDelete = true } if c.flagRetrieve { - c.UI.Warn(wrapAtLength( - "WARNING! The -retrieve flag is deprecated. Please use -backup-retrieve " + - "instead. This flag will be removed in Vault 0.11 (or later).")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -retrieve flag is deprecated. Please use -backup-retrieve " + + "instead. This flag will be removed in Vault 0.11 (or later).")) + } c.flagBackupRetrieve = true } if c.flagRecoveryKey { - c.UI.Warn(wrapAtLength( - "WARNING! The -recovery-key flag is deprecated. Please use -target=recovery " + - "instead. This flag will be removed in Vault 0.11 (or later).")) + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! The -recovery-key flag is deprecated. Please use -target=recovery " + + "instead. This flag will be removed in Vault 0.11 (or later).")) + } c.flagTarget = "recovery" } @@ -344,25 +350,29 @@ func (c *OperatorRekeyCommand) init(client *api.Client) int { // Print warnings about recovery, etc. if len(c.flagPGPKeys) == 0 { - c.UI.Warn(wrapAtLength( - "WARNING! If you lose the keys after they are returned, there is no " + - "recovery. Consider canceling this operation and re-initializing " + - "with the -pgp-keys flag to protect the returned unseal keys along " + - "with -backup to allow recovery of the encrypted keys in case of " + - "emergency. You can delete the stored keys later using the -delete " + - "flag.")) - c.UI.Output("") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! If you lose the keys after they are returned, there is no " + + "recovery. Consider canceling this operation and re-initializing " + + "with the -pgp-keys flag to protect the returned unseal keys along " + + "with -backup to allow recovery of the encrypted keys in case of " + + "emergency. You can delete the stored keys later using the -delete " + + "flag.")) + c.UI.Output("") + } } if len(c.flagPGPKeys) > 0 && !c.flagBackup { - c.UI.Warn(wrapAtLength( - "WARNING! You are using PGP keys for encrypted the resulting unseal " + - "keys, but you did not enable the option to backup the keys to " + - "Vault's core. If you lose the encrypted keys after they are " + - "returned, you will not be able to recover them. Consider canceling " + - "this operation and re-running with -backup to allow recovery of the " + - "encrypted unseal keys in case of emergency. You can delete the " + - "stored keys later using the -delete flag.")) - c.UI.Output("") + if Format(c.UI) == "table" { + c.UI.Warn(wrapAtLength( + "WARNING! You are using PGP keys for encrypted the resulting unseal " + + "keys, but you did not enable the option to backup the keys to " + + "Vault's core. If you lose the encrypted keys after they are " + + "returned, you will not be able to recover them. Consider canceling " + + "this operation and re-running with -backup to allow recovery of the " + + "encrypted unseal keys in case of emergency. You can delete the " + + "stored keys later using the -delete flag.")) + c.UI.Output("") + } } // Provide the current status diff --git a/command/token_create.go b/command/token_create.go index 738030406e..fd269d947a 100644 --- a/command/token_create.go +++ b/command/token_create.go @@ -207,8 +207,10 @@ func (c *TokenCreateCommand) Run(args []string) int { // TODO: remove in 0.9.0 if c.flagLease != 0 { - c.UI.Warn("The -lease flag is deprecated. Please use -ttl instead.") - c.flagTTL = c.flagLease + if Format(c.UI) == "table" { + c.UI.Warn("The -lease flag is deprecated. Please use -ttl instead.") + c.flagTTL = c.flagLease + } } client, err := c.Client() diff --git a/command/token_renew.go b/command/token_renew.go index 7e7f00775b..ee6a626028 100644 --- a/command/token_renew.go +++ b/command/token_renew.go @@ -99,9 +99,10 @@ func (c *TokenRenewCommand) Run(args []string) int { token = strings.TrimSpace(args[0]) case 2: // TODO: remove in 0.9.0 - backwards compat - c.UI.Warn("Specifying increment as a second argument is deprecated. " + - "Please use -increment instead.") - + if Format(c.UI) == "table" { + c.UI.Warn("Specifying increment as a second argument is deprecated. " + + "Please use -increment instead.") + } token = strings.TrimSpace(args[0]) parsed, err := time.ParseDuration(appendDurationSuffix(args[1])) if err != nil {