-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
126 lines (107 loc) · 3.07 KB
/
runner.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
118
119
120
121
122
123
124
125
126
package main
import (
"awesome-runner/src/cache"
"awesome-runner/src/config"
"awesome-runner/src/handle"
"awesome-runner/src/logr"
"awesome-runner/src/queue"
"flag"
"time"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
)
var (
configFile = flag.String("f", "etc/config.yaml", "the config file")
sessionID = "IRISSESSIONID"
sess = sessions.New(sessions.Config{
Cookie: sessionID,
Expires: time.Hour,
})
)
func main() {
// log
logr.LogInit()
logr.Clog.Debug(`
_____ _____
/ ____| | __ \
| | __ ___ | |__) | _ _ __ _ __ ___ _ __
| | |_ |/ _ \ | _ / | | | '_ \| '_ \ / _ \ '__|
| |__| | (_) | | | \ \ |_| | | | | | | | __/ |
\_____|\___/ |_| \_\__,_|_| |_|_| |_|\___|_|
`)
flag.Parse()
// 加载配置
config.StoreConfig(configFile)
// 队列初始化
queue.StoreMachinery()
go func() {
if err := queue.MachineryWork.Launch(); err != nil {
logr.Logrus.Errorf("Work 进程异常,%v", err)
return
}
}()
defer func() {
if err := cache.GetReidsInstance().Close(); err != nil {
logr.Logrus.Error(err)
}
}()
app := iris.New()
// 405
app.OnAnyErrorCode(func(ctx iris.Context) {
errMessage := map[int]string{
405: "Method not allowed",
404: "Not found",
500: "Server error",
}
ctx.JSON(iris.Map{
"code": ctx.GetStatusCode(),
"message": errMessage[ctx.GetStatusCode()],
})
})
app.UseGlobal(sess.Handler())
app.HandleDir("/web", "./web")
app.Handle("POST", "/", handle.DeployHandle)
app.Handle("GET", "/ws", handle.WsHandler)
// api
taskRouter := app.Party("/task", SecurityMiddleware)
{
// 自动化部署
taskRouter.Get("/proj/list", handle.ProjList)
taskRouter.Delete("/proj/{symbol}", handle.ProjDelete)
taskRouter.Post("/proj", handle.ProjCreate)
taskRouter.Patch("/proj/{symbol}", handle.ProjUpdate)
taskRouter.Get("/console/list", handle.ConsoleList)
// 发布上线单
taskRouter.Post("/proj/publish", handle.TaskPublish)
taskRouter.Get("/release/list", handle.ReleaseList)
// 用户
taskRouter.Post("/retry/{symbol}", handle.Retry)
//taskRouter.Post("/console/cancle/{uuid}")
}
// api
userRouter := app.Party("/user")
{
userRouter.Get("/list", SecurityMiddleware, handle.UserList)
userRouter.Post("/handle", SecurityMiddleware, handle.UserCreate)
userRouter.Patch("/handle/{id:int64}", SecurityMiddleware, handle.UserUpdate)
userRouter.Delete("/handle/{id:int64}", SecurityMiddleware, handle.UserDelete)
userRouter.Get("/info/currentUser", SecurityMiddleware, handle.CurrentUser)
userRouter.Get("/logout", SecurityMiddleware, handle.Logout)
userRouter.Post("/login/account", handle.LoginAccount)
}
app.Listen(config.Cnf.Host + ":" + config.Cnf.Port)
}
// passport
func SecurityMiddleware(ctx iris.Context) {
session := sessions.Get(ctx)
isLogin, err := session.GetBoolean("Runner:Login")
if err != nil || !isLogin {
ctx.JSON(iris.Map{
"currentAuthority": "guest",
"status": "error",
"type": "account",
})
return
}
ctx.Next()
}