@@ -4,27 +4,29 @@ import (
4
4
"fmt"
5
5
"os"
6
6
7
+ "github.com/openshift-online/ocm-cli/pkg/arguments"
7
8
"github.com/openshift-online/ocm-cli/pkg/dump"
8
9
"github.com/openshift-online/ocm-cli/pkg/ocm"
9
- "github.com/openshift-online/ocm-cli/pkg/urls"
10
10
"github.com/pkg/errors"
11
11
"github.com/spf13/cobra"
12
12
)
13
13
14
14
var GetWorkloadIdentityConfigurationOpts struct {
15
- single bool
15
+ single bool
16
+ parameter []string
16
17
}
17
18
18
- // NewCreateWorkloadIdentityConfiguration provides the "create-wif-config" subcommand
19
19
func NewGetWorkloadIdentityConfiguration () * cobra.Command {
20
20
getWorkloadIdentityPoolCmd := & cobra.Command {
21
21
Use : "wif-config [ID]" ,
22
22
Short : "Send a GET request for wif-config." ,
23
23
RunE : getWorkloadIdentityConfigurationCmd ,
24
24
PreRunE : validationForGetWorkloadIdentityConfigurationCmd ,
25
+ Aliases : []string {"wif-configs" },
25
26
}
26
27
27
28
fs := getWorkloadIdentityPoolCmd .Flags ()
29
+ arguments .AddParameterFlag (fs , & GetWorkloadIdentityConfigurationOpts .parameter )
28
30
fs .BoolVar (
29
31
& GetWorkloadIdentityConfigurationOpts .single ,
30
32
"single" ,
@@ -36,9 +38,14 @@ func NewGetWorkloadIdentityConfiguration() *cobra.Command {
36
38
}
37
39
38
40
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" )
42
49
}
43
50
44
51
connection , err := ocm .NewConnection ().Build ()
@@ -47,7 +54,10 @@ func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) erro
47
54
}
48
55
defer connection .Close ()
49
56
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 ()
51
61
if err != nil {
52
62
return errors .Wrapf (err , "can't send request" )
53
63
}
@@ -73,8 +83,8 @@ func getWorkloadIdentityConfigurationCmd(cmd *cobra.Command, argv []string) erro
73
83
}
74
84
75
85
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" )
78
88
}
79
89
return nil
80
90
}
0 commit comments