/
app.go
117 lines (109 loc) · 2.57 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package c7nclient
import (
"fmt"
"github.com/choerodon/c7nctl/pkg/c7nclient/model"
"io"
)
func (c *C7NClient) ListApps(out io.Writer, projectId int) {
if projectId == 0 {
return
}
paras := make(map[string]interface{})
paras["doPage"] = "false"
req, err := c.newRequest("POST", fmt.Sprintf("/devops/v1/projects/%d/app_service/page_by_options", projectId), paras, nil)
if err != nil {
fmt.Printf("build request error")
}
var apps = model.Apps{}
_, err = c.do(req, &apps)
if err != nil {
fmt.Printf("request err:%v", err)
return
}
appInfos := []model.AppInfo{}
for _, app := range apps.List {
var status string
var types string
if app.Synchro && app.Active {
status = "可用"
} else {
status = "不可用"
}
if app.Type == "normal" {
types = "普通应用"
} else {
types = "测试应用"
}
appInfo := model.AppInfo{
Id: app.ID,
Name: app.Name,
Code: app.Code,
RepoURL: app.RepoURL,
Status: status,
Type: types,
}
appInfos = append(appInfos, appInfo)
}
model.PrintAppInfo(appInfos, out)
}
func (c *C7NClient) GetApp(appCode string, projectId int) (error error, result *model.App) {
if projectId == 0 {
return nil, nil
}
paras := make(map[string]interface{})
paras["code"] = appCode
req, err := c.newRequest("GET", fmt.Sprintf("devops/v1/projects/%d/app_service/query_by_code", projectId), paras, nil)
if err != nil {
fmt.Printf("build request error")
return err, nil
}
var app = model.App{}
_, err = c.do(req, &app)
if err != nil {
fmt.Printf("request err:%v", err)
return err, nil
}
return nil, &app
}
func (c *C7NClient) CreateApp(out io.Writer, projectId int, appPostInfo *model.AppPostInfo) {
if projectId == 0 {
return
}
if appPostInfo.Type != "normal" && appPostInfo.Type != "test" {
fmt.Printf("the app type value should be normal or test!")
return
}
req, err := c.newRequest("POST", fmt.Sprintf("/devops/v1/projects/%d/app_service", projectId), nil, appPostInfo)
if err != nil {
fmt.Printf("build request error")
}
var app = model.App{}
_, err = c.do(req, &app)
if err != nil {
fmt.Printf("request err:%v", err)
return
}
var status string
var types string
appInfos := []model.AppInfo{}
if app.Synchro {
status = "可用"
} else {
status = "不可用"
}
if app.Type == "normal" {
types = "普通应用"
} else {
types = "测试应用"
}
appInfo := model.AppInfo{
Id: app.ID,
Name: app.Name,
Code: app.Code,
RepoURL: app.RepoURL,
Status: status,
Type: types,
}
appInfos = append(appInfos, appInfo)
model.PrintAppInfo(appInfos, out)
}