mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 09:42:25 +00:00
Don't say "Success!" when a specific field is requested. (#21546)
* add a test to show the bug * do not output a "Success!" message if a specific field was requested * Create 21545.txt * Fix changelog name --------- Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
This commit is contained in:
3
changelog/21546.txt
Normal file
3
changelog/21546.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
cli: Avoid printing "Success" message when `-field` flag is provided during a `vault write`.
|
||||
```
|
||||
@@ -155,7 +155,8 @@ func handleWriteSecretOutput(c *BaseCommand, path string, secret *api.Secret, er
|
||||
}
|
||||
if secret == nil {
|
||||
// Don't output anything unless using the "table" format
|
||||
if Format(c.UI) == "table" {
|
||||
// and even then, don't output anything if a specific field was requested
|
||||
if c.flagField == "" && Format(c.UI) == "table" {
|
||||
c.UI.Info(fmt.Sprintf("Success! Data written to: %s", path))
|
||||
}
|
||||
return 0
|
||||
|
||||
@@ -118,6 +118,30 @@ func TestWriteCommand_Run(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// If we ask for a field and get an empty result, do not output "Success!" or anything else
|
||||
t.Run("field_from_nothing", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, closer := testVaultServer(t)
|
||||
defer closer()
|
||||
|
||||
ui, cmd := testWriteCommand(t)
|
||||
cmd.client = client
|
||||
|
||||
code := cmd.Run([]string{
|
||||
"-field", "somefield",
|
||||
"secret/write/foo", "foo=bar",
|
||||
})
|
||||
if exp := 0; code != exp {
|
||||
t.Fatalf("expected %d to be %d: %q", code, exp, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||
if combined != "" {
|
||||
t.Errorf("expected %q to be empty", combined)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("force", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -127,9 +127,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", or "yaml". This can also be specified via the
|
||||
|
||||
@@ -72,9 +72,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", or "yaml". This can also be specified via the
|
||||
|
||||
@@ -65,9 +65,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", "yaml", or "raw". This can also be specified
|
||||
|
||||
@@ -54,9 +54,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", or "yaml". This can also be specified via the
|
||||
|
||||
@@ -36,9 +36,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", or "yaml". This can also be specified via the
|
||||
|
||||
@@ -106,9 +106,9 @@ flags](/vault/docs/commands) included on all commands.
|
||||
|
||||
### Output options
|
||||
|
||||
- `-field` `(string: "")` - Print only the field with the given name. Specifying
|
||||
this option will take precedence over other formatting directives. The result
|
||||
will not have a trailing newline making it ideal for piping to other processes.
|
||||
- `-field` `(string: "")` - Print only the field with the given name, in the format
|
||||
specified in the `-format` directive. The result will not have a trailing
|
||||
newline making it ideal for piping to other processes.
|
||||
|
||||
- `-format` `(string: "table")` - Print the output in the given format. Valid
|
||||
formats are "table", "json", or "yaml". This can also be specified via the
|
||||
|
||||
Reference in New Issue
Block a user