-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgateways.go
More file actions
90 lines (76 loc) · 2.14 KB
/
gateways.go
File metadata and controls
90 lines (76 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cmd
import (
"fmt"
"strings"
"github.com/drycc/controller-sdk-go/api"
"github.com/drycc/controller-sdk-go/gateways"
)
// GatewaysList lists gateways for the app
func (d *DryccCmd) GatewaysList(appID string, results int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
if results == defaultLimit {
results = s.Limit
}
gateways, count, err := gateways.List(s.Client, appID, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
if count == 0 {
d.Println(fmt.Sprintf("No gateways found in %s app.", appID))
} else {
table := d.getDefaultFormatTable([]string{"NAME", "LISENTER", "PORT", "PROTOCOL", "ADDRESSES"})
for _, gateway := range gateways {
addresesStr := parseAddress(gateway.Addresses)
for _, listener := range gateway.Listeners {
table.Append([]string{gateway.Name, listener.Name, fmt.Sprint(listener.Port), listener.Protocol, addresesStr})
}
}
table.Render()
}
return nil
}
// GatewaysAdd adds a gateway to an app.
func (d *DryccCmd) GatewaysAdd(appID, name string, port int, protocol string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Adding gateway %s to %s... ", name, appID)
quit := progress(d.WOut)
err = gateways.New(s.Client, appID, name, port, protocol)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
// GatewaysRemove removes a gateway registered with an app.
func (d *DryccCmd) GatewaysRemove(appID, name string, port int, protocol string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Removing gateway %s to %s... ", name, appID)
quit := progress(d.WOut)
err = gateways.Delete(s.Client, appID, name, port, protocol)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
func parseAddress(addresses []api.Address) string {
var addresList []string
for _, address := range addresses {
addresList = append(addresList, address.Value)
}
addresStr := strings.Join(addresList, ",")
return addresStr
}