Skip to content

Commit

Permalink
Merge pull request #36 from sensu-community/feature/secret-option
Browse files Browse the repository at this point in the history
working secret option that hides default value from option usage message
  • Loading branch information
jspaleta authored Aug 14, 2020
2 parents 30f809e + bcc33cd commit ce4a6d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- 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.
### Fixed
- Do not create commandline flag unless Argument is set for PluginConfigOption

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 @@ -196,6 +199,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

0 comments on commit ce4a6d9

Please sign in to comment.