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:
Marty Pauley
2023-08-18 00:49:04 +09:00
committed by GitHub
parent 7d361eec46
commit 6ceee6276f
9 changed files with 47 additions and 19 deletions

3
changelog/21546.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
cli: Avoid printing "Success" message when `-field` flag is provided during a `vault write`.
```

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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