Skip to content

Commit

Permalink
PDI-1454: CLI v2 Command: Custom Request (#135)
Browse files Browse the repository at this point in the history
* PDI-1454: CLI v2 Command: Custom Request

- Add Command Usage examples and Configuration format examples to Cobra
usage messages where applicable.
- Unite all Pingone and Pingfederate configuration options under 'service'
parent, now used by both 'platform export' and 'request' commands.
- Add 'authentication' parent in service configuration to allow the
user to directly specify which authentication method to use. This removes
the flag exclusivity requirement on the 'platform export' command, as well as removes
authentication "hierarchy" in pingfederate go-client authentication logic.
- Refactor MultiService custom map type to ExportServices []string type.
- Add new command 'request' to send custom requests to PingIdentity services. Currently,
only PingOne is supported.
- Add multiple additional custom types to support Ints, authentication types, HTTP methods, and request
services.
- In the configuration file, support Yaml array lists for scopes, CA cert files, and Export services.
- Use PingOne region codes instead of deprecated PingOne Regions.
- Various testing fixes and additions.
  • Loading branch information
erikostien-pingidentity authored Sep 20, 2024
1 parent a3560e2 commit 1cc16e9
Show file tree
Hide file tree
Showing 63 changed files with 2,772 additions and 1,182 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/code-analysis-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ jobs:
PING_IDENTITY_CONFIG: ${{ secrets.PING_IDENTITY_CONFIG }}
PINGCTL_PINGONE_WORKER_CLIENT_ID: ${{ secrets.PINGCTL_PINGONE_WORKER_CLIENT_ID }}
PINGCTL_PINGONE_WORKER_CLIENT_SECRET: ${{ secrets.PINGCTL_PINGONE_WORKER_CLIENT_SECRET }}
PINGCTL_PINGONE_REGION: ${{ secrets.PINGCTL_PINGONE_REGION }}
PINGCTL_PINGONE_REGION_CODE: ${{ secrets.PINGCTL_PINGONE_REGION_CODE }}
PINGCTL_PINGONE_WORKER_ENVIRONMENT_ID: ${{ secrets.PINGCTL_PINGONE_WORKER_ENVIRONMENT_ID }}
PINGCTL_PINGONE_EXPORT_ENVIRONMENT_ID: ${{ secrets.PINGCTL_PINGONE_EXPORT_ENVIRONMENT_ID }}
PINGONE_CLIENT_ID: ${{ secrets.PINGONE_CLIENT_ID }}
PINGONE_CLIENT_SECRET: ${{ secrets.PINGONE_CLIENT_SECRET }}
PINGONE_ENVIRONMENT_ID: ${{ secrets.PINGONE_ENVIRONMENT_ID }}
Expand Down
19 changes: 12 additions & 7 deletions cmd/config/add_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ import (
"github.com/spf13/cobra"
)

const (
addProfilecommandExamples = `Command Usage Examples:
pingctl config add-profile
pingctl config add-profile --name myprofile --description "My Profile desc"
pingctl config add-profile --set-active=true`
)

func NewConfigAddProfileCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(0),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config add-profile
pingctl config add-profile --name myprofile --description "My Profile desc"
pingctl config add-profile --set-active=true`,
Long: `Add a new configuration profile to pingctl.`,
RunE: configAddProfileRunE,
Short: "Add a new configuration profile to pingctl.",
Use: "add-profile [flags]",
Example: addProfilecommandExamples,
Long: `Add a new configuration profile to pingctl.`,
RunE: configAddProfileRunE,
Short: "Add a new configuration profile to pingctl.",
Use: "add-profile [flags]",
}

cmd.Flags().AddFlag(options.ConfigAddProfileNameOption.Flag)
Expand Down
19 changes: 12 additions & 7 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ import (
"github.com/spf13/cobra"
)

const (
configCommandExamples = `Command Usage Examples:
pingctl config
pingctl config --profile myprofile
pingctl 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: `pingctl config
pingctl config --profile myprofile
pingctl config --name myprofile --description "My Profile"`,
Long: `Update an existing configuration profile's name and description. See subcommands for more profile configuration management options.`,
RunE: configRunE,
Short: "Update an existing configuration profile's name and description. See subcommands for more profile configuration management options.",
Use: "config [flags]",
Example: configCommandExamples,
Long: `Update an existing configuration profile's name and description. See subcommands for more profile configuration management options.`,
RunE: configRunE,
Short: "Update an existing configuration profile's name and description. See subcommands for more profile configuration management options.",
Use: "config [flags]",
}

