Skip to content

Commit ca8d9db

Browse files
authored
Support listing and parameters in 'gcp get wif-config' (#656)
1 parent 0724f62 commit ca8d9db

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

cmd/ocm/gcp/get-wif-config.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/openshift-online/ocm-cli/pkg/arguments"
78
"github.com/openshift-online/ocm-cli/pkg/dump"
89
"github.com/openshift-online/ocm-cli/pkg/ocm"
9-
"github.com/openshift-online/ocm-cli/pkg/urls"
1010
"github.com/pkg/errors"
1111
"github.com/spf13/cobra"
1212
)
1313

1414
var GetWorkloadIdentityConfigurationOpts struct {
15-
single bool
15+
single bool
16+
parameter []string
1617
}
1718

18-
// NewCreateWorkloadIdentityConfiguration provides the "create-wif-config" subcommand
1919
func NewGetWorkloadIdentityConfiguration() *cobra.Command {
2020
getWorkloadIdentityPoolCmd := &cobra.Command{
2121
Use: "wif-config [ID]",
2222
Short: "Send a GET request for wif-config.",
2323
RunE: getWorkloadIdentityConfigurationCmd,
2424
PreRunE: validationForGetWorkloadIdentityConfigurationCmd,
25+
Aliases: []string{"wif-configs"},
2526
}
2627

2728
fs := getWorkloadIdentityPoolCmd.Flags()
29+
arguments.AddParameterFlag(fs, &GetWorkloadIdentityConfigurationOpts.parameter)
2830
fs.BoolVar(
2931
&GetWorkloadIdentityConfigurationOpts.single,
3032
"single",
@@ -36,9 +38,14 @@ func NewGetWorkloadIdentityConfiguration() *cobra.Command {
3638
}
3739

3840
func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) error {
39-
id, err := urls.Expand(argv)
40-
if err != nil {
41-
return errors.Wrapf(err, "could not create URI")
41+
var path string
42+
if len(argv) == 0 {
43+
path = "/api/clusters_mgmt/v1/gcp/wif_configs"
44+
} else if len(argv) == 1 {
45+
id := argv[0]
46+
path = fmt.Sprintf("/api/clusters_mgmt/v1/gcp/wif_configs/%s", id)
47+
} else {
48+
return fmt.Errorf("unexpected number of arguments")
4249
}
4350

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

50-
resp, err := connection.Get().Path(fmt.Sprintf("/api/clusters_mgmt/v1/gcp/wif_configs/%s", id)).Send()
57+
request := connection.Get().Path(path)
58+
arguments.ApplyParameterFlag(request, GetWorkloadIdentityConfigurationOpts.parameter)
59+
60+
resp, err := request.Send()
5161
if err != nil {
5262
return errors.Wrapf(err, "can't send request")
5363
}
@@ -73,8 +83,8 @@ func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) erro
7383
}
7484

7585
func validationForGetWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) error {
76-
if len(argv) != 1 {
77-
return fmt.Errorf("Expected exactly one command line parameter containing the id of the WIF config.")
86+
if len(argv) > 1 {
87+
return fmt.Errorf("expected at most one command line parameter containing the id of the WIF config")
7888
}
7989
return nil
8090
}

0 commit comments

Comments
 (0)