diff --git a/cmd/config/add_profile.go b/cmd/config/add_profile.go index a6ede486..fa7990de 100644 --- a/cmd/config/add_profile.go +++ b/cmd/config/add_profile.go @@ -18,7 +18,7 @@ const ( pingcli config add-profile --name MyDeveloperEnv --description "My awesome new profile for my development environment" Add a new configuration profile with a guided experience and set it as the active profile. - pingcli config add-profile --set-active=true` + pingcli config add-profile --set-active` ) func NewConfigAddProfileCommand() *cobra.Command { diff --git a/cmd/config/add_profile_test.go b/cmd/config/add_profile_test.go index 455d2528..59989029 100644 --- a/cmd/config/add_profile_test.go +++ b/cmd/config/add_profile_test.go @@ -33,7 +33,7 @@ func TestConfigAddProfileCmd_InvalidFlag(t *testing.T) { // Test config add profile command fails when provided an invalid value for a flag func TestConfigAddProfileCmd_InvalidFlagValue(t *testing.T) { expectedErrorPattern := `^invalid argument ".*" for ".*" flag: strconv\.ParseBool: parsing ".*": invalid syntax$` - err := testutils_cobra.ExecutePingcli(t, "config", "add-profile", "--set-active", "invalid-value") + err := testutils_cobra.ExecutePingcli(t, "config", "add-profile", "--set-active=invalid-value") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -63,6 +63,6 @@ func TestConfigAddProfileCmd_InvalidSetActiveValue(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "config", "add-profile", "--name", "test-profile", "--description", "test description", - "--set-active", "invalid-value") + "--set-active=invalid-value") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } diff --git a/cmd/config/config.go b/cmd/config/config.go index 2811adf7..89815d3e 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -4,21 +4,17 @@ import ( "github.com/spf13/cobra" ) -// const ( -// configCommandExamples = ` pingcli config -// pingcli config --profile myprofile -// pingcli config --name myprofile --description "My Profile"` -// ) - func NewConfigCommand() *cobra.Command { cmd := &cobra.Command{ - // Args: common.ExactArgs(0), - // DisableFlagsInUseLine: true, // We write our own flags in @Use attribute - // Example: configCommandExamples, Long: "Manage the configuration of the CLI, including Ping product connection parameters.\n\n" + - "The Ping CLI supports the use of configuration profiles.\nConfiguration profiles can be used when connecting to multiple environments using the same Ping CLI instance, such as when managing multiple development or demonstration environments.\n\n" + - "A pre-defined default profile will be used to store the configuration of the CLI.\nAdditional custom profiles can be created using the `pingcli config add-profile` command.\nTo use a custom profile, the `--profile` flag can be used on supported commands to specify the profile to use for that command.\nTo set a custom profile as the default, use the `pingcli config set-active-profile` command.", - // RunE: configRunE, + "The Ping CLI supports the use of configuration profiles." + + "\nConfiguration profiles can be used when connecting to multiple environments using the same Ping CLI " + + "instance, such as when managing multiple development or demonstration environments.\n\n" + + "A pre-defined default profile will be used to store the configuration of the CLI." + + "\nAdditional custom profiles can be created using the `pingcli config add-profile` command." + + "\nTo use a custom profile, the `--profile` flag can be used on supported commands to specify the " + + "profile to use for that command." + + "\nTo set a custom profile as the default, use the `pingcli config set-active-profile` command.", Short: "Manage the CLI configuration.", Use: "config", } @@ -35,20 +31,5 @@ func NewConfigCommand() *cobra.Command { NewConfigUnsetCommand(), ) - // cmd.Flags().AddFlag(options.ConfigProfileOption.Flag) - // cmd.Flags().AddFlag(options.ConfigNameOption.Flag) - // cmd.Flags().AddFlag(options.ConfigDescriptionOption.Flag) - return cmd } - -// func configRunE(cmd *cobra.Command, args []string) error { -// l := logger.Get() -// l.Debug().Msgf("Config Subcommand Called.") - -// if err := config_internal.RunInternalConfig(os.Stdin); err != nil { -// return err -// } - -// return nil -// } diff --git a/cmd/platform/export_test.go b/cmd/platform/export_test.go index c7ca7666..a16b888c 100644 --- a/cmd/platform/export_test.go +++ b/cmd/platform/export_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/pingidentity/pingcli/internal/configuration/options" + "github.com/pingidentity/pingcli/internal/customtypes" "github.com/pingidentity/pingcli/internal/testing/testutils" "github.com/pingidentity/pingcli/internal/testing/testutils_cobra" "github.com/pingidentity/pingcli/internal/testing/testutils_viper" @@ -16,7 +17,7 @@ func TestPlatformExportCmd_Execute(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true") + "--overwrite") testutils.CheckExpectedError(t, err, nil) } @@ -51,7 +52,7 @@ func TestPlatformExportCmd_ServiceFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingone-protect") testutils.CheckExpectedError(t, err, nil) } @@ -70,7 +71,7 @@ func TestPlatformExportCmd_ExportFormatFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, "--format", "HCL", - "--overwrite", "true", + "--overwrite", "--services", "pingone-protect") testutils.CheckExpectedError(t, err, nil) } @@ -88,7 +89,7 @@ func TestPlatformExportCmd_OutputDirectoryFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingone-protect") testutils.CheckExpectedError(t, err, nil) } @@ -106,7 +107,7 @@ func TestPlatformExportCmd_OverwriteFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingone-protect") testutils.CheckExpectedError(t, err, nil) } @@ -125,7 +126,7 @@ func TestPlatformExportCmd_OverwriteFlagFalseWithExistingDirectory(t *testing.T) err = testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, "--services", "pingone-protect", - "--overwrite", "false") + "--overwrite=false") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -142,7 +143,7 @@ func TestPlatformExportCmd_OverwriteFlagTrueWithExistingDirectory(t *testing.T) err = testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, "--services", "pingone-protect", - "--overwrite", "true") + "--overwrite") testutils.CheckExpectedError(t, err, nil) } @@ -156,7 +157,7 @@ func TestPlatformExportCmd_PingOneWorkerEnvironmentIdFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingone-protect", "--pingone-worker-environment-id", os.Getenv(options.PingOneAuthenticationWorkerEnvironmentIDOption.EnvVar), "--pingone-worker-client-id", os.Getenv(options.PingOneAuthenticationWorkerClientIDOption.EnvVar), @@ -179,7 +180,7 @@ func TestPlatformExportCmd_PingFederateBasicAuthFlags(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-username", os.Getenv(options.PingFederateBasicAuthUsernameOption.EnvVar), "--pingfederate-password", os.Getenv(options.PingFederateBasicAuthPasswordOption.EnvVar), @@ -203,7 +204,7 @@ func TestPlatformExportCmd_PingFederateBasicAuthFlagsInvalid(t *testing.T) { expectedErrorPattern := `^failed to export 'pingfederate' service: failed to export resource .*\. err: .* Request for resource '.*' was not successful\.\s+Response Code: 401 Unauthorized\s+Response Body: {{"resultId":"invalid_credentials","message":"The credentials you provided were not recognized\."}}\s+Error: 401 Unauthorized$` err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-username", "Administrator", "--pingfederate-password", "invalid", @@ -218,7 +219,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlags(t *testing.T) err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-client-id", os.Getenv(options.PingFederateClientCredentialsAuthClientIDOption.EnvVar), "--pingfederate-client-secret", os.Getenv(options.PingFederateClientCredentialsAuthClientSecretOption.EnvVar), @@ -244,7 +245,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalid(t *test expectedErrorPattern := `^failed to export 'pingfederate' service: failed to export resource .*\. err: .* Request for resource '.*' was not successful\. Response is nil\. Error: oauth2: "invalid_client" "Invalid client or client credentials\."$` err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-client-id", "test", "--pingfederate-client-secret", "invalid", @@ -261,7 +262,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalidTokenURL expectedErrorPattern := `(?s)^failed to export 'pingfederate' service: failed to export resource.*\. err:.*Request for resource '.*' was not successful\. Response is nil\. Error: oauth2: cannot fetch token: 404 Not Found\s+Response: \\s+.*$` err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-client-id", os.Getenv(options.PingFederateClientCredentialsAuthClientIDOption.EnvVar), "--pingfederate-client-secret", os.Getenv(options.PingFederateClientCredentialsAuthClientSecretOption.EnvVar), @@ -277,9 +278,9 @@ func TestPlatformExportCmd_PingFederateXBypassHeaderFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", - "--pingfederate-x-bypass-external-validation-header=true", + "--pingfederate-x-bypass-external-validation-header", "--pingfederate-username", os.Getenv(options.PingFederateBasicAuthUsernameOption.EnvVar), "--pingfederate-password", os.Getenv(options.PingFederateBasicAuthPasswordOption.EnvVar), "--pingfederate-authentication-type", "basicAuth", @@ -293,9 +294,9 @@ func TestPlatformExportCmd_PingFederateTrustAllTLSFlag(t *testing.T) { err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", - "--pingfederate-insecure-trust-all-tls=true", + "--pingfederate-insecure-trust-all-tls", "--pingfederate-username", os.Getenv(options.PingFederateBasicAuthUsernameOption.EnvVar), "--pingfederate-password", os.Getenv(options.PingFederateBasicAuthPasswordOption.EnvVar), "--pingfederate-authentication-type", "basicAuth", @@ -310,7 +311,7 @@ func TestPlatformExportCmd_PingFederateTrustAllTLSFlagFalse(t *testing.T) { expectedErrorPattern := `^failed to export '.*' service: failed to export resource .*\. err: .* Request for resource '.*' was not successful\. Response is nil\. Error: Get "https.*": tls: failed to verify certificate: x509: certificate signed by unknown authority$` err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-insecure-trust-all-tls=false", "--pingfederate-username", os.Getenv(options.PingFederateBasicAuthUsernameOption.EnvVar), @@ -320,19 +321,21 @@ func TestPlatformExportCmd_PingFederateTrustAllTLSFlagFalse(t *testing.T) { testutils.CheckExpectedError(t, err, &expectedErrorPattern) } -// Test Platform Export command passes with PingFederate --pingfederate-insecure-trust-all-tls=false and --pingfederate-ca-certificate-pem-files set +// Test Platform Export command passes with PingFederate +// --pingfederate-insecure-trust-all-tls=false +// and --pingfederate-ca-certificate-pem-files set func TestPlatformExportCmd_PingFederateCaCertificatePemFiles(t *testing.T) { outputDir := t.TempDir() err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, - "--overwrite", "true", + "--overwrite", "--services", "pingfederate", "--pingfederate-insecure-trust-all-tls=false", "--pingfederate-ca-certificate-pem-files", "testdata/ssl-server-crt.pem", "--pingfederate-username", os.Getenv(options.PingFederateBasicAuthUsernameOption.EnvVar), "--pingfederate-password", os.Getenv(options.PingFederateBasicAuthPasswordOption.EnvVar), - "--pingfederate-authentication-type", "basicAuth", + "--pingfederate-authentication-type", customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC, ) testutils.CheckExpectedError(t, err, nil) } diff --git a/cmd/root_test.go b/cmd/root_test.go index d55e0c6c..1e0834f8 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -81,19 +81,19 @@ func TestRootCmd_OutputFlagTextVsJSON(t *testing.T) { } } -// Test Root Command Executes when provided the --color flag +// Test Root Command Executes when provided the --no-color flag func TestRootCmd_ColorFlag(t *testing.T) { - err := testutils_cobra.ExecutePingcli(t, "--color=true") + err := testutils_cobra.ExecutePingcli(t, "--no-color") testutils.CheckExpectedError(t, err, nil) - err = testutils_cobra.ExecutePingcli(t, "--color=false") + err = testutils_cobra.ExecutePingcli(t, "--no-color=false") testutils.CheckExpectedError(t, err, nil) } -// Test Root Command fails when provided an invalid value for the --color flag +// Test Root Command fails when provided an invalid value for the --no-color flag func TestRootCmd_InvalidColorFlag(t *testing.T) { - expectedErrorPattern := `^invalid argument "invalid" for "--color" flag: strconv\.ParseBool: parsing "invalid": invalid syntax$` - err := testutils_cobra.ExecutePingcli(t, "--color=invalid") + expectedErrorPattern := `^invalid argument "invalid" for ".*" flag: strconv\.ParseBool: parsing "invalid": invalid syntax$` + err := testutils_cobra.ExecutePingcli(t, "--no-color=invalid") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } diff --git a/docs/tool-configuration/configuration-key.md b/docs/tool-configuration/configuration-key.md index eb133f29..50011f67 100644 --- a/docs/tool-configuration/configuration-key.md +++ b/docs/tool-configuration/configuration-key.md @@ -8,7 +8,7 @@ The following parameters can be configured in Ping CLI's static configuration fi | Config File Property | Type | Equivalent Parameter | Purpose | |---|---|---|---| | activeProfile | ENUM_STRING | | The name of the stored custom configuration profile to use by default. | -| color | ENUM_BOOL | --color | Show text output in color. | +| noColor | ENUM_BOOL | --no-color | Disable text output in color. | | outputFormat | ENUM_OUTPUT_FORMAT | --output-format / -O | Specify the console output format.

Options are: json, text.

Example: `json` | #### Ping Platform Service Properties diff --git a/docs/tool-configuration/example-configuration.md b/docs/tool-configuration/example-configuration.md index 04a0bf5a..d25d64e2 100644 --- a/docs/tool-configuration/example-configuration.md +++ b/docs/tool-configuration/example-configuration.md @@ -3,7 +3,7 @@ ``` activeprofile: default default: - color: true + noColor: true description: Default profile created by pingcli export: format: HCL diff --git a/internal/commands/config/config_internal.go b/internal/commands/config/config_internal.go deleted file mode 100644 index 9d7bf2f2..00000000 --- a/internal/commands/config/config_internal.go +++ /dev/null @@ -1,111 +0,0 @@ -package config_internal - -import ( - "fmt" - "io" - - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/input" - "github.com/pingidentity/pingcli/internal/output" - "github.com/pingidentity/pingcli/internal/profiles" -) - -func RunInternalConfig(rc io.ReadCloser) (err error) { - profileName, newProfileName, newDescription, err := readConfigOptions(rc) - if err != nil { - return fmt.Errorf("failed to update profile. %v", err) - } - - output.Print(output.Opts{ - Message: fmt.Sprintf("Updating profile '%s'...", profileName), - Result: output.ENUM_RESULT_NIL, - }) - - if err = profiles.GetMainConfig().ChangeProfileName(profileName, newProfileName); err != nil { - return fmt.Errorf("failed to update profile '%s' name to: %s. %v", profileName, newProfileName, err) - } - - if err = profiles.GetMainConfig().ChangeProfileDescription(newProfileName, newDescription); err != nil { - return fmt.Errorf("failed to update profile '%s' description to: %s. %v", newProfileName, newDescription, err) - } - - output.Print(output.Opts{ - Message: fmt.Sprintf("Profile updated. Update additional profile attributes via 'pingcli config set' or directly within the config file at '%s'", profiles.GetMainConfig().ViperInstance().ConfigFileUsed()), - Result: output.ENUM_RESULT_SUCCESS, - }) - - return nil -} - -func readConfigOptions(rc io.ReadCloser) (profileName, newName, description string, err error) { - if profileName, err = readConfigProfileNameOption(); err != nil { - return profileName, newName, description, err - } - - if newName, err = readConfigNameOption(rc); err != nil { - return profileName, newName, description, err - } - - if description, err = readConfigDescriptionOption(rc); err != nil { - return profileName, newName, description, err - } - - return profileName, newName, description, nil -} - -func readConfigProfileNameOption() (pName string, err error) { - if !options.ConfigProfileOption.Flag.Changed { - pName, err = profiles.GetOptionValue(options.RootActiveProfileOption) - } else { - pName, err = profiles.GetOptionValue(options.ConfigProfileOption) - } - - if err != nil { - return pName, err - } - - if pName == "" { - return pName, fmt.Errorf("unable to determine profile name to update") - } - - return pName, nil -} - -func readConfigNameOption(rc io.ReadCloser) (newName string, err error) { - if !options.ConfigNameOption.Flag.Changed { - newName, err = input.RunPrompt("New profile name: ", validateChangeProfileName, rc) - } else { - newName, err = profiles.GetOptionValue(options.ConfigNameOption) - } - - if err != nil { - return newName, err - } - - if newName == "" { - return newName, fmt.Errorf("unable to determine new profile name") - } - - return newName, nil -} - -func readConfigDescriptionOption(rc io.ReadCloser) (description string, err error) { - if !options.ConfigDescriptionOption.Flag.Changed { - return input.RunPrompt("New profile description: ", nil, rc) - } else { - return profiles.GetOptionValue(options.ConfigDescriptionOption) - } -} - -func validateChangeProfileName(newName string) (err error) { - oldName, err := readConfigProfileNameOption() - if err != nil { - return err - } - - if err = profiles.GetMainConfig().ValidateUpdateExistingProfileName(oldName, newName); err != nil { - return err - } - - return nil -} diff --git a/internal/commands/config/config_internal_test.go b/internal/commands/config/config_internal_test.go deleted file mode 100644 index f768746e..00000000 --- a/internal/commands/config/config_internal_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package config_internal - -import ( - "os" - "testing" - - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/customtypes" - "github.com/pingidentity/pingcli/internal/testing/testutils" - "github.com/pingidentity/pingcli/internal/testing/testutils_viper" -) - -// Test RunInternalConfig function -func Test_RunInternalConfig(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("test-profile") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - err := RunInternalConfig(os.Stdin) - if err != nil { - t.Errorf("RunInternalConfig returned error: %v", err) - } -} - -// Test RunInternalConfig function fails when existing profile name is provided -func Test_RunInternalConfig_ExistingProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("default") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. profile already exists$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when invalid profile name is provided -func Test_RunInternalConfig_InvalidProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("test-profile!") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when profile name is not provided -func Test_RunInternalConfig_NoProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("production") - profileName = customtypes.String("") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile\. unable to determine new profile name$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} - -// Test RunInternalConfig function fails when provided active profile name -func Test_RunInternalConfig_ActiveProfileName(t *testing.T) { - testutils_viper.InitVipers(t) - - var ( - oldProfile = customtypes.String("default") - profileName = customtypes.String("test-profile") - description = customtypes.String("test-description") - ) - - options.ConfigProfileOption.Flag.Changed = true - options.ConfigProfileOption.CobraParamValue = &oldProfile - - options.ConfigNameOption.Flag.Changed = true - options.ConfigNameOption.CobraParamValue = &profileName - - options.ConfigDescriptionOption.Flag.Changed = true - options.ConfigDescriptionOption.CobraParamValue = &description - - expectedErrorPattern := `^failed to update profile '.*' name to: .*\. '.*' is the active profile and cannot be deleted$` - err := RunInternalConfig(os.Stdin) - testutils.CheckExpectedError(t, err, &expectedErrorPattern) -} diff --git a/internal/commands/config/set_internal_test.go b/internal/commands/config/set_internal_test.go index d01a1edb..4b9314ff 100644 --- a/internal/commands/config/set_internal_test.go +++ b/internal/commands/config/set_internal_test.go @@ -13,7 +13,7 @@ import ( func Test_RunInternalConfigSet(t *testing.T) { testutils_viper.InitVipers(t) - err := RunInternalConfigSet("color=true") + err := RunInternalConfigSet("noColor=true") if err != nil { t.Errorf("RunInternalConfigSet returned error: %v", err) } @@ -33,7 +33,7 @@ func Test_RunInternalConfigSet_InvalidValue(t *testing.T) { testutils_viper.InitVipers(t) expectedErrorPattern := `^failed to set configuration: value for key '.*' must be a boolean. Allowed .*: strconv.ParseBool: parsing ".*": invalid syntax$` - err := RunInternalConfigSet("color=invalid") + err := RunInternalConfigSet("noColor=invalid") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -49,7 +49,7 @@ func Test_RunInternalConfigSet_NonExistentProfileName(t *testing.T) { options.ConfigSetProfileOption.CobraParamValue = &profileName expectedErrorPattern := `^failed to set configuration: invalid profile name: '.*' profile does not exist$` - err := RunInternalConfigSet("color=true") + err := RunInternalConfigSet("noColor=true") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -64,7 +64,7 @@ func Test_RunInternalConfigSet_DifferentProfile(t *testing.T) { options.ConfigSetProfileOption.Flag.Changed = true options.ConfigSetProfileOption.CobraParamValue = &profileName - err := RunInternalConfigSet("color=true") + err := RunInternalConfigSet("noColor=true") if err != nil { t.Errorf("RunInternalConfigSet returned error: %v", err) } @@ -82,7 +82,7 @@ func Test_RunInternalConfigSet_InvalidProfileName(t *testing.T) { options.ConfigSetProfileOption.CobraParamValue = &profileName expectedErrorPattern := `^failed to set configuration: invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$` - err := RunInternalConfigSet("color=true") + err := RunInternalConfigSet("noColor=true") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -91,7 +91,7 @@ func Test_RunInternalConfigSet_NoValue(t *testing.T) { testutils_viper.InitVipers(t) expectedErrorPattern := `^failed to set configuration: value for key '.*' is empty. Use 'pingcli config unset .*' to unset the key$` - err := RunInternalConfigSet("color=") + err := RunInternalConfigSet("noColor=") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } diff --git a/internal/commands/config/unset_internal_test.go b/internal/commands/config/unset_internal_test.go index 61089aea..8a6d60d9 100644 --- a/internal/commands/config/unset_internal_test.go +++ b/internal/commands/config/unset_internal_test.go @@ -13,7 +13,7 @@ import ( func Test_RunInternalConfigUnset(t *testing.T) { testutils_viper.InitVipers(t) - err := RunInternalConfigUnset("color") + err := RunInternalConfigUnset("noColor") if err != nil { t.Errorf("RunInternalConfigUnset returned error: %v", err) } @@ -39,7 +39,7 @@ func Test_RunInternalConfigUnset_DifferentProfile(t *testing.T) { options.ConfigUnsetProfileOption.Flag.Changed = true options.ConfigUnsetProfileOption.CobraParamValue = &profileName - err := RunInternalConfigUnset("color") + err := RunInternalConfigUnset("noColor") if err != nil { t.Errorf("RunInternalConfigUnset returned error: %v", err) } @@ -57,6 +57,6 @@ func Test_RunInternalConfigUnset_InvalidProfileName(t *testing.T) { options.ConfigUnsetProfileOption.CobraParamValue = &profileName expectedErrorPattern := `^failed to unset configuration: invalid profile name: '.*' profile does not exist$` - err := RunInternalConfigUnset("color") + err := RunInternalConfigUnset("noColor") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } diff --git a/internal/configuration/config/add_profile.go b/internal/configuration/config/add_profile.go index 95026b60..d98d8f86 100644 --- a/internal/configuration/config/add_profile.go +++ b/internal/configuration/config/add_profile.go @@ -27,7 +27,6 @@ func initAddProfileDescriptionOption() { Shorthand: "d", Usage: "The description of the new configuration profile.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -49,7 +48,6 @@ func initAddProfileNameOption() { Shorthand: "n", Usage: "The name of the new configuration profile.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -69,9 +67,10 @@ func initAddProfileSetActiveOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: "Set the new configuration profile as the active profile.", - Value: cobraValue, - DefValue: "false", + Usage: "Set the new configuration profile as the active profile. " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "", // No viper key diff --git a/internal/configuration/config/config.go b/internal/configuration/config/config.go deleted file mode 100644 index bf134b1c..00000000 --- a/internal/configuration/config/config.go +++ /dev/null @@ -1,79 +0,0 @@ -package configuration_config - -import ( - "github.com/pingidentity/pingcli/internal/configuration/options" - "github.com/pingidentity/pingcli/internal/customtypes" - "github.com/spf13/pflag" -) - -func InitConfigOptions() { - initConfigProfileOption() - initConfigNameOption() - initConfigDescriptionOption() -} - -func initConfigProfileOption() { - cobraParamName := "profile" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigProfileOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "p", - Usage: "The name of the profile to update. Example: `myAwesomeProfile`", - Value: cobraValue, - DefValue: "The active profile", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} - -func initConfigNameOption() { - cobraParamName := "name" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigNameOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "n", - Usage: "The new name for the profile.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} - -func initConfigDescriptionOption() { - cobraParamName := "description" - cobraValue := new(customtypes.String) - defaultValue := customtypes.String("") - - options.ConfigDescriptionOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: "", // No environment variable - Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "d", - Usage: "The new description for the profile.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_STRING, - ViperKey: "", // No viper key - } -} diff --git a/internal/configuration/config/delete_profile.go b/internal/configuration/config/delete_profile.go index 6cbcf2bb..9c0d0a21 100644 --- a/internal/configuration/config/delete_profile.go +++ b/internal/configuration/config/delete_profile.go @@ -21,11 +21,11 @@ func initDeleteAutoAcceptOption() { DefaultValue: &defaultValue, EnvVar: "", // No environment variable Flag: &pflag.Flag{ - Name: cobraParamName, - Shorthand: "y", - Usage: "Auto-accept the profile deletion confirmation prompt.", + Name: cobraParamName, + Shorthand: "y", + Usage: "Auto-accept the profile deletion confirmation prompt. " + + "(default false)", Value: cobraValue, - DefValue: "false", NoOptDefVal: "true", // Make the flag a boolean flag }, Type: options.ENUM_STRING, diff --git a/internal/configuration/config/get.go b/internal/configuration/config/get.go index ffdfaa27..49ede6ef 100644 --- a/internal/configuration/config/get.go +++ b/internal/configuration/config/get.go @@ -23,9 +23,9 @@ func initGetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to get the configuration value from.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile used to get the configuration value from. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/set.go b/internal/configuration/config/set.go index 90dd99bf..722260c1 100644 --- a/internal/configuration/config/set.go +++ b/internal/configuration/config/set.go @@ -23,9 +23,9 @@ func initSetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile used to set the configuration value to.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile used to set the configuration value to. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/config/unset.go b/internal/configuration/config/unset.go index d8151c4c..08bcb27f 100644 --- a/internal/configuration/config/unset.go +++ b/internal/configuration/config/unset.go @@ -23,9 +23,9 @@ func initUnsetProfileOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "p", - Usage: "The name of the configuration profile to unset a configuration value from.", - Value: cobraValue, - DefValue: "The active profile", + Usage: "The name of the configuration profile to unset a configuration value from. " + + "(default The active profile)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index ff95b30d..cd46d877 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -81,7 +81,6 @@ func OptionFromViperKey(viperKey string) (opt options.Option, err error) { } func InitAllOptions() { - configuration_config.InitConfigOptions() configuration_config.InitConfigAddProfileOptions() configuration_config.InitConfigDeleteProfileOptions() configuration_config.InitConfigSetOptions() diff --git a/internal/configuration/configuration_test.go b/internal/configuration/configuration_test.go index af08730d..79146ece 100644 --- a/internal/configuration/configuration_test.go +++ b/internal/configuration/configuration_test.go @@ -12,7 +12,7 @@ import ( func Test_ValidateViperKey(t *testing.T) { testutils_viper.InitVipers(t) - err := configuration.ValidateViperKey("color") + err := configuration.ValidateViperKey("noColor") if err != nil { t.Errorf("ValidateViperKey returned error: %v", err) } @@ -68,12 +68,12 @@ func Test_ValidateParentViperKey_EmptyKey(t *testing.T) { func Test_OptionFromViperKey(t *testing.T) { testutils_viper.InitVipers(t) - opt, err := configuration.OptionFromViperKey("color") + opt, err := configuration.OptionFromViperKey("noColor") if err != nil { t.Errorf("OptionFromViperKey returned error: %v", err) } - if opt.ViperKey != "color" { + if opt.ViperKey != "noColor" { t.Errorf("OptionFromViperKey returned invalid option: %v", opt) } } diff --git a/internal/configuration/options/options.go b/internal/configuration/options/options.go index 8addec9a..b19e10f5 100644 --- a/internal/configuration/options/options.go +++ b/internal/configuration/options/options.go @@ -67,9 +67,6 @@ func Options() []Option { ProfileDescriptionOption, - ConfigProfileOption, - ConfigNameOption, - ConfigDescriptionOption, ConfigAddProfileDescriptionOption, ConfigAddProfileNameOption, ConfigAddProfileSetActiveOption, @@ -114,10 +111,6 @@ var ( // 'pingcli config' command options var ( - ConfigProfileOption Option - ConfigNameOption Option - ConfigDescriptionOption Option - ConfigAddProfileDescriptionOption Option ConfigAddProfileNameOption Option ConfigAddProfileSetActiveOption Option diff --git a/internal/configuration/platform/export.go b/internal/configuration/platform/export.go index fb45e84b..e40a003e 100644 --- a/internal/configuration/platform/export.go +++ b/internal/configuration/platform/export.go @@ -33,9 +33,13 @@ func initFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "f", - Usage: fmt.Sprintf("Specifies the export format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.ExportFormatValidValues(), ", "), string(customtypes.ENUM_EXPORT_FORMAT_HCL)), - Value: cobraValue, - DefValue: customtypes.ENUM_EXPORT_FORMAT_HCL, + Usage: fmt.Sprintf( + "Specifies the export format. (default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_EXPORT_FORMAT_HCL, + strings.Join(customtypes.ExportFormatValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "export.format", @@ -56,9 +60,18 @@ func initServicesOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf("Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services.\nOptions are: %s.\nExample: `%s,%s,%s`", strings.Join(customtypes.ExportServicesValidValues(), ", "), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE)), - Value: cobraValue, - DefValue: strings.Join(customtypes.ExportServicesValidValues(), ", "), + Usage: fmt.Sprintf( + "Specifies the service(s) to export. Accepts a comma-separated string to delimit multiple services. "+ + "(default %s)"+ + "\nOptions are: %s."+ + "\nExample: '%s,%s,%s'", + strings.Join(customtypes.ExportServicesValidValues(), ", "), + strings.Join(customtypes.ExportServicesValidValues(), ", "), + string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_SSO), + string(customtypes.ENUM_EXPORT_SERVICE_PINGONE_MFA), + string(customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE), + ), + Value: cobraValue, }, Type: options.ENUM_EXPORT_SERVICES, ViperKey: "export.services", @@ -79,9 +92,10 @@ func initOutputDirectoryOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "d", - Usage: "Specifies the output directory for export. Example: `$HOME/pingcli-export`", - Value: cobraValue, - DefValue: "$(pwd)/export", + Usage: "Specifies the output directory for export. " + + "(default $(pwd)/export)" + + "\nExample: '$HOME/pingcli-export'", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "export.outputDirectory", @@ -101,15 +115,37 @@ func initOverwriteOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "o", - Usage: "Overwrite the existing generated exports in output directory.", - Value: cobraValue, - DefValue: "false", + Usage: "Overwrite the existing generated exports in output directory. " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "export.overwrite", } } +func initPingOneEnvironmentIDOption() { + cobraParamName := "pingone-export-environment-id" + cobraValue := new(customtypes.UUID) + defaultValue := customtypes.UUID("") + envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" + + options.PlatformExportPingOneEnvironmentIDOption = options.Option{ + CobraParamName: cobraParamName, + CobraParamValue: cobraValue, + DefaultValue: &defaultValue, + EnvVar: envVar, + Flag: &pflag.Flag{ + Name: cobraParamName, + Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", + Value: cobraValue, + }, + Type: options.ENUM_UUID, + ViperKey: "export.pingone.environmentID", + } +} + func getDefaultExportDir() (defaultExportDir *customtypes.String) { l := logger.Get() pwd, err := os.Getwd() @@ -128,25 +164,3 @@ func getDefaultExportDir() (defaultExportDir *customtypes.String) { return defaultExportDir } - -func initPingOneEnvironmentIDOption() { - cobraParamName := "pingone-export-environment-id" - cobraValue := new(customtypes.UUID) - defaultValue := customtypes.UUID("") - envVar := "PINGCLI_PINGONE_EXPORT_ENVIRONMENT_ID" - - options.PlatformExportPingOneEnvironmentIDOption = options.Option{ - CobraParamName: cobraParamName, - CobraParamValue: cobraValue, - DefaultValue: &defaultValue, - EnvVar: envVar, - Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment to export. Must be a valid PingOne UUID.", - Value: cobraValue, - DefValue: "", - }, - Type: options.ENUM_UUID, - ViperKey: "export.pingone.environmentID", - } -} diff --git a/internal/configuration/request/request.go b/internal/configuration/request/request.go index 3d7d1e7b..7ff1e795 100644 --- a/internal/configuration/request/request.go +++ b/internal/configuration/request/request.go @@ -30,10 +30,10 @@ func initDataOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. Example: `@data.json`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The data to send in the request. Use prefix '@' to specify data file path instead of raw data. " + + "\nExample: '@data.json'", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -53,9 +53,15 @@ func initHTTPMethodOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "m", - Usage: fmt.Sprintf("The HTTP method to use for the request.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.HTTPMethodValidValues(), ", "), string(customtypes.ENUM_HTTP_METHOD_POST)), - Value: cobraValue, - DefValue: customtypes.ENUM_HTTP_METHOD_GET, + Usage: fmt.Sprintf( + "The HTTP method to use for the request. (default %s)"+ + "\nOptions are: %s."+ + "\nExample: '%s'", + customtypes.ENUM_HTTP_METHOD_GET, + strings.Join(customtypes.HTTPMethodValidValues(), ", "), + customtypes.ENUM_HTTP_METHOD_POST, + ), + Value: cobraValue, }, Type: options.ENUM_REQUEST_HTTP_METHOD, ViperKey: "", // No viper key @@ -76,9 +82,14 @@ func initServiceOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "s", - Usage: fmt.Sprintf("The Ping service (configured in the active profile) to send the custom request to.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.RequestServiceValidValues(), ", "), string(customtypes.ENUM_REQUEST_SERVICE_PINGONE)), - Value: cobraValue, - DefValue: "", + Usage: fmt.Sprintf( + "The Ping service (configured in the active profile) to send the custom request to."+ + "\nOptions are: %s."+ + "\nExample: '%s'", + strings.Join(customtypes.RequestServiceValidValues(), ", "), + customtypes.ENUM_REQUEST_SERVICE_PINGONE, + ), + Value: cobraValue, }, Type: options.ENUM_REQUEST_SERVICE, ViperKey: "request.service", diff --git a/internal/configuration/root/root.go b/internal/configuration/root/root.go index c731e0de..a2ca4da6 100644 --- a/internal/configuration/root/root.go +++ b/internal/configuration/root/root.go @@ -48,7 +48,6 @@ func initProfileOption() { Shorthand: "P", Usage: "The name of a configuration profile to use.", Value: cobraValue, - DefValue: "", }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -56,23 +55,23 @@ func initProfileOption() { } func initColorOption() { - cobraParamName := "color" + cobraParamName := "no-color" cobraValue := new(customtypes.Bool) - defaultValue := customtypes.Bool(true) + defaultValue := customtypes.Bool(false) options.RootColorOption = options.Option{ CobraParamName: cobraParamName, CobraParamValue: cobraValue, DefaultValue: &defaultValue, - EnvVar: "PINGCLI_COLOR", + EnvVar: "PINGCLI_NO_COLOR", Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Show text output in color.", - Value: cobraValue, - DefValue: "true", + Name: cobraParamName, + Usage: "Disable text output in color. (default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, - ViperKey: "color", + ViperKey: "noColor", } } @@ -89,9 +88,9 @@ func initConfigOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "C", - Usage: "The relative or full path to a custom Ping CLI configuration file. Example: `$HOME/.pingcli/config.yaml`", - Value: cobraValue, - DefValue: "\"$HOME/.pingcli/config.yaml\"", + Usage: "The relative or full path to a custom Ping CLI configuration file. " + + "(default $HOME/.pingcli/config.yaml)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "", // No viper key @@ -111,9 +110,14 @@ func initOutputFormatOption() { Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "O", - Usage: fmt.Sprintf("Specify the console output format.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.OutputFormatValidValues(), ", "), string(customtypes.ENUM_OUTPUT_FORMAT_JSON)), - Value: cobraValue, - DefValue: customtypes.ENUM_OUTPUT_FORMAT_TEXT, + Usage: fmt.Sprintf( + "Specify the console output format. "+ + "(default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_OUTPUT_FORMAT_TEXT, + strings.Join(customtypes.OutputFormatValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_OUTPUT_FORMAT, ViperKey: "outputFormat", diff --git a/internal/configuration/services/pingfederate.go b/internal/configuration/services/pingfederate.go index 5b439c1b..cba1a6d3 100644 --- a/internal/configuration/services/pingfederate.go +++ b/internal/configuration/services/pingfederate.go @@ -37,10 +37,10 @@ func initHTTPSHostOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API.\nExample: `https://pingfederate-admin.bxretail.org`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate HTTPS host used to communicate with PingFederate's admin API." + + "\nExample: 'https://pingfederate-admin.bxretail.org'", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.httpsHost", @@ -59,10 +59,10 @@ func initAdminAPIPathOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API.\nExample: `/pf-admin-api/v1`", - Value: cobraValue, - DefValue: "/pf-admin-api/v1", + Name: cobraParamName, + Usage: "The PingFederate API URL path used to communicate with PingFederate's admin API. " + + "(default /pf-admin-api/v1)", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.adminAPIPath", @@ -81,10 +81,12 @@ func initXBypassExternalValidationHeaderOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header when using PingFederate's admin API).", - Value: cobraValue, - DefValue: "false", + Name: cobraParamName, + Usage: "Bypass connection tests when configuring PingFederate (the X-BypassExternalValidation header " + + "when using PingFederate's admin API). " + + "(default false)", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.xBypassExternalValidationHeader", @@ -103,10 +105,12 @@ func initCACertificatePemFilesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when connecting to the PingFederate server over HTTPS.\nAccepts a comma-separated string to delimit multiple PEM files.", - Value: cobraValue, - DefValue: "[]", + Name: cobraParamName, + Usage: "Relative or full paths to PEM-encoded certificate files to be trusted as root CAs when " + + "connecting to the PingFederate server over HTTPS. " + + "(default [])" + + "\nAccepts a comma-separated string to delimit multiple PEM files.", + Value: cobraValue, }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.caCertificatePemFiles", @@ -125,10 +129,12 @@ func initInsecureTrustAllTLSOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "Trust any certificate when connecting to the PingFederate server admin API.\nThis is insecure and should not be enabled outside of testing.", - Value: cobraValue, - DefValue: "false", + Name: cobraParamName, + Usage: "Trust any certificate when connecting to the PingFederate server admin API. " + + "(default false)" + + "\nThis is insecure and should not be enabled outside of testing.", + Value: cobraValue, + NoOptDefVal: "true", // Make this flag a boolean flag }, Type: options.ENUM_BOOL, ViperKey: "service.pingfederate.insecureTrustAllTLS", @@ -147,10 +153,11 @@ func initUsernameOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic authentication. Example: `administrator`", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate username used to authenticate to the PingFederate admin API when using basic " + + "authentication." + + "\nExample: 'administrator'", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.username", @@ -169,10 +176,10 @@ func initPasswordOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic authentication.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate password used to authenticate to the PingFederate admin API when using basic " + + "authentication.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.basicAuth.password", @@ -191,10 +198,10 @@ func initAccessTokenOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a custom OAuth 2.0 token method.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate access token used to authenticate to the PingFederate admin API when using a " + + "custom OAuth 2.0 token method.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.accessTokenAuth.accessToken", @@ -213,10 +220,10 @@ func initClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth client ID used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientID", @@ -235,10 +242,10 @@ func initClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth client secret used to authenticate to the PingFederate admin API when " + + "using the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.clientSecret", @@ -257,10 +264,10 @@ func initTokenURLOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The PingFederate OAuth token URL used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.tokenURL", @@ -279,10 +286,13 @@ func initScopesOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using the OAuth 2.0 client credentials grant type.\nAccepts a comma-separated string to delimit multiple scopes.\nExample: `openid,profile`", - Value: cobraValue, - DefValue: "[]", + Name: cobraParamName, + Usage: "The PingFederate OAuth scopes used to authenticate to the PingFederate admin API when using " + + "the OAuth 2.0 client credentials grant type. " + + "(default [])" + + "\nAccepts a comma-separated string to delimit multiple scopes." + + "\nExample: 'openid,profile'", + Value: cobraValue, }, Type: options.ENUM_STRING_SLICE, ViperKey: "service.pingfederate.authentication.clientCredentialsAuth.scopes", @@ -301,10 +311,15 @@ func initPingFederateAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The authentication type to use when connecting to the PingFederate admin API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC)), - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: fmt.Sprintf( + "The authentication type to use when connecting to the PingFederate admin API."+ + "\nOptions are: %s."+ + "\nExample: '%s'", + strings.Join(customtypes.PingFederateAuthenticationTypeValidValues(), ", "), + customtypes.ENUM_PINGFEDERATE_AUTHENTICATION_TYPE_BASIC, + ), + Value: cobraValue, }, Type: options.ENUM_PINGFEDERATE_AUTH_TYPE, ViperKey: "service.pingfederate.authentication.type", diff --git a/internal/configuration/services/pingone.go b/internal/configuration/services/pingone.go index 43367ba1..917d4ae9 100644 --- a/internal/configuration/services/pingone.go +++ b/internal/configuration/services/pingone.go @@ -30,10 +30,9 @@ func initAuthenticationWorkerClientIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client ID used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The worker client ID used to authenticate to the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.clientID", @@ -52,10 +51,9 @@ func initAuthenticationWorkerClientSecretOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The worker client secret used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The worker client secret used to authenticate to the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_STRING, ViperKey: "service.pingone.authentication.worker.clientSecret", @@ -74,10 +72,10 @@ func initAuthenticationWorkerEnvironmentIDOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to the PingOne management API.", - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: "The ID of the PingOne environment that contains the worker client used to authenticate to " + + "the PingOne management API.", + Value: cobraValue, }, Type: options.ENUM_UUID, ViperKey: "service.pingone.authentication.worker.environmentID", @@ -96,10 +94,14 @@ func initPingOneAuthenticationTypeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The authentication type to use to authenticate to the PingOne management API.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), string(customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER)), - Value: cobraValue, - DefValue: customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, + Name: cobraParamName, + Usage: fmt.Sprintf( + "The authentication type to use to authenticate to the PingOne management API. (default %s)"+ + "\nOptions are: %s.", + customtypes.ENUM_PINGONE_AUTHENTICATION_TYPE_WORKER, + strings.Join(customtypes.PingOneAuthenticationTypeValidValues(), ", "), + ), + Value: cobraValue, }, Type: options.ENUM_PINGONE_AUTH_TYPE, ViperKey: "service.pingone.authentication.type", @@ -118,10 +120,15 @@ func initRegionCodeOption() { DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ - Name: cobraParamName, - Usage: fmt.Sprintf("The region code of the PingOne tenant.\nOptions are: %s.\nExample: `%s`", strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), string(customtypes.ENUM_PINGONE_REGION_CODE_NA)), - Value: cobraValue, - DefValue: "", + Name: cobraParamName, + Usage: fmt.Sprintf( + "The region code of the PingOne tenant."+ + "\nOptions are: %s."+ + "\nExample: '%s'", + strings.Join(customtypes.PingOneRegionCodeValidValues(), ", "), + customtypes.ENUM_PINGONE_REGION_CODE_NA, + ), + Value: cobraValue, }, Type: options.ENUM_PINGONE_REGION_CODE, ViperKey: "service.pingone.regionCode", diff --git a/internal/output/output.go b/internal/output/output.go index f45a96a3..46368134 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -40,15 +40,15 @@ const ( ) func SetColorize() { - colorizeOutput, err := profiles.GetOptionValue(options.RootColorOption) + disableColorOutput, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { color.NoColor = false } else { - colorizeOutputBool, err := strconv.ParseBool(colorizeOutput) + disableColorOutputBool, err := strconv.ParseBool(disableColorOutput) if err != nil { color.NoColor = false } else { - color.NoColor = !colorizeOutputBool + color.NoColor = disableColorOutputBool } } } diff --git a/internal/profiles/validate_test.go b/internal/profiles/validate_test.go index aa27f6e5..e0192e20 100644 --- a/internal/profiles/validate_test.go +++ b/internal/profiles/validate_test.go @@ -56,7 +56,7 @@ func TestValidateInvalidBool(t *testing.T) { default: description: "default description" pingcli: - color: invalid` + noColor: invalid` testutils_viper.InitVipersCustomFile(t, fileContents) diff --git a/internal/testing/testutils_viper/viper_utils.go b/internal/testing/testutils_viper/viper_utils.go index 18922b9e..7d28fcd8 100644 --- a/internal/testing/testutils_viper/viper_utils.go +++ b/internal/testing/testutils_viper/viper_utils.go @@ -20,7 +20,7 @@ var ( defaultConfigFileContentsPattern string = `activeProfile: default default: description: "default description" - color: true + noColor: true outputFormat: text export: outputDirectory: %s @@ -47,7 +47,7 @@ default: xBypassExternalValidationHeader: true production: description: "test profile description" - color: true + noColor: true outputFormat: text service: pingfederate: