forked from 1Panel-dev/KubePi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
76 lines (67 loc) · 2.18 KB
/
logs.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
package system
import (
"errors"
"github.com/asdine/storm/v3"
pkgV1 "github.com/godtool/kubeone/pkg/api/v1"
"github.com/godtool/kubeone/service/api/v1/commons"
"github.com/godtool/kubeone/service/service/v1/common"
"github.com/godtool/kubeone/service/service/v1/system"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
)
type Handler struct {
systemService system.Service
}
func NewHandler() *Handler {
return &Handler{
systemService: system.NewService(),
}
}
func (h *Handler) OperationLogsSearch() iris.Handler {
return func(ctx *context.Context) {
pageNum, _ := ctx.Values().GetInt(pkgV1.PageNum)
pageSize, _ := ctx.Values().GetInt(pkgV1.PageSize)
var conditions commons.SearchConditions
if err := ctx.ReadJSON(&conditions); err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.Values().Set("message", err.Error())
return
}
systems, total, err := h.systemService.SearchOperationLogs(pageNum, pageSize, conditions.Conditions, common.DBOptions{})
if err != nil {
if !errors.Is(err, storm.ErrNotFound) {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Values().Set("message", err.Error())
return
}
}
ctx.Values().Set("data", pkgV1.Page{Items: systems, Total: total})
}
}
func (h *Handler) LoginLogsSearch() iris.Handler {
return func(ctx *context.Context) {
pageNum, _ := ctx.Values().GetInt(pkgV1.PageNum)
pageSize, _ := ctx.Values().GetInt(pkgV1.PageSize)
var conditions commons.SearchConditions
if err := ctx.ReadJSON(&conditions); err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.Values().Set("message", err.Error())
return
}
systems, total, err := h.systemService.SearchLoginLogs(pageNum, pageSize, conditions.Conditions, common.DBOptions{})
if err != nil {
if !errors.Is(err, storm.ErrNotFound) {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Values().Set("message", err.Error())
return
}
}
ctx.Values().Set("data", pkgV1.Page{Items: systems, Total: total})
}
}
func Install(parent iris.Party) {
handler := NewHandler()
sp := parent.Party("/systems")
sp.Post("/login/logs/search", handler.LoginLogsSearch())
sp.Post("/operation/logs/search", handler.OperationLogsSearch())
}