-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathingress.go
74 lines (65 loc) · 1.88 KB
/
ingress.go
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
package c7nclient
import (
"fmt"
"github.com/choerodon/c7nctl/pkg/c7nclient/model"
"io"
"strings"
)
// /devops/v1/projects/42/ingress/54/listByEnv
func (c *C7NClient) ListIngress(out io.Writer, envId int) {
if c.config.ProjectId == -1 {
fmt.Printf("Set project Id")
return
}
paras := make(map[string]interface{})
paras["page"] = 0
paras["size"] = 99
paras["sort"] = "id,desc"
body := make(map[string]interface{})
body["param"] = ""
body["searchParam"] = make(map[string]string)
req, err := c.newRequest("POST", fmt.Sprintf("/devops/v1/projects/%d/ingress/%d/listByEnv", c.config.ProjectId, envId), paras, body)
if err != nil {
fmt.Printf("build request error")
}
var resp = model.DevopsIngressPage{}
_, err = c.do(req, &resp)
if err != nil {
fmt.Printf("request err:%v", err)
return
}
ingressInfoList := []model.DevOpsIngressInfo{}
for _, ingress := range resp.Content {
ingressInfo := model.DevOpsIngressInfo{
Id: ingress.ID,
Name: ingress.Name,
Host: ingress.Domain,
Status: ingress.Status,
}
var paths = []string{}
if len(ingress.PathList) != 0 {
for _, ingressPath := range ingress.PathList {
paths = append(paths, fmt.Sprintf("%s -> %s", ingressPath.Path, ingressPath.ServiceName))
}
ingressInfo.Paths = strings.Join(paths, ",")
}
ingressInfoList = append(ingressInfoList, ingressInfo)
}
model.PrintIngressInfo(ingressInfoList, out)
}
func (c *C7NClient) CreateIngress(out io.Writer, projectId int, ingressPostInfo *model.IngressPostInfo) {
if projectId == 0 {
return
}
req, err := c.newRequest("POST", fmt.Sprintf("devops/v1/projects/%d/ingress", projectId), nil, ingressPostInfo)
if err != nil {
fmt.Printf("build request error")
}
var result string
_, err = c.doHandleString(req, &result)
if err != nil {
fmt.Printf("request err:%v", err)
return
}
fmt.Printf("create ingress %s success!", ingressPostInfo.Name)
}