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
2 changes: 1 addition & 1 deletion cmd/config/add_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/add_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
35 changes: 8 additions & 27 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand All @@ -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
// }
45 changes: 24 additions & 21 deletions cmd/platform/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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",
Expand All @@ -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),
Expand All @@ -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",
Expand All @@ -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: \<!DOCTYPE html\>\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),
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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),
Expand All @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/tool-configuration/configuration-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>Options are: json, text.<br><br>Example: `json` |

#### Ping Platform Service Properties
Expand Down
2 changes: 1 addition & 1 deletion docs/tool-configuration/example-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
activeprofile: default
default:
color: true
noColor: true
description: Default profile created by pingcli
export:
format: HCL
Expand Down
Loading