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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ linters:
- ineffassign
- interfacebloat
- intrange
- ireturn
- makezero
- mirror
- misspell
Expand Down
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ devcheck: devchecknotest spincontainer test removetestcontainer

importfmtlint:
@echo -n "Running 'impi' to format import ordering..."
@if go tool impi --local . --scheme stdThirdPartyLocal ./...; then \
@if go tool impi --skip internal/proto/pingcli_command --local . --scheme stdThirdPartyLocal ./...; then \
echo " SUCCESS"; \
else \
echo " FAILED"; \
Expand All @@ -111,7 +111,12 @@ importfmtlint:
golangcilint:
@echo -n "Running 'golangci-lint' to check for code quality issues... "
@# Clear the cache for every run, so that the linter outputs the same results as the GH Actions workflow
@go tool golangci-lint cache clean && go tool golangci-lint run --timeout 5m ./...
@if go tool golangci-lint cache clean && go tool golangci-lint run --timeout 5m ./...; then \
echo "SUCCESS"; \
else \
echo "FAILED"; \
exit 1; \
fi

starttestcontainer: --checkpfcontainerenvvars --checkdocker --dockerrunpf --waitforpfhealthy

Expand Down Expand Up @@ -186,3 +191,12 @@ openapp:
echo " FAILED"; \
exit 1; \
fi

