Skip to content

Commit

Permalink
cli: remove viper StringToString pflag workaround
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
  • Loading branch information
alexandear committed Sep 26, 2023
1 parent 7a18f27 commit 339a3b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/bank-vaults/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func kvStoreForConfig(cfg *viper.Viper) (kv.Service, error) {
k8s, err := k8s.New(
cfg.GetString(cfgK8SNamespace),
cfg.GetString(cfgK8SSecret),
k8sSecretLabels,
cfg.GetStringMapString(cfgK8SLabels),
)
if err != nil {
return nil, errors.Wrap(err, "error creating K8S Secret kv store")
Expand All @@ -253,7 +253,7 @@ func kvStoreForConfig(cfg *viper.Viper) (kv.Service, error) {
k8s, err := k8s.New(
cfg.GetString(cfgK8SNamespace),
cfg.GetString(cfgK8SSecret),
k8sSecretLabels,
cfg.GetStringMapString(cfgK8SLabels),
)
if err != nil {
return nil, errors.Wrap(err, "error creating K8S Secret with kv store")
Expand Down
19 changes: 4 additions & 15 deletions cmd/bank-vaults/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ const (
cfgOnce = "once"
)

// We need to pre-create a value and bind the flag to this until
// https://github.com/spf13/viper/issues/608 gets fixed.
var (
k8sSecretLabels map[string]string
awsKmsEncryptionContext map[string]string
)

var defaultAwsKmsEncryptionContext = map[string]string{
"Tool": "bank-vaults",
}

var rootCmd = &cobra.Command{
Use: "bank-vaults",
Short: "Automates initialization, unsealing and configuration of Hashicorp Vault.",
Expand Down Expand Up @@ -173,8 +162,8 @@ func configStringSliceVar(cmd *cobra.Command, key string, defaultValue []string,
_ = c.BindPFlag(key, cmd.PersistentFlags().Lookup(key))
}

func configStringMapVar(cmd *cobra.Command, key string, value *map[string]string, defaultValue map[string]string, description string) {
cmd.PersistentFlags().StringToStringVar(value, key, defaultValue, description)
func configStringMapVar(cmd *cobra.Command, key string, defaultValue map[string]string, description string) {
cmd.PersistentFlags().StringToString(key, defaultValue, description)
_ = c.BindPFlag(key, cmd.PersistentFlags().Lookup(key))
}

Expand Down Expand Up @@ -230,7 +219,7 @@ func init() {
// AWS KMS flags
configStringSliceVar(rootCmd, cfgAWSKMSRegion, nil, "The region of the AWS KMS key to encrypt values")
configStringSliceVar(rootCmd, cfgAWSKMSKeyID, nil, "The ID or ARN of the AWS KMS key to encrypt values")
configStringMapVar(rootCmd, cfgAWSKMSEncryptionContext, &awsKmsEncryptionContext, defaultAwsKmsEncryptionContext, "The encryption context that AWS KMS will use to encrypt values")
configStringMapVar(rootCmd, cfgAWSKMSEncryptionContext, map[string]string{"Tool": "bank-vaults"}, "The encryption context that AWS KMS will use to encrypt values")

// AWS S3 Object Storage flags
configStringSliceVar(rootCmd, cfgAWSS3Region, []string{"us-east-1"}, "The region to use for storing values in AWS S3")
Expand Down Expand Up @@ -265,7 +254,7 @@ func init() {
// K8S Secret Storage flags
configStringVar(rootCmd, cfgK8SNamespace, "", "The namespace of the K8S Secret to store values in")
configStringVar(rootCmd, cfgK8SSecret, "", "The name of the K8S Secret to store values in")
configStringMapVar(rootCmd, cfgK8SLabels, &k8sSecretLabels, map[string]string{}, "The labels of the K8S Secret to store values in")
configStringMapVar(rootCmd, cfgK8SLabels, map[string]string{}, "The labels of the K8S Secret to store values in")

// HSM flags
configStringVar(rootCmd, cfgHSMModulePath, "", "The library path of the HSM device")
Expand Down

0 comments on commit 339a3b8

Please sign in to comment.