Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working secret option that hides default value from option usage message #36

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
- Added support for to designated PluginConfigOptions as Secret. If Secret, the default value for the argument will not be displayed in the usage message. This prevents sensitive values stored in envvars from leaking into the usage message.

## [0.7.0] - 2020-06-03

Expand Down
1 change: 1 addition & 0 deletions sensu/gohandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
Path: "path1",
Shorthand: "d",
Usage: "First argument",
Secret: true,
}

defaultOption2 = PluginConfigOption{
Expand Down
1 change: 1 addition & 0 deletions sensu/gomutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
Path: "path1",
Shorthand: "d",
Usage: "First argument",
Secret: true,
}

mutatorOption2 = PluginConfigOption{
Expand Down
9 changes: 9 additions & 0 deletions sensu/goplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type PluginConfigOption struct {

// Usage adds help context to the command-line flag.
Usage string

// If secret option do not copy Argument value into Default
Secret bool
}

// PluginConfig defines the base plugin configuration.
Expand Down Expand Up @@ -193,6 +196,12 @@ func setupFlag(cmd *cobra.Command, opt *PluginConfigOption) error {
default:
return fmt.Errorf("invalid input type: %v", kind)
}
flag := cmd.Flags().Lookup(opt.Argument)
// Set empty DefValue string if option is a secret
// DefValue is only used for pflag usage message construction
if opt.Secret {
flag.DefValue = ""
}
return nil
}

Expand Down