// Add subcommands
Expand Down
17 changes: 11 additions & 6 deletions cmd/config/delete_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import (
"github.com/spf13/cobra"
)

const (
deleteProfileCommandExamples = `Command Usage Examples:
pingctl config delete-profile
pingctl config delete-profile --profile myprofile`
)

func NewConfigDeleteProfileCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(0),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config delete-profile
pingctl config delete-profile --profile myprofile`,
Long: `Delete a configuration profile from pingctl.`,
RunE: configDeleteProfileRunE,
Short: "Delete a configuration profile from pingctl.",
Use: "delete-profile [flags]",
Example: deleteProfileCommandExamples,
Long: `Delete a configuration profile from pingctl.`,
RunE: configDeleteProfileRunE,
Short: "Delete a configuration profile from pingctl.",
Use: "delete-profile [flags]",
}

cmd.Flags().AddFlag(options.ConfigDeleteProfileOption.Flag)
Expand Down
19 changes: 12 additions & 7 deletions cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import (
"github.com/spf13/cobra"
)

const (
configGetCommandExamples = `Command Usage Examples:
pingctl config get pingone
pingctl config get --profile myProfile color
pingctl config get service.pingone.authentication.worker.environmentID`
)

func NewConfigGetCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(1),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config get pingone
pingctl config get --profile myProfile pingctl.color
pingctl config get pingone.export.environmentID`,
Long: `Get pingctl configuration settings.`,
RunE: configGetRunE,
Short: "Get pingctl configuration settings.",
Use: "get [flags] key",
Example: configGetCommandExamples,
Long: `Get pingctl configuration settings.`,
RunE: configGetRunE,
Short: "Get pingctl configuration settings.",
Use: "get [flags] key",
}

cmd.Flags().AddFlag(options.ConfigGetProfileOption.Flag)
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func TestConfigGetCmd_TooManyArgs(t *testing.T) {

// Test Config Get Command Executes when provided a full key
func TestConfigGetCmd_FullKey(t *testing.T) {
err := testutils_cobra.ExecutePingctl(t, "config", "get", options.PlatformExportPingoneWorkerClientIDOption.ViperKey)
err := testutils_cobra.ExecutePingctl(t, "config", "get", options.PingoneAuthenticationWorkerClientIDOption.ViperKey)
testutils.CheckExpectedError(t, err, nil)
}

// Test Config Get Command Executes when provided a partial key
func TestConfigGetCmd_PartialKey(t *testing.T) {
err := testutils_cobra.ExecutePingctl(t, "config", "get", "export.pingone")
err := testutils_cobra.ExecutePingctl(t, "config", "get", "service.pingone")
testutils.CheckExpectedError(t, err, nil)
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/config/list_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
"github.com/spf13/cobra"
)

const (
listProfilesCommandExamples = `Command Usage Examples:
pingctl config list-profiles`
)

func NewConfigListProfilesCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(0),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config list-profiles`,
Example: listProfilesCommandExamples,
Long: `List all configuration profiles from pingctl.`,
RunE: configListProfilesRunE,
Short: "List all configuration profiles from pingctl.",
Expand Down
17 changes: 11 additions & 6 deletions cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import (
"github.com/spf13/cobra"
)

const (
configSetCommandExamples = `Command Usage Examples:
pingctl config set color=true
pingctl config set --profile myProfile service.pingone.regionCode=AP`
)

func NewConfigSetCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(1),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config set pingctl.color=true
pingctl config set --profile myProfile pingone.region=AsiaPacific`,
Long: `Set pingctl configuration settings.`,
RunE: configSetRunE,
Short: "Set pingctl configuration settings.",
Use: "set [flags] key=value",
Example: configSetCommandExamples,
Long: `Set pingctl configuration settings.`,
RunE: configSetRunE,
Short: "Set pingctl configuration settings.",
Use: "set [flags] key=value",
}

cmd.Flags().AddFlag(options.ConfigSetProfileOption.Flag)
Expand Down
17 changes: 11 additions & 6 deletions cmd/config/set_active_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import (
"github.com/spf13/cobra"
)

const (
setActiveProfileCommandExamples = `Command Usage Examples:
pingctl config set-active-profile
pingctl config set-active-profile --profile myprofile`
)

func NewConfigSetActiveProfileCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(0),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config set-active-profile
pingctl config set-active-profile --profile myprofile`,
Long: `Set a configuration profile as the in-use profile for pingctl.`,
RunE: configSetActiveProfileRunE,
Short: "Set a configuration profile as the in-use profile for pingctl.",
Use: "set-active-profile [flags]",
Example: setActiveProfileCommandExamples,
Long: `Set a configuration profile as the in-use profile for pingctl.`,
RunE: configSetActiveProfileRunE,
Short: "Set a configuration profile as the in-use profile for pingctl.",
Use: "set-active-profile [flags]",
}

cmd.Flags().AddFlag(options.ConfigSetActiveProfileOption.Flag)
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func TestConfigSetCmd_InvalidValueType(t *testing.T) {

// Test Config Set Command Fails when no value is provided
func TestConfigSetCmd_NoValueProvided(t *testing.T) {
expectedErrorPattern := `^failed to set configuration: value for key 'pingctl\.color' is empty\. Use 'pingctl config unset pingctl\.color' to unset the key$`
expectedErrorPattern := `^failed to set configuration: value for key '.*' is empty\. Use 'pingctl config unset .*' to unset the key$`
err := testutils_cobra.ExecutePingctl(t, "config", "set", fmt.Sprintf("%s=", options.RootColorOption.ViperKey))
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test Config Set Command for key 'pingone.worker.clientId' updates viper configuration
func TestConfigSetCmd_CheckViperConfig(t *testing.T) {
viperKey := options.PlatformExportPingoneWorkerClientIDOption.ViperKey
viperKey := options.PingoneAuthenticationWorkerClientIDOption.ViperKey
viperNewUUID := "12345678-1234-1234-1234-123456789012"

err := testutils_cobra.ExecutePingctl(t, "config", "set", fmt.Sprintf("%s=%s", viperKey, viperNewUUID))
Expand Down
17 changes: 11 additions & 6 deletions cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import (
"github.com/spf13/cobra"
)

const (
configUnsetCommandExamples = `Command Usage Examples:
pingctl config unset color
pingctl config unset --profile myProfile service.pingone.regionCode`
)

func NewConfigUnsetCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(1),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config unset pingctl.color
pingctl config unset --profile myProfile pingone.region`,
Long: `Unset pingctl configuration settings.`,
RunE: configUnsetRunE,
Short: "Unset pingctl configuration settings.",
Use: "unset [flags] key",
Example: configUnsetCommandExamples,
Long: `Unset pingctl configuration settings.`,
RunE: configUnsetRunE,
Short: "Unset pingctl configuration settings.",
Use: "unset [flags] key",
}

cmd.Flags().AddFlag(options.ConfigUnsetProfileOption.Flag)
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestConfigUnsetCmd_InvalidKey(t *testing.T) {

// Test Config Unset Command for key 'pingone.worker.clientId' updates viper configuration
func TestConfigUnsetCmd_CheckViperConfig(t *testing.T) {
viperKey := options.PlatformExportPingoneWorkerClientIDOption.ViperKey
viperOldValue := os.Getenv(options.PlatformExportPingoneWorkerClientIDOption.EnvVar)
viperKey := options.PingoneAuthenticationWorkerClientIDOption.ViperKey
viperOldValue := os.Getenv(options.PingoneAuthenticationWorkerClientIDOption.EnvVar)

err := testutils_cobra.ExecutePingctl(t, "config", "unset", viperKey)
testutils.CheckExpectedError(t, err, nil)
Expand Down
17 changes: 11 additions & 6 deletions cmd/config/view_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import (
"github.com/spf13/cobra"
)

const (
viewProfileCommandExamples = `Command Usage Examples:
pingctl config view-profile
pingctl config view-profile --profile myprofile`
)

func NewConfigViewProfileCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(0),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: `pingctl config view-profile
pingctl config view-profile --profile myprofile`,
Long: `View a configuration profile from pingctl.`,
RunE: configViewProfileRunE,
Short: "View a configuration profile from pingctl.",
Use: "view-profile [flags]",
Example: viewProfileCommandExamples,
Long: `View a configuration profile from pingctl.`,
RunE: configViewProfileRunE,
Short: "View a configuration profile from pingctl.",
Use: "view-profile [flags]",
}

cmd.Flags().AddFlag(options.ConfigViewProfileOption.Flag)
Expand Down
Loading

0 comments on commit 1cc16e9

Please sign in to comment.