@@ -11,8 +11,9 @@ import (
11
11
"strings"
12
12
13
13
"github.com/cloudforet-io/cfctl/pkg/configs"
14
+ "github.com/cloudforet-io/cfctl/pkg/format"
15
+ "github.com/cloudforet-io/cfctl/pkg/transport"
14
16
"github.com/jhump/protoreflect/grpcreflect"
15
- "github.com/pterm/pterm"
16
17
"github.com/spf13/cobra"
17
18
"github.com/spf13/viper"
18
19
"google.golang.org/grpc"
@@ -28,18 +29,19 @@ func FetchApiResourcesCmd(serviceName string) *cobra.Command {
28
29
Use : "api_resources" ,
29
30
Short : fmt .Sprintf ("Displays supported API resources for the %s service" , serviceName ),
30
31
RunE : func (cmd * cobra.Command , args []string ) error {
31
- return listAPIResources (serviceName )
32
+ return ListAPIResources (serviceName )
32
33
},
33
34
}
34
35
}
35
36
36
- func listAPIResources (serviceName string ) error {
37
+ func ListAPIResources (serviceName string ) error {
37
38
setting , err := configs .LoadSetting ()
38
39
if err != nil {
39
40
return fmt .Errorf ("failed to load setting: %v" , err )
40
41
}
41
42
42
- endpoint , err := getServiceEndpoint (setting , serviceName )
43
+ //endpoint, err := getServiceEndpoint(setting, serviceName)
44
+ endpoint , err := transport .GetServiceEndpoint (setting , serviceName )
43
45
if err != nil {
44
46
return fmt .Errorf ("failed to get endpoint for service %s: %v" , serviceName , err )
45
47
}
@@ -58,39 +60,11 @@ func listAPIResources(serviceName string) error {
58
60
return data [i ][0 ] < data [j ][0 ]
59
61
})
60
62
61
- renderAPITable (data )
63
+ format . RenderTable (data )
62
64
63
65
return nil
64
66
}
65
67
66
- func getServiceEndpoint (config * configs.Setting , serviceName string ) (string , error ) {
67
- envConfig := config .Environments [config .Environment ]
68
- if envConfig .URL == "" {
69
- return "" , fmt .Errorf ("URL not found in environment config" )
70
- }
71
-
72
- // Parse URL to get environment
73
- urlParts := strings .Split (envConfig .URL , "." )
74
- if len (urlParts ) < 4 {
75
- return "" , fmt .Errorf ("invalid URL format: %s" , envConfig .URL )
76
- }
77
-
78
- var envPrefix string
79
- for i , part := range urlParts {
80
- if part == "console" && i + 1 < len (urlParts ) {
81
- envPrefix = urlParts [i + 1 ] // Get the part after "console" (dev or stg)
82
- break
83
- }
84
- }
85
-
86
- if envPrefix == "" {
87
- return "" , fmt .Errorf ("environment prefix not found in URL: %s" , envConfig .URL )
88
- }
89
-
90
- endpoint := fmt .Sprintf ("grpc+ssl://%s.api.%s.spaceone.dev:443" , serviceName , envPrefix )
91
- return endpoint , nil
92
- }
93
-
94
68
func loadShortNames () (map [string ]string , error ) {
95
69
home , err := os .UserHomeDir ()
96
70
if err != nil {
@@ -237,16 +211,3 @@ func fetchServiceResources(serviceName, endpoint string, shortNamesMap map[strin
237
211
238
212
return data , nil
239
213
}
240
-
241
- func renderAPITable (data [][]string ) {
242
- // Create table header
243
- table := pterm.TableData {
244
- {"Service" , "Verb" , "Resource" , "Short Names" },
245
- }
246
-
247
- // Add data rows
248
- table = append (table , data ... )
249
-
250
- // Render the table
251
- pterm .DefaultTable .WithHasHeader ().WithData (table ).Render ()
252
- }
0 commit comments