@@ -2,11 +2,14 @@ package commands
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67
78 "github.com/drycc/controller-sdk-go/api"
89 "github.com/drycc/controller-sdk-go/gateways"
910 "github.com/drycc/workflow-cli/internal/loader"
11+ "github.com/drycc/workflow-cli/pkg/coder"
12+ "sigs.k8s.io/yaml"
1013)
1114
1215// GatewaysList lists gateways for the app
@@ -26,28 +29,69 @@ func (d *DryccCmd) GatewaysList(appID string, results int) error {
2629 if count == 0 {
2730 d .Println (fmt .Sprintf ("No gateways found in %s app." , appID ))
2831 } else {
29- table := d .getDefaultFormatTable ([]string {"NAME" , "LISENTER" , " PORT" , "PROTOCOL" , "ADDRESSES" })
32+ table := d .getDefaultFormatTable ([]string {"NAME" , "PORT" , "PROTOCOL" , "ADDRESSES" })
3033 for _ , gateway := range gateways {
3134 addresesStr := parseAddress (gateway .Addresses )
32- for _ , listener := range gateway .Listeners {
33- table .Append ([]string {gateway .Name , listener . Name , fmt .Sprint (listener .Port ), listener .Protocol , addresesStr })
35+ for _ , port := range gateway .Ports {
36+ table .Append ([]string {gateway .Name , fmt .Sprint (port .Port ), port .Protocol , addresesStr })
3437 }
3538 }
3639 table .Render ()
3740 }
3841 return nil
3942}
4043
41- // GatewaysAdd adds a gateway to an app .
42- func (d * DryccCmd ) GatewaysAdd (appID , name string , port int , protocol string ) error {
44+ // GatewaysInfo shows detailed information about a gateway .
45+ func (d * DryccCmd ) GatewaysInfo (appID , name string ) error {
4346 appID , s , err := loader .LoadAppSettings (d .ConfigFile , appID )
4447 if err != nil {
4548 return err
4649 }
47- d .Printf ("Adding gateway %s to %s... " , name , appID )
50+
51+ info , err := gateways .Info (s .Client , appID , name )
52+ if d .checkAPICompatibility (s .Client , err ) != nil {
53+ return err
54+ }
55+
56+ c := & coder.GatewayCoder {Info : info }
57+ yamlBytes , err := c .Encode ()
58+ if err != nil {
59+ return err
60+ }
61+ d .Println (string (yamlBytes ))
62+ return nil
63+ }
64+
65+ // GatewaysApply applies gateway configuration from a YAML file.
66+ func (d * DryccCmd ) GatewaysApply (appID , filePath string ) error {
67+ appID , s , err := loader .LoadAppSettings (d .ConfigFile , appID )
68+ if err != nil {
69+ return err
70+ }
71+
72+ yamlData , err := os .ReadFile (filePath )
73+ if err != nil {
74+ return err
75+ }
76+
77+ jsonData , err := yaml .YAMLToJSON (yamlData )
78+ if err != nil {
79+ return err
80+ }
81+
82+ c := & coder.GatewayCoder {}
83+ if err := c .Decode (jsonData ); err != nil {
84+ return fmt .Errorf ("invalid gateway configuration: %w" , err )
85+ }
86+ if c .Request .Name == "" {
87+ return fmt .Errorf ("invalid gateway configuration: missing metadata.name" )
88+ }
89+ req := c .Request
90+
91+ d .Printf ("Applying gateway %s to %s... " , req .Name , appID )
4892
4993 quit := progress (d .WOut )
50- err = gateways .New (s .Client , appID , name , port , protocol )
94+ _ , err = gateways .Apply (s .Client , appID , req )
5195 quit <- true
5296 <- quit
5397 if d .checkAPICompatibility (s .Client , err ) != nil {
@@ -58,16 +102,16 @@ func (d *DryccCmd) GatewaysAdd(appID, name string, port int, protocol string) er
58102 return nil
59103}
60104
61- // GatewaysRemove removes a gateway registered with an app.
62- func (d * DryccCmd ) GatewaysRemove (appID , name string , port int , protocol string ) error {
105+ // GatewaysRemove removes a gateway from an app.
106+ func (d * DryccCmd ) GatewaysRemove (appID , name string ) error {
63107 appID , s , err := loader .LoadAppSettings (d .ConfigFile , appID )
64108 if err != nil {
65109 return err
66110 }
67- d .Printf ("Removing gateway %s to %s... " , name , appID )
111+ d .Printf ("Removing gateway %s from %s... " , name , appID )
68112
69113 quit := progress (d .WOut )
70- err = gateways .Delete (s .Client , appID , name , port , protocol )
114+ err = gateways .Delete (s .Client , appID , name )
71115 quit <- true
72116 <- quit
73117 if d .checkAPICompatibility (s .Client , err ) != nil {
0 commit comments