Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -32,5 +33,7 @@ func NewConfigCommand() *cobra.Command {
NewConfigViewProfileCommand(),
)

cmd.PersistentFlags().AddFlag(options.ConfigUnmaskSecretValueOption.Flag)

return cmd
}
5 changes: 4 additions & 1 deletion cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const (
pingcli config get --profile myProfile noColor

Read the worker ID used to authenticate to the PingOne service management API.
pingcli config get service.pingone.authentication.worker.environmentID`
pingcli config get service.pingone.authentication.worker.environmentID

Read the unmasked value for the request access token.
pingcli config get --unmask-values request.accessToken`
)

func NewConfigGetCommand() *cobra.Command {
Expand Down
11 changes: 11 additions & 0 deletions cmd/config/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@ func Example_getUnmaskedValue() {
// Configuration values for profile 'default' and key 'noColor':
// noColor=true
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_get_UnmaskValuesFlag() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", "--unmask-values", options.RequestAccessTokenOption.ViperKey)

// Output:
// Configuration values for profile 'default' and key 'request.accessToken':
// request.accessToken=
// request.accessTokenExpiry=0
}
5 changes: 4 additions & 1 deletion cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const (
pingcli config set color=true

Set the PingOne tenant region code setting to 'AP' for the profile named 'myProfile'.
pingcli config set --profile myProfile service.pingone.regionCode=AP`
pingcli config set --profile myProfile service.pingone.regionCode=AP

Set the PingFederate basic authentication password with unmasked output
pingcli config set --profile myProfile --unmask-values service.pingfederate.authentication.basicAuth.password=1234`
)

func NewConfigSetCommand() *cobra.Command {
Expand Down
10 changes: 10 additions & 0 deletions cmd/config/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func Example_setMaskedValue() {
// service.pingfederate.authentication.basicAuth.password=********
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_set_UnmaskedValuesFlag() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", "--unmask-values", fmt.Sprintf("%s=%s", options.PingFederateBasicAuthPasswordOption.ViperKey, "1234"))

// Output:
// SUCCESS: Configuration set successfully:
// service.pingfederate.authentication.basicAuth.password=1234
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_setUnmaskedValue() {
t := testing.T{}
Expand Down
5 changes: 4 additions & 1 deletion cmd/config/view_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const (
pingcli config view-profile

View configuration for a specific profile
pingcli config view-profile myprofile`
pingcli config view-profile myprofile

View configuration for a specific profile with unmasked values
pingcli config --unmask-values view-profile myprofile`
)

func NewConfigViewProfileCommand() *cobra.Command {
Expand Down
5 changes: 5 additions & 0 deletions cmd/config/view_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func TestConfigViewProfileCmd_Execute_WithProfileFlag(t *testing.T) {
testutils.CheckExpectedError(t, err, nil)
}

func TestConfigViewProfileCmd_Execute_UnmaskValuesFlag(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t, "config", "view-profile", "--unmask-values")
testutils.CheckExpectedError(t, err, nil)
}

// Test Config Set Command fails with invalid flag
func TestConfigViewProfileCmd_Execute_InvalidFlag(t *testing.T) {
expectedErrorPattern := `^unknown flag: --invalid$`
Expand Down
7 changes: 6 additions & 1 deletion internal/commands/config/get_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ func RunInternalConfigGet(viperKey string) (err error) {
return fmt.Errorf("failed to get configuration: %v", err)
}

if opt.Sensitive {
unmaskOptionVal, err := profiles.GetOptionValue(options.ConfigUnmaskSecretValueOption)
if err != nil {
unmaskOptionVal = "false"
}

if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") {
msgStr += fmt.Sprintf("%s=%s\n", opt.ViperKey, profiles.MaskValue(vVal))
} else {
msgStr += fmt.Sprintf("%s=%s\n", opt.ViperKey, vVal)
Expand Down
7 changes: 6 additions & 1 deletion internal/commands/config/set_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ func RunInternalConfigSet(kvPair string) (err error) {
return fmt.Errorf("failed to set configuration: %v", err)
}

if opt.Sensitive {
unmaskOptionVal, err := profiles.GetOptionValue(options.ConfigUnmaskSecretValueOption)
if err != nil {
unmaskOptionVal = "false"
}

if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") {
msgStr += fmt.Sprintf("%s=%s", vKey, profiles.MaskValue(vVal))
} else {
msgStr += fmt.Sprintf("%s=%s", vKey, vVal)
Expand Down
10 changes: 8 additions & 2 deletions internal/commands/config/unset_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config_internal

import (
"fmt"
"strings"

"github.com/pingidentity/pingcli/internal/configuration"
"github.com/pingidentity/pingcli/internal/configuration/options"
Expand Down Expand Up @@ -39,10 +40,15 @@ func RunInternalConfigUnset(viperKey string) (err error) {

vVal, _, err := profiles.ViperValueFromOption(opt)
if err != nil {
return fmt.Errorf("failed to set configuration: %v", err)
return fmt.Errorf("failed to unset configuration: %v", err)
}

unmaskOptionVal, err := profiles.GetOptionValue(options.ConfigUnmaskSecretValueOption)
if err != nil {
unmaskOptionVal = "false"
}

if opt.Sensitive {
if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") {
msgStr += fmt.Sprintf("%s=%s", viperKey, profiles.MaskValue(vVal))
} else {
msgStr += fmt.Sprintf("%s=%s", viperKey, vVal)
Expand Down
8 changes: 7 additions & 1 deletion internal/commands/config/view_profile_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config_internal

import (
"fmt"
"strings"

"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/pingidentity/pingcli/internal/output"
Expand Down Expand Up @@ -37,7 +38,12 @@ func RunInternalConfigViewProfile(args []string) (err error) {
return fmt.Errorf("failed to view profile: %v", err)
}

if opt.Sensitive {
unmaskOptionVal, err := profiles.GetOptionValue(options.ConfigUnmaskSecretValueOption)
if err != nil {
unmaskOptionVal = "false"
}

if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") {
msgStr += fmt.Sprintf("%s=%s\n", opt.ViperKey, profiles.MaskValue(vVal))
} else {
msgStr += fmt.Sprintf("%s=%s\n", opt.ViperKey, vVal)
Expand Down
3 changes: 3 additions & 0 deletions internal/configuration/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Options() []Option {
ConfigAddProfileSetActiveOption,
ConfigDeleteAutoAcceptOption,
ConfigListKeysYamlOption,
ConfigUnmaskSecretValueOption,

RequestDataOption,
RequestDataRawOption,
Expand Down Expand Up @@ -131,6 +132,8 @@ var (
ConfigListKeysYamlOption Option

ConfigDeleteAutoAcceptOption Option

ConfigUnmaskSecretValueOption Option
)

// 'pingcli platform export' command options
Expand Down
24 changes: 24 additions & 0 deletions internal/configuration/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func InitRootOptions() {
initColorOption()
initConfigOption()
initOutputFormatOption()
initUnmaskSecretValuesOption()
}

func initActiveProfileOption() {
Expand Down Expand Up @@ -129,6 +130,29 @@ func initOutputFormatOption() {
}
}

func initUnmaskSecretValuesOption() {
cobraParamName := "unmask-values"
cobraValue := new(customtypes.Bool)
defaultValue := customtypes.Bool(false)

options.ConfigUnmaskSecretValueOption = options.Option{
CobraParamName: cobraParamName,
CobraParamValue: cobraValue,
DefaultValue: &defaultValue,
EnvVar: "", // No EnvVar
Flag: &pflag.Flag{
Name: cobraParamName,
Shorthand: "U",
Usage: "Unmask secret values. (default false)",
Value: cobraValue,
NoOptDefVal: "true", // Make this flag a boolean flag
},
Sensitive: false,
Type: options.ENUM_BOOL,
ViperKey: "", // No ViperKey
}
}

func getDefaultConfigFilepath() (defaultConfigFilepath *customtypes.String) {
l := logger.Get()

Expand Down
Loading