protogen:
@echo -n "Running 'protoc' to generate Go code from proto files..."
@if protoc --proto_path=./internal/proto --go_out=./internal --go-grpc_out=./internal ./internal/proto/*.proto; then \
echo " SUCCESS"; \
else \
echo " FAILED"; \
exit 1; \
fi
1 change: 1 addition & 0 deletions cmd/config/list_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Example_listKeysValue() {
// - export.services
// - noColor
// - outputFormat
// - plugins
// - request.accessToken
// - request.accessTokenExpiry
// - request.fail
Expand Down
2 changes: 2 additions & 0 deletions cmd/config/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func TestConfigUnsetCmd_CheckKoanfConfig(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t, "config", "unset", koanfKey)
testutils.CheckExpectedError(t, err, nil)

koanfConfig = profiles.GetKoanfConfig().KoanfInstance()

koanfNewValue := koanfConfig.String(profileKoanfKey)
if koanfOldValue == koanfNewValue {
t.Errorf("Expected koanf configuration value to be updated. Old: %s, New: %s", koanfOldValue, koanfNewValue)
Expand Down
36 changes: 34 additions & 2 deletions cmd/platform/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

// Test Platform Export Command Executes without issue
func TestPlatformExportCmd_Execute(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -25,8 +26,6 @@ func TestPlatformExportCmd_Execute(t *testing.T) {

// Test Platform Export Command fails when provided too many arguments
func TestPlatformExportCmd_TooManyArgs(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^failed to execute 'pingcli platform export': command accepts 0 arg\(s\), received 1$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export", "extra-arg")
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
Expand All @@ -50,6 +49,7 @@ func TestPlatformExportCmd_HelpFlag(t *testing.T) {

// Test Platform Export Command --service-group, -g flag
func TestPlatformExportCmd_ServiceGroupFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -61,6 +61,8 @@ func TestPlatformExportCmd_ServiceGroupFlag(t *testing.T) {

// Test Platform Export Command --service-group with non-supported service group
func TestPlatformExportCmd_ServiceGroupFlagInvalidServiceGroup(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^invalid argument ".*" for "-g, --service-group" flag: unrecognized service group '.*'\. Must be one of: .*$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PlatformExportServiceGroupOption.CobraParamName, "invalid")
Expand All @@ -69,6 +71,7 @@ func TestPlatformExportCmd_ServiceGroupFlagInvalidServiceGroup(t *testing.T) {

// Test Platform Export Command --services flag
func TestPlatformExportCmd_ServicesFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -80,6 +83,8 @@ func TestPlatformExportCmd_ServicesFlag(t *testing.T) {

// Test Platform Export Command --services flag with invalid service
func TestPlatformExportCmd_ServicesFlagInvalidService(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^invalid argument ".*" for "-s, --services" flag: failed to set ExportServices: Invalid service: .*\. Allowed services: .*$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PlatformExportServiceOption.CobraParamName, "invalid")
Expand All @@ -88,6 +93,7 @@ func TestPlatformExportCmd_ServicesFlagInvalidService(t *testing.T) {

// Test Platform Export Command --format flag
func TestPlatformExportCmd_ExportFormatFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -100,6 +106,8 @@ func TestPlatformExportCmd_ExportFormatFlag(t *testing.T) {

// Test Platform Export Command --format flag with invalid format
func TestPlatformExportCmd_ExportFormatFlagInvalidFormat(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^invalid argument ".*" for "-f, --format" flag: unrecognized export format '.*'\. Must be one of: .*$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PlatformExportExportFormatOption.CobraParamName, "invalid")
Expand All @@ -108,6 +116,7 @@ func TestPlatformExportCmd_ExportFormatFlagInvalidFormat(t *testing.T) {

// Test Platform Export Command --output-directory flag
func TestPlatformExportCmd_OutputDirectoryFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -119,6 +128,8 @@ func TestPlatformExportCmd_OutputDirectoryFlag(t *testing.T) {

// Test Platform Export Command --output-directory flag with invalid directory
func TestPlatformExportCmd_OutputDirectoryFlagInvalidDirectory(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^failed to create output directory '\/invalid': mkdir \/invalid: .+$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PlatformExportOutputDirectoryOption.CobraParamName, "/invalid")
Expand All @@ -127,6 +138,7 @@ func TestPlatformExportCmd_OutputDirectoryFlagInvalidDirectory(t *testing.T) {

// Test Platform Export Command --overwrite flag
func TestPlatformExportCmd_OverwriteFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -139,6 +151,7 @@ func TestPlatformExportCmd_OverwriteFlag(t *testing.T) {
// Test Platform Export Command --overwrite flag false with existing directory
// where the directory already contains a file
func TestPlatformExportCmd_OverwriteFlagFalseWithExistingDirectory(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

_, err := os.Create(outputDir + "/file") //#nosec G304 -- this is a test
Expand All @@ -157,6 +170,7 @@ func TestPlatformExportCmd_OverwriteFlagFalseWithExistingDirectory(t *testing.T)
// Test Platform Export Command --overwrite flag true with existing directory
// where the directory already contains a file
func TestPlatformExportCmd_OverwriteFlagTrueWithExistingDirectory(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

_, err := os.Create(outputDir + "/file") //#nosec G304 -- this is a test
Expand All @@ -177,6 +191,7 @@ func TestPlatformExportCmd_OverwriteFlagTrueWithExistingDirectory(t *testing.T)
// --pingone-worker-client-secret flag
// --pingone-region flag
func TestPlatformExportCmd_PingOneWorkerEnvironmentIdFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -192,6 +207,8 @@ func TestPlatformExportCmd_PingOneWorkerEnvironmentIdFlag(t *testing.T) {

// Test Platform Export Command fails when not provided required pingone flags together
func TestPlatformExportCmd_PingOneWorkerEnvironmentIdFlagRequiredTogether(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^if any flags in the group \[pingone-worker-environment-id pingone-worker-client-id pingone-worker-client-secret pingone-region-code] are set they must all be set; missing \[pingone-region-code pingone-worker-client-id pingone-worker-client-secret]$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PingOneAuthenticationWorkerEnvironmentIDOption.CobraParamName, os.Getenv("TEST_PINGONE_ENVIRONMENT_ID"))
Expand All @@ -200,6 +217,7 @@ func TestPlatformExportCmd_PingOneWorkerEnvironmentIdFlagRequiredTogether(t *tes

// Test Platform Export command with PingFederate Basic Auth flags
func TestPlatformExportCmd_PingFederateBasicAuthFlags(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -215,6 +233,8 @@ func TestPlatformExportCmd_PingFederateBasicAuthFlags(t *testing.T) {

// Test Platform Export Command fails when not provided required PingFederate Basic Auth flags together
func TestPlatformExportCmd_PingFederateBasicAuthFlagsRequiredTogether(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^if any flags in the group \[pingfederate-username pingfederate-password] are set they must all be set; missing \[pingfederate-password]$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PingFederateBasicAuthUsernameOption.CobraParamName, "Administrator")
Expand All @@ -223,6 +243,7 @@ func TestPlatformExportCmd_PingFederateBasicAuthFlagsRequiredTogether(t *testing

// Test Platform Export Command fails when provided invalid PingOne Client Credential flags
func TestPlatformExportCmd_PingOneClientCredentialFlagsInvalid(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

expectedErrorPattern := `^failed to initialize pingone API client\. Check worker client ID, worker client secret, worker environment ID, and pingone region code configuration values\. oauth2: \"invalid_client\" \"Request denied: Unsupported authentication method \(Correlation ID: .*\)\"$`
Expand All @@ -240,6 +261,7 @@ func TestPlatformExportCmd_PingOneClientCredentialFlagsInvalid(t *testing.T) {

// Test Platform Export Command fails when provided invalid PingFederate Basic Auth flags
func TestPlatformExportCmd_PingFederateBasicAuthFlagsInvalid(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

expectedErrorPattern := `^failed to initialize PingFederate Go Client. Check authentication type and credentials$`
Expand All @@ -256,6 +278,8 @@ func TestPlatformExportCmd_PingFederateBasicAuthFlagsInvalid(t *testing.T) {

// Test Platform Export Command fails when not provided required PingFederate Client Credentials Auth flags together
func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsRequiredTogether(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^if any flags in the group \[pingfederate-client-id pingfederate-client-secret pingfederate-token-url] are set they must all be set; missing \[pingfederate-client-secret pingfederate-token-url]$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PingFederateClientCredentialsAuthClientIDOption.CobraParamName, "test")
Expand All @@ -264,6 +288,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsRequiredTogethe

// Test Platform Export Command fails when provided invalid PingFederate Client Credentials Auth flags
func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalid(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

expectedErrorPattern := `^failed to initialize PingFederate Go Client. Check authentication type and credentials$`
Expand All @@ -282,6 +307,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalid(t *test

// Test Platform Export Command fails when provided invalid PingFederate OAuth2 Token URL
func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalidTokenURL(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

expectedErrorPattern := `^failed to initialize PingFederate Go Client. Check authentication type and credentials$`
Expand All @@ -299,6 +325,7 @@ func TestPlatformExportCmd_PingFederateClientCredentialsAuthFlagsInvalidTokenURL

// Test Platform Export command with PingFederate X-Bypass Header set to true
func TestPlatformExportCmd_PingFederateXBypassHeaderFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -315,6 +342,7 @@ func TestPlatformExportCmd_PingFederateXBypassHeaderFlag(t *testing.T) {

// Test Platform Export command with PingFederate --pingfederate-insecure-trust-all-tls flag set to true
func TestPlatformExportCmd_PingFederateTrustAllTLSFlag(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -331,6 +359,7 @@ func TestPlatformExportCmd_PingFederateTrustAllTLSFlag(t *testing.T) {

// Test Platform Export command fails with PingFederate --pingfederate-insecure-trust-all-tls flag set to false
func TestPlatformExportCmd_PingFederateTrustAllTLSFlagFalse(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

expectedErrorPattern := `^failed to initialize PingFederate Go Client. Check authentication type and credentials$`
Expand All @@ -350,6 +379,7 @@ func TestPlatformExportCmd_PingFederateTrustAllTLSFlagFalse(t *testing.T) {
// --pingfederate-insecure-trust-all-tls=false
// and --pingfederate-ca-certificate-pem-files set
func TestPlatformExportCmd_PingFederateCaCertificatePemFiles(t *testing.T) {
testutils_koanf.InitKoanfs(t)
outputDir := t.TempDir()

err := testutils_cobra.ExecutePingcli(t, "platform", "export",
Expand All @@ -367,6 +397,8 @@ func TestPlatformExportCmd_PingFederateCaCertificatePemFiles(t *testing.T) {

// Test Platform Export command fails with --pingfederate-ca-certificate-pem-files set to non-existent file.
func TestPlatformExportCmd_PingFederateCaCertificatePemFilesInvalid(t *testing.T) {
testutils_koanf.InitKoanfs(t)

expectedErrorPattern := `^failed to read CA certificate PEM file '.*': open .*: no such file or directory$`
err := testutils_cobra.ExecutePingcli(t, "platform", "export",
"--"+options.PlatformExportServiceOption.CobraParamName, customtypes.ENUM_EXPORT_SERVICE_PINGFEDERATE,
Expand Down
40 changes: 40 additions & 0 deletions cmd/plugin/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright © 2025 Ping Identity Corporation

package plugin

import (
"github.com/pingidentity/pingcli/cmd/common"
plugin_internal "github.com/pingidentity/pingcli/internal/commands/plugin"
"github.com/pingidentity/pingcli/internal/logger"
"github.com/spf13/cobra"
)

const (
addPluginCommandExamples = ` Add a plugin to use with PingCLI.
pingcli plugin add pingcli-plugin-executable`
)

func NewPluginAddCommand() *cobra.Command {
cmd := &cobra.Command{
Args: common.ExactArgs(1),
DisableFlagsInUseLine: true, // We write our own flags in @Use attribute
Example: addPluginCommandExamples,
Long: `Add a plugin to use with PingCLI.`,
RunE: pluginAddRunE,
Short: "Add a plugin to use with PingCLI",
Use: "add plugin-executable",
}

return cmd
}

func pluginAddRunE(cmd *cobra.Command, args []string) error {
l := logger.Get()
l.Debug().Msgf("Plugin Add Subcommand Called.")

if err := plugin_internal.RunInternalPluginAdd(args[0]); err != nil {
return err
}

return nil
}
Loading