Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support listing and parameters in 'gcp get wif-config' #656

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
28 changes: 19 additions & 9 deletions cmd/ocm/gcp/get-wif-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import (
"fmt"
"os"

"github.com/openshift-online/ocm-cli/pkg/arguments"
"github.com/openshift-online/ocm-cli/pkg/dump"
"github.com/openshift-online/ocm-cli/pkg/ocm"
"github.com/openshift-online/ocm-cli/pkg/urls"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var GetWorkloadIdentityConfigurationOpts struct {
single bool
single bool
parameter []string
}

// NewCreateWorkloadIdentityConfiguration provides the "create-wif-config" subcommand
func NewGetWorkloadIdentityConfiguration() *cobra.Command {
getWorkloadIdentityPoolCmd := &cobra.Command{
Use: "wif-config [ID]",
Short: "Send a GET request for wif-config.",
RunE: getWorkloadIdentityConfigurationCmd,
PreRunE: validationForGetWorkloadIdentityConfigurationCmd,
Aliases: []string{"wif-configs"},
}

fs := getWorkloadIdentityPoolCmd.Flags()
arguments.AddParameterFlag(fs, &GetWorkloadIdentityConfigurationOpts.parameter)
fs.BoolVar(
&GetWorkloadIdentityConfigurationOpts.single,
"single",
Expand All @@ -36,9 +38,14 @@ func NewGetWorkloadIdentityConfiguration() *cobra.Command {
}

func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) error {
id, err := urls.Expand(argv)
if err != nil {
return errors.Wrapf(err, "could not create URI")
var path string
if len(argv) == 0 {
path = "/api/clusters_mgmt/v1/gcp/wif_configs"
} else if len(argv) == 1 {
id := argv[0]
path = fmt.Sprintf("/api/clusters_mgmt/v1/gcp/wif_configs/%s", id)
} else {
return fmt.Errorf("unexpected number of arguments")
}

connection, err := ocm.NewConnection().Build()
Expand All @@ -47,7 +54,10 @@ func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) erro
}
defer connection.Close()

resp, err := connection.Get().Path(fmt.Sprintf("/api/clusters_mgmt/v1/gcp/wif_configs/%s", id)).Send()
request := connection.Get().Path(path)
arguments.ApplyParameterFlag(request, GetWorkloadIdentityConfigurationOpts.parameter)

resp, err := request.Send()
if err != nil {
return errors.Wrapf(err, "can't send request")
}
Expand All @@ -73,8 +83,8 @@ func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) erro
}

func validationForGetWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) error {
if len(argv) != 1 {
return fmt.Errorf("Expected exactly one command line parameter containing the id of the WIF config.")
if len(argv) > 1 {
return fmt.Errorf("expected at most one command line parameter containing the id of the WIF config")
}
return nil
}
Loading