mirror of
https://github.com/cuigh/swirl
synced 2025-02-19 02:29:11 +00:00
Remove context.TODO()
This commit is contained in:
parent
48fdc6e094
commit
29bf212edb
api
api.gochart.goconfig.gocontainer.godashboard.goevent.goimage.gonetwork.gonode.goregistry.gorole.gosecret.goservice.gosetting.gostack.gosystem.gotask.gouser.govolume.go
biz
chart.goconfig.gocontainer.godashboard.goevent.goimage.gometric.gonetwork.gonode.goregistry.gorole.gosecret.goservice.gosession.gosetting.gostack.gosystem.gotask.gouser.govolume.go
dao
docker
main.gomisc
scaler
security
ui/src/api
@ -1,10 +1,14 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cuigh/auxo/app/container"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
)
|
||||
|
||||
const defaultTimeout = 30 * time.Second
|
||||
|
||||
func ajax(ctx web.Context, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
47
api/chart.go
47
api/chart.go
@ -5,6 +5,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// ChartHandler encapsulates chart related handlers.
|
||||
@ -26,22 +27,25 @@ func NewChart(b biz.ChartBiz) *ChartHandler {
|
||||
}
|
||||
|
||||
func chartSearch(b biz.ChartBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &dao.ChartSearchArgs{}
|
||||
charts []*dao.Chart
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
charts, total, err = b.Search(args)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
charts, total, err = b.Search(ctx, args)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": charts,
|
||||
"total": total,
|
||||
})
|
||||
@ -49,13 +53,16 @@ func chartSearch(b biz.ChartBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func chartFind(b biz.ChartBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
chart, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
chart, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, chart)
|
||||
return success(c, chart)
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,26 +71,32 @@ func chartDelete(b biz.ChartBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.ID, args.Title, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Title, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func chartSave(b biz.ChartBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
r := &dao.Chart{}
|
||||
err := ctx.Bind(r, true)
|
||||
err := c.Bind(r, true)
|
||||
if err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if r.ID == "" {
|
||||
err = b.Create(r, ctx.User())
|
||||
err = b.Create(ctx, r, c.User())
|
||||
} else {
|
||||
err = b.Update(r, ctx.User())
|
||||
err = b.Update(ctx, r, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// ConfigHandler encapsulates config related handlers.
|
||||
@ -31,22 +32,25 @@ func configSearch(b biz.ConfigBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
configs []*biz.Config
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
configs, total, err = b.Search(args.Name, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
configs, total, err = b.Search(ctx, args.Name, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": configs,
|
||||
"total": total,
|
||||
})
|
||||
@ -54,13 +58,16 @@ func configSearch(b biz.ConfigBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func configFind(b biz.ConfigBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
config, raw, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
config, raw, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"config": config, "raw": raw})
|
||||
return success(c, data.Map{"config": config, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,26 +76,32 @@ func configDelete(b biz.ConfigBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func configSave(b biz.ConfigBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
c := &biz.Config{}
|
||||
err := ctx.Bind(c, true)
|
||||
return func(c web.Context) error {
|
||||
config := &biz.Config{}
|
||||
err := c.Bind(config, true)
|
||||
if err == nil {
|
||||
if c.ID == "" {
|
||||
err = b.Create(c, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if config.ID == "" {
|
||||
err = b.Create(ctx, config, c.User())
|
||||
} else {
|
||||
err = b.Update(c, ctx.User())
|
||||
err = b.Update(ctx, config, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/cuigh/auxo/log"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
"github.com/gobwas/ws"
|
||||
"github.com/gobwas/ws/wsutil"
|
||||
)
|
||||
@ -43,22 +44,25 @@ func containerSearch(b biz.ContainerBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
containers []*biz.Container
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
containers, total, err = b.Search(args.Node, args.Name, args.Status, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
containers, total, err = b.Search(ctx, args.Node, args.Name, args.Status, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": containers,
|
||||
"total": total,
|
||||
})
|
||||
@ -66,16 +70,19 @@ func containerSearch(b biz.ContainerBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func containerFind(b biz.ContainerBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
node := ctx.Query("node")
|
||||
id := ctx.Query("id")
|
||||
container, raw, err := b.Find(node, id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
node := c.Query("node")
|
||||
id := c.Query("id")
|
||||
container, raw, err := b.Find(ctx, node, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if container == nil {
|
||||
return web.NewError(http.StatusNotFound)
|
||||
}
|
||||
return success(ctx, data.Map{"container": container, "raw": raw})
|
||||
return success(c, data.Map{"container": container, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,12 +92,15 @@ func containerDelete(b biz.ContainerBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.Node, args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.Node, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,52 +112,58 @@ func containerFetchLogs(b biz.ContainerBiz) web.HandlerFunc {
|
||||
Timestamps bool `json:"timestamps" bind:"timestamps"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
stdout, stderr string
|
||||
)
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
stdout, stderr, err = b.FetchLogs(args.Node, args.ID, args.Lines, args.Timestamps)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
stdout, stderr, err = b.FetchLogs(ctx, args.Node, args.ID, args.Lines, args.Timestamps)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
return success(c, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
}
|
||||
}
|
||||
|
||||
func containerConnect(b biz.ContainerBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
var (
|
||||
node = ctx.Query("node")
|
||||
id = ctx.Query("id")
|
||||
cmd = ctx.Query("cmd")
|
||||
node = c.Query("node")
|
||||
id = c.Query("id")
|
||||
cmd = c.Query("cmd")
|
||||
)
|
||||
|
||||
container, _, err := b.Find(node, id)
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
container, _, err := b.Find(ctx, node, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if container == nil {
|
||||
return web.NewError(http.StatusNotFound)
|
||||
}
|
||||
|
||||
conn, _, _, err := ws.UpgradeHTTP(ctx.Request(), ctx.Response())
|
||||
conn, _, _, err := ws.UpgradeHTTP(c.Request(), c.Response())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
idResp, err := b.ExecCreate(node, id, cmd)
|
||||
idResp, err := b.ExecCreate(ctx, node, id, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := b.ExecAttach(node, idResp.ID)
|
||||
resp, err := b.ExecAttach(ctx, node, idResp.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.ExecStart(node, idResp.ID)
|
||||
err = b.ExecStart(ctx, node, idResp.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -227,18 +243,21 @@ func containerPrune(b biz.ContainerBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Node string `json:"node"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err != nil {
|
||||
if err = c.Bind(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
count, size, err := b.Prune(args.Node, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
count, size, err := b.Prune(ctx, args.Node, c.User())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"count": count,
|
||||
"size": size,
|
||||
})
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// DashboardHandler encapsulates dashboard related handlers.
|
||||
@ -28,35 +29,42 @@ func NewDashboard(b biz.DashboardBiz) *DashboardHandler {
|
||||
}
|
||||
|
||||
func dashboardFind(b biz.DashboardBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
d *dao.Dashboard
|
||||
name = ctx.Query("name")
|
||||
key = ctx.Query("key")
|
||||
name = c.Query("name")
|
||||
key = c.Query("key")
|
||||
)
|
||||
d, err = b.FindDashboard(name, key)
|
||||
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
d, err = b.FindDashboard(ctx, name, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, d)
|
||||
return success(c, d)
|
||||
}
|
||||
}
|
||||
|
||||
func dashboardSave(b biz.DashboardBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
dashboard := &dao.Dashboard{}
|
||||
err := ctx.Bind(dashboard)
|
||||
err := c.Bind(dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch dashboard.Name {
|
||||
case "home", "service":
|
||||
err = b.UpdateDashboard(dashboard, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.UpdateDashboard(ctx, dashboard, c.User())
|
||||
default:
|
||||
err = errors.New("unknown dashboard: " + dashboard.Name)
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,17 +74,19 @@ func dashboardFetchData(b biz.DashboardBiz) web.HandlerFunc {
|
||||
Dashboards string `json:"charts" bind:"charts"`
|
||||
Period int32 `json:"period" bind:"period"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
d data.Map
|
||||
)
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
d, err = b.FetchData(args.Key, strings.Split(args.Dashboards, ","), times.Minutes(args.Period))
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
d, err = b.FetchData(ctx, args.Key, strings.Split(args.Dashboards, ","), times.Minutes(args.Period))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, d)
|
||||
return success(c, d)
|
||||
}
|
||||
}
|
||||
|
23
api/event.go
23
api/event.go
@ -5,6 +5,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// EventHandler encapsulates event related handlers.
|
||||
@ -22,22 +23,25 @@ func NewEvent(b biz.EventBiz) *EventHandler {
|
||||
}
|
||||
|
||||
func eventSearch(b biz.EventBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &dao.EventSearchArgs{}
|
||||
events []*dao.Event
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
events, total, err = b.Search(args)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
events, total, err = b.Search(ctx, args)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": events,
|
||||
"total": total,
|
||||
})
|
||||
@ -49,11 +53,14 @@ func eventPrune(b biz.EventBiz) web.HandlerFunc {
|
||||
Days int32 `json:"days"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var args = &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Prune(args.Days)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Prune(ctx, args.Days)
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
49
api/image.go
49
api/image.go
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// ImageHandler encapsulates image related handlers.
|
||||
@ -32,22 +33,25 @@ func imageSearch(b biz.ImageBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
images []*biz.Image
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
images, total, err = b.Search(args.Node, args.Name, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
images, total, err = b.Search(ctx, args.Node, args.Name, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": images,
|
||||
"total": total,
|
||||
})
|
||||
@ -55,14 +59,17 @@ func imageSearch(b biz.ImageBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func imageFind(b biz.ImageBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
node := ctx.Query("node")
|
||||
id := ctx.Query("id")
|
||||
image, raw, err := b.Find(node, id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
node := c.Query("node")
|
||||
id := c.Query("id")
|
||||
image, raw, err := b.Find(ctx, node, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"image": image, "raw": raw})
|
||||
return success(c, data.Map{"image": image, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,12 +78,16 @@ func imageDelete(b biz.ImageBiz) web.HandlerFunc {
|
||||
Node string `json:"node"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.Node, args.ID, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.Node, args.ID, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,18 +95,22 @@ func imagePrune(b biz.ImageBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Node string `json:"node"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err != nil {
|
||||
if err = c.Bind(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
count, size, err := b.Prune(args.Node, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
count, size, err := b.Prune(ctx, args.Node, c.User())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"count": count,
|
||||
"size": size,
|
||||
})
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// NetworkHandler encapsulates network related handlers.
|
||||
@ -27,23 +28,29 @@ func NewNetwork(nb biz.NetworkBiz) *NetworkHandler {
|
||||
}
|
||||
|
||||
func networkSearch(nb biz.NetworkBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
networks, err := nb.Search()
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
networks, err := nb.Search(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, networks)
|
||||
return success(c, networks)
|
||||
}
|
||||
}
|
||||
|
||||
func networkFind(nb biz.NetworkBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
name := ctx.Query("name")
|
||||
network, raw, err := nb.Find(name)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
name := c.Query("name")
|
||||
network, raw, err := nb.Find(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"network": network, "raw": raw})
|
||||
return success(c, data.Map{"network": network, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,23 +59,30 @@ func networkDelete(nb biz.NetworkBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = nb.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = nb.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func networkSave(nb biz.NetworkBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
n := &biz.Network{}
|
||||
err := ctx.Bind(n, true)
|
||||
err := c.Bind(n, true)
|
||||
if err == nil {
|
||||
err = nb.Create(n, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = nb.Create(ctx, n, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,12 +92,16 @@ func networkDisconnect(nb biz.NetworkBiz) web.HandlerFunc {
|
||||
NetworkName string `json:"networkName"`
|
||||
Container string `json:"container"`
|
||||
}
|
||||
return func(ctx web.Context) error {
|
||||
|
||||
return func(c web.Context) error {
|
||||
args := &Args{}
|
||||
err := ctx.Bind(args, true)
|
||||
err := c.Bind(args, true)
|
||||
if err == nil {
|
||||
err = nb.Disconnect(args.NetworkID, args.NetworkName, args.Container, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = nb.Disconnect(ctx, args.NetworkID, args.NetworkName, args.Container, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
49
api/node.go
49
api/node.go
@ -5,6 +5,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/auxo/util/cast"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// NodeHandler encapsulates node related handlers.
|
||||
@ -28,35 +29,41 @@ func NewNode(nb biz.NodeBiz) *NodeHandler {
|
||||
}
|
||||
|
||||
func nodeList(nb biz.NodeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
agent := cast.ToBool(ctx.Query("agent"))
|
||||
return func(c web.Context) error {
|
||||
agent := cast.ToBool(c.Query("agent"))
|
||||
nodes, err := nb.List(agent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, nodes)
|
||||
return success(c, nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func nodeSearch(nb biz.NodeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
nodes, err := nb.Search()
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
nodes, err := nb.Search(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return success(ctx, nodes)
|
||||
return success(c, nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func nodeFind(nb biz.NodeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
node, raw, err := nb.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
node, raw, err := nb.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"node": node, "raw": raw})
|
||||
return success(c, data.Map{"node": node, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,22 +72,28 @@ func nodeDelete(nb biz.NodeBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = nb.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = nb.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func nodeSave(nb biz.NodeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
n := &biz.Node{}
|
||||
err := ctx.Bind(n, true)
|
||||
err := c.Bind(n, true)
|
||||
if err == nil {
|
||||
err = nb.Update(n, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = nb.Update(ctx, n, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// RegistryHandler encapsulates registry related handlers.
|
||||
@ -25,23 +26,29 @@ func NewRegistry(b biz.RegistryBiz) *RegistryHandler {
|
||||
}
|
||||
|
||||
func registrySearch(b biz.RegistryBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
registries, err := b.Search()
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
registries, err := b.Search(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, registries)
|
||||
return success(c, registries)
|
||||
}
|
||||
}
|
||||
|
||||
func registryFind(b biz.RegistryBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
node, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
node, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, node)
|
||||
return success(c, node)
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,26 +57,32 @@ func registryDelete(b biz.RegistryBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func registrySave(b biz.RegistryBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
r := &dao.Registry{}
|
||||
err := ctx.Bind(r, true)
|
||||
err := c.Bind(r, true)
|
||||
if err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if r.ID == "" {
|
||||
err = b.Create(r, ctx.User())
|
||||
err = b.Create(ctx, r, c.User())
|
||||
} else {
|
||||
err = b.Update(r, ctx.User())
|
||||
err = b.Update(ctx, r, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
47
api/role.go
47
api/role.go
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// RoleHandler encapsulates role related handlers.
|
||||
@ -25,24 +26,30 @@ func NewRole(b biz.RoleBiz) *RoleHandler {
|
||||
}
|
||||
|
||||
func roleSearch(b biz.RoleBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
name := ctx.Query("name")
|
||||
roles, err := b.Search(name)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
name := c.Query("name")
|
||||
roles, err := b.Search(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, roles)
|
||||
return success(c, roles)
|
||||
}
|
||||
}
|
||||
|
||||
func roleFind(b biz.RoleBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
role, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
role, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, role)
|
||||
return success(c, role)
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,26 +58,32 @@ func roleDelete(b biz.RoleBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func roleSave(b biz.RoleBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
r := &dao.Role{}
|
||||
err := ctx.Bind(r, true)
|
||||
err := c.Bind(r, true)
|
||||
if err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if r.ID == "" {
|
||||
err = b.Create(r, ctx.User())
|
||||
err = b.Create(ctx, r, c.User())
|
||||
} else {
|
||||
err = b.Update(r, ctx.User())
|
||||
err = b.Update(ctx, r, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// SecretHandler encapsulates secret related handlers.
|
||||
@ -31,22 +32,25 @@ func secretSearch(b biz.SecretBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
secrets []*biz.Secret
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
secrets, total, err = b.Search(args.Name, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
secrets, total, err = b.Search(ctx, args.Name, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": secrets,
|
||||
"total": total,
|
||||
})
|
||||
@ -54,13 +58,16 @@ func secretSearch(b biz.SecretBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func secretFind(b biz.SecretBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
secret, raw, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
secret, raw, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"secret": secret, "raw": raw})
|
||||
return success(c, data.Map{"secret": secret, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,26 +76,32 @@ func secretDelete(b biz.SecretBiz) web.HandlerFunc {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.ID, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func secretSave(b biz.SecretBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
c := &biz.Secret{}
|
||||
err := ctx.Bind(c, true)
|
||||
return func(c web.Context) error {
|
||||
secret := &biz.Secret{}
|
||||
err := c.Bind(secret, true)
|
||||
if err == nil {
|
||||
if c.ID == "" {
|
||||
err = b.Create(c, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if secret.ID == "" {
|
||||
err = b.Create(ctx, secret, c.User())
|
||||
} else {
|
||||
err = b.Update(c, ctx.User())
|
||||
err = b.Update(ctx, secret, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
110
api/service.go
110
api/service.go
@ -6,6 +6,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// ServiceHandler encapsulates service related handlers.
|
||||
@ -44,22 +45,25 @@ func serviceSearch(b biz.ServiceBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
services []*biz.ServiceBase
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
services, total, err = b.Search(args.Name, args.Mode, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
services, total, err = b.Search(ctx, args.Name, args.Mode, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": services,
|
||||
"total": total,
|
||||
})
|
||||
@ -67,16 +71,19 @@ func serviceSearch(b biz.ServiceBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func serviceFind(b biz.ServiceBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
name := ctx.Query("name")
|
||||
status := ctx.Query("status") == "true"
|
||||
service, raw, err := b.Find(name, status)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
name := c.Query("name")
|
||||
status := c.Query("status") == "true"
|
||||
service, raw, err := b.Find(ctx, name, status)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if service == nil {
|
||||
return web.NewError(http.StatusNotFound)
|
||||
}
|
||||
return success(ctx, data.Map{"service": service, "raw": raw})
|
||||
return success(c, data.Map{"service": service, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,12 +91,15 @@ func serviceDelete(b biz.ServiceBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,12 +107,15 @@ func serviceRestart(b biz.ServiceBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Restart(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Restart(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +123,15 @@ func serviceRollback(b biz.ServiceBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Rollback(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Rollback(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,52 +141,61 @@ func serviceScale(b biz.ServiceBiz) web.HandlerFunc {
|
||||
Count uint64 `json:"count"`
|
||||
Version uint64 `json:"version"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Scale(args.Name, args.Count, args.Version, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Scale(ctx, args.Name, args.Count, args.Version, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func serviceSave(b biz.ServiceBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
s := &biz.Service{}
|
||||
err := ctx.Bind(s, true)
|
||||
err := c.Bind(s, true)
|
||||
if err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if s.ID == "" {
|
||||
err = b.Create(s, ctx.User())
|
||||
err = b.Create(ctx, s, c.User())
|
||||
} else {
|
||||
err = b.Update(s, ctx.User())
|
||||
err = b.Update(ctx, s, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func serviceDeploy(b biz.ServiceBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
//mode := ctx.Query("mode") // update/replace
|
||||
return func(c web.Context) error {
|
||||
//mode := c.Query("mode") // update/replace
|
||||
service := &biz.Service{}
|
||||
err := ctx.Bind(service, true)
|
||||
err := c.Bind(service, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
var s *biz.Service
|
||||
if s, _, err = b.Find(service.Name, false); err != nil {
|
||||
if s, _, err = b.Find(ctx, service.Name, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
err = b.Create(service, ctx.User())
|
||||
err = b.Create(ctx, service, c.User())
|
||||
} else {
|
||||
// Only the image field is allowed to be changed when updating.
|
||||
s.Image = service.Image
|
||||
err = b.Update(s, ctx.User())
|
||||
err = b.Update(ctx, s, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,17 +206,20 @@ func serviceFetchLogs(b biz.ServiceBiz) web.HandlerFunc {
|
||||
Timestamps bool `json:"timestamps" bind:"timestamps"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
stdout, stderr string
|
||||
)
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
stdout, stderr, err = b.FetchLogs(args.ID, args.Lines, args.Timestamps)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
stdout, stderr, err = b.FetchLogs(ctx, args.ID, args.Lines, args.Timestamps)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
return success(c, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// SettingHandler encapsulates setting related handlers.
|
||||
@ -22,12 +23,15 @@ func NewSetting(b biz.SettingBiz) *SettingHandler {
|
||||
}
|
||||
|
||||
func settingLoad(b biz.SettingBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
options, err := b.Load()
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
options, err := b.Load(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, options)
|
||||
return success(c, options)
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,12 +41,15 @@ func settingSave(b biz.SettingBiz) web.HandlerFunc {
|
||||
Options json.RawMessage `json:"options"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
err = ctx.Bind(args)
|
||||
err = c.Bind(args)
|
||||
if err == nil {
|
||||
err = b.Save(args.ID, args.Options, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Save(ctx, args.ID, args.Options, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
75
api/stack.go
75
api/stack.go
@ -7,6 +7,7 @@ import (
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/docker/compose"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// StackHandler encapsulates stack related handlers.
|
||||
@ -33,8 +34,8 @@ func NewStack(b biz.StackBiz) *StackHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func stackUpload(ctx web.Context) (err error) {
|
||||
file, _, err := ctx.File("content")
|
||||
func stackUpload(c web.Context) (err error) {
|
||||
file, _, err := c.File("content")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -42,7 +43,7 @@ func stackUpload(ctx web.Context) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Data(b)
|
||||
return c.Data(b)
|
||||
}
|
||||
|
||||
func stackSearch(b biz.StackBiz) web.HandlerFunc {
|
||||
@ -51,32 +52,38 @@ func stackSearch(b biz.StackBiz) web.HandlerFunc {
|
||||
Filter string `json:"filter" bind:"filter"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
stacks []*dao.Stack
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
stacks, err = b.Search(args.Name, args.Filter)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
stacks, err = b.Search(ctx, args.Name, args.Filter)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, stacks)
|
||||
return success(c, stacks)
|
||||
}
|
||||
}
|
||||
|
||||
func stackFind(b biz.StackBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
name := ctx.Query("name")
|
||||
stack, err := b.Find(name)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
name := c.Query("name")
|
||||
stack, err := b.Find(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, stack)
|
||||
return success(c, stack)
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,12 +91,15 @@ func stackDelete(b biz.StackBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,12 +107,15 @@ func stackShutdown(b biz.StackBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Shutdown(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Shutdown(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +123,15 @@ func stackDeploy(b biz.StackBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Deploy(args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Deploy(ctx, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,9 +141,9 @@ func stackSave(b biz.StackBiz) web.HandlerFunc {
|
||||
dao.Stack
|
||||
}
|
||||
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
stack := &Args{}
|
||||
err := ctx.Bind(stack, true)
|
||||
err := c.Bind(stack, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -138,11 +154,14 @@ func stackSave(b biz.StackBiz) web.HandlerFunc {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if stack.ID == "" {
|
||||
err = b.Create(&stack.Stack, ctx.User())
|
||||
err = b.Create(ctx, &stack.Stack, c.User())
|
||||
} else {
|
||||
err = b.Update(&stack.Stack, ctx.User())
|
||||
err = b.Update(ctx, &stack.Stack, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/cuigh/auxo/app"
|
||||
@ -34,7 +33,10 @@ func NewSystem(d *docker.Docker, b biz.SystemBiz, ub biz.UserBiz) *SystemHandler
|
||||
|
||||
func systemCheckState(b biz.SystemBiz) web.HandlerFunc {
|
||||
return func(c web.Context) (err error) {
|
||||
state, err := b.CheckState()
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
state, err := b.CheckState(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -58,16 +60,19 @@ func systemSummarize(d *docker.Docker) web.HandlerFunc {
|
||||
StackCount int `json:"stackCount"`
|
||||
}{}
|
||||
|
||||
if summary.NodeCount, err = d.NodeCount(context.TODO()); err != nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if summary.NodeCount, err = d.NodeCount(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if summary.NetworkCount, err = d.NetworkCount(context.TODO()); err != nil {
|
||||
if summary.NetworkCount, err = d.NetworkCount(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if summary.ServiceCount, err = d.ServiceCount(context.TODO()); err != nil {
|
||||
if summary.ServiceCount, err = d.ServiceCount(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if summary.StackCount, err = d.StackCount(context.TODO()); err != nil {
|
||||
if summary.StackCount, err = d.StackCount(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -82,14 +87,17 @@ func systemCreateAdmin(ub biz.UserBiz) web.HandlerFunc {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
var count int
|
||||
if count, err = ub.Count(); err == nil && count > 0 {
|
||||
if count, err = ub.Count(ctx); err == nil && count > 0 {
|
||||
return errors.Coded(misc.ErrSystemInitialized, "system was already initialized")
|
||||
}
|
||||
|
||||
user.Admin = true
|
||||
user.Type = biz.UserTypeInternal
|
||||
_, err = ub.Create(user, nil)
|
||||
_, err = ub.Create(ctx, user, nil)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
34
api/task.go
34
api/task.go
@ -6,6 +6,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// TaskHandler encapsulates node related handlers.
|
||||
@ -32,22 +33,25 @@ func taskSearch(b biz.TaskBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
tasks []*biz.Task
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
tasks, total, err = b.Search("", args.Service, args.State, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
tasks, total, err = b.Search(ctx, "", args.Service, args.State, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": tasks,
|
||||
"total": total,
|
||||
})
|
||||
@ -55,15 +59,18 @@ func taskSearch(b biz.TaskBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func taskFind(b biz.TaskBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
task, raw, err := b.Find(id)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
task, raw, err := b.Find(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if task == nil {
|
||||
return web.NewError(http.StatusNotFound)
|
||||
}
|
||||
return success(ctx, data.Map{"task": task, "raw": raw})
|
||||
return success(c, data.Map{"task": task, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,17 +81,20 @@ func taskFetchLogs(b biz.TaskBiz) web.HandlerFunc {
|
||||
Timestamps bool `json:"timestamps" bind:"timestamps"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
stdout, stderr string
|
||||
)
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
stdout, stderr, err = b.FetchLogs(args.ID, args.Lines, args.Timestamps)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
stdout, stderr, err = b.FetchLogs(ctx, args.ID, args.Lines, args.Timestamps)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
return success(c, data.Map{"stdout": stdout, "stderr": stderr})
|
||||
}
|
||||
}
|
||||
|
93
api/user.go
93
api/user.go
@ -5,6 +5,7 @@ import (
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
"github.com/cuigh/swirl/security"
|
||||
)
|
||||
|
||||
@ -40,23 +41,26 @@ func userSignIn(auth *security.Identifier, eb biz.EventBiz) web.HandlerFunc {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &SignInArgs{}
|
||||
user security.Identity
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err != nil {
|
||||
if err = c.Bind(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if user, err = auth.Identify(args.Name, args.Password); err != nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if user, err = auth.Identify(ctx, args.Name, args.Password); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
eb.CreateUser(biz.EventActionLogin, user.ID(), user.Name(), user)
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"name": user.Name(),
|
||||
"token": user.Token(),
|
||||
"perms": user.Perms(),
|
||||
@ -65,17 +69,20 @@ func userSignIn(auth *security.Identifier, eb biz.EventBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func userSave(b biz.UserBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
user := &dao.User{}
|
||||
err := ctx.Bind(user, true)
|
||||
err := c.Bind(user, true)
|
||||
if err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
if user.ID == "" {
|
||||
_, err = b.Create(user, ctx.User())
|
||||
_, err = b.Create(ctx, user, c.User())
|
||||
} else {
|
||||
err = b.Update(user, ctx.User())
|
||||
err = b.Update(ctx, user, c.User())
|
||||
}
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,32 +95,38 @@ func userSearch(b biz.UserBiz) web.HandlerFunc {
|
||||
PageSize int `bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
args := &Args{}
|
||||
err := ctx.Bind(args)
|
||||
err := c.Bind(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
users, total, err := b.Search(args.Name, args.LoginName, args.Filter, args.PageIndex, args.PageSize)
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
users, total, err := b.Search(ctx, args.Name, args.LoginName, args.Filter, args.PageIndex, args.PageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"items": users, "total": total})
|
||||
return success(c, data.Map{"items": users, "total": total})
|
||||
}
|
||||
}
|
||||
|
||||
func userFind(b biz.UserBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
id := ctx.Query("id")
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
id = ctx.User().ID()
|
||||
id = c.User().ID()
|
||||
}
|
||||
user, err := b.FindByID(id)
|
||||
user, err := b.FindByID(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, user)
|
||||
return success(c, user)
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,13 +136,16 @@ func userDelete(b biz.UserBiz) web.HandlerFunc {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
args := &Args{}
|
||||
err := ctx.Bind(args)
|
||||
err := c.Bind(args)
|
||||
if err == nil {
|
||||
err = b.Delete(args.ID, args.Name, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.ID, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,13 +155,16 @@ func userSetStatus(b biz.UserBiz) web.HandlerFunc {
|
||||
Status int32 `json:"status"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
args := &Args{}
|
||||
err := ctx.Bind(args)
|
||||
err := c.Bind(args)
|
||||
if err == nil {
|
||||
err = b.SetStatus(args.ID, args.Status, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.SetStatus(ctx, args.ID, args.Status, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,23 +174,29 @@ func userModifyPassword(b biz.UserBiz) web.HandlerFunc {
|
||||
NewPassword string `json:"newPwd"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
args := &Args{}
|
||||
err := ctx.Bind(args)
|
||||
err := c.Bind(args)
|
||||
if err == nil {
|
||||
err = b.ModifyPassword(args.OldPassword, args.NewPassword, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.ModifyPassword(ctx, args.OldPassword, args.NewPassword, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func userModifyProfile(b biz.UserBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
u := &dao.User{}
|
||||
err := ctx.Bind(u, true)
|
||||
err := c.Bind(u, true)
|
||||
if err == nil {
|
||||
err = b.ModifyProfile(u, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.ModifyProfile(ctx, u, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/auxo/net/web"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
)
|
||||
|
||||
// VolumeHandler encapsulates volume related handlers.
|
||||
@ -34,22 +35,25 @@ func volumeSearch(b biz.VolumeBiz) web.HandlerFunc {
|
||||
PageSize int `json:"pageSize" bind:"pageSize"`
|
||||
}
|
||||
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
var (
|
||||
args = &Args{}
|
||||
volumes []*biz.Volume
|
||||
total int
|
||||
)
|
||||
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
volumes, total, err = b.Search(args.Node, args.Name, args.PageIndex, args.PageSize)
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
volumes, total, err = b.Search(ctx, args.Node, args.Name, args.PageIndex, args.PageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"items": volumes,
|
||||
"total": total,
|
||||
})
|
||||
@ -57,14 +61,17 @@ func volumeSearch(b biz.VolumeBiz) web.HandlerFunc {
|
||||
}
|
||||
|
||||
func volumeFind(b biz.VolumeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
node := ctx.Query("node")
|
||||
name := ctx.Query("name")
|
||||
volume, raw, err := b.Find(node, name)
|
||||
return func(c web.Context) error {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
node := c.Query("node")
|
||||
name := c.Query("name")
|
||||
volume, raw, err := b.Find(ctx, node, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return success(ctx, data.Map{"volume": volume, "raw": raw})
|
||||
return success(c, data.Map{"volume": volume, "raw": raw})
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,23 +80,29 @@ func volumeDelete(b biz.VolumeBiz) web.HandlerFunc {
|
||||
Node string `json:"node"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err == nil {
|
||||
err = b.Delete(args.Node, args.Name, ctx.User())
|
||||
if err = c.Bind(args); err == nil {
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Delete(ctx, args.Node, args.Name, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
func volumeSave(b biz.VolumeBiz) web.HandlerFunc {
|
||||
return func(ctx web.Context) error {
|
||||
return func(c web.Context) error {
|
||||
v := &biz.Volume{}
|
||||
err := ctx.Bind(v, true)
|
||||
err := c.Bind(v, true)
|
||||
if err == nil {
|
||||
err = b.Create(v, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = b.Create(ctx, v, c.User())
|
||||
}
|
||||
return ajax(ctx, err)
|
||||
return ajax(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,18 +110,21 @@ func volumePrune(b biz.VolumeBiz) web.HandlerFunc {
|
||||
type Args struct {
|
||||
Node string `json:"node"`
|
||||
}
|
||||
return func(ctx web.Context) (err error) {
|
||||
return func(c web.Context) (err error) {
|
||||
args := &Args{}
|
||||
if err = ctx.Bind(args); err != nil {
|
||||
if err = c.Bind(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
count, size, err := b.Prune(args.Node, ctx.User())
|
||||
ctx, cancel := misc.Context(defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
count, size, err := b.Prune(ctx, args.Node, c.User())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return success(ctx, data.Map{
|
||||
return success(c, data.Map{
|
||||
"count": count,
|
||||
"size": size,
|
||||
})
|
||||
|
36
biz/chart.go
36
biz/chart.go
@ -8,12 +8,11 @@ import (
|
||||
)
|
||||
|
||||
type ChartBiz interface {
|
||||
Search(args *dao.ChartSearchArgs) (charts []*dao.Chart, total int, err error)
|
||||
Delete(id, title string, user web.User) (err error)
|
||||
Find(id string) (chart *dao.Chart, err error)
|
||||
Batch(ids ...string) (charts []*dao.Chart, err error)
|
||||
Create(chart *dao.Chart, user web.User) (err error)
|
||||
Update(chart *dao.Chart, user web.User) (err error)
|
||||
Search(ctx context.Context, args *dao.ChartSearchArgs) (charts []*dao.Chart, total int, err error)
|
||||
Delete(ctx context.Context, id, title string, user web.User) (err error)
|
||||
Find(ctx context.Context, id string) (chart *dao.Chart, err error)
|
||||
Create(ctx context.Context, chart *dao.Chart, user web.User) (err error)
|
||||
Update(ctx context.Context, chart *dao.Chart, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewChart(d dao.Interface, mb MetricBiz, eb EventBiz) ChartBiz {
|
||||
@ -30,44 +29,39 @@ type chartBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *chartBiz) Search(args *dao.ChartSearchArgs) (charts []*dao.Chart, total int, err error) {
|
||||
return b.d.ChartSearch(context.TODO(), args)
|
||||
func (b *chartBiz) Search(ctx context.Context, args *dao.ChartSearchArgs) (charts []*dao.Chart, total int, err error) {
|
||||
return b.d.ChartSearch(ctx, args)
|
||||
}
|
||||
|
||||
func (b *chartBiz) Create(chart *dao.Chart, user web.User) (err error) {
|
||||
func (b *chartBiz) Create(ctx context.Context, chart *dao.Chart, user web.User) (err error) {
|
||||
chart.ID = createId()
|
||||
chart.CreatedAt = now()
|
||||
chart.CreatedBy = newOperator(user)
|
||||
chart.UpdatedAt = chart.CreatedAt
|
||||
chart.UpdatedBy = chart.CreatedBy
|
||||
err = b.d.ChartCreate(context.TODO(), chart)
|
||||
err = b.d.ChartCreate(ctx, chart)
|
||||
if err == nil {
|
||||
b.eb.CreateChart(EventActionCreate, chart.ID, chart.Title, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *chartBiz) Delete(id, title string, user web.User) (err error) {
|
||||
err = b.d.ChartDelete(context.TODO(), id)
|
||||
func (b *chartBiz) Delete(ctx context.Context, id, title string, user web.User) (err error) {
|
||||
err = b.d.ChartDelete(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateChart(EventActionDelete, id, title, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *chartBiz) Find(id string) (chart *dao.Chart, err error) {
|
||||
return b.d.ChartGet(context.TODO(), id)
|
||||
func (b *chartBiz) Find(ctx context.Context, id string) (chart *dao.Chart, err error) {
|
||||
return b.d.ChartGet(ctx, id)
|
||||
}
|
||||
|
||||
func (b *chartBiz) Batch(ids ...string) (charts []*dao.Chart, err error) {
|
||||
charts, err = b.d.ChartGetBatch(context.TODO(), ids...)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *chartBiz) Update(chart *dao.Chart, user web.User) (err error) {
|
||||
func (b *chartBiz) Update(ctx context.Context, chart *dao.Chart, user web.User) (err error) {
|
||||
chart.UpdatedAt = now()
|
||||
chart.UpdatedBy = newOperator(user)
|
||||
err = b.d.ChartUpdate(context.TODO(), chart)
|
||||
err = b.d.ChartUpdate(ctx, chart)
|
||||
if err == nil {
|
||||
b.eb.CreateChart(EventActionUpdate, chart.ID, chart.Title, user)
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type ConfigBiz interface {
|
||||
Search(name string, pageIndex, pageSize int) (configs []*Config, total int, err error)
|
||||
Find(id string) (config *Config, raw string, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Create(c *Config, user web.User) (err error)
|
||||
Update(c *Config, user web.User) (err error)
|
||||
Search(ctx context.Context, name string, pageIndex, pageSize int) (configs []*Config, total int, err error)
|
||||
Find(ctx context.Context, id string) (config *Config, raw string, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, c *Config, user web.User) (err error)
|
||||
Update(ctx context.Context, c *Config, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewConfig(d *docker.Docker, eb EventBiz) ConfigBiz {
|
||||
@ -26,12 +26,12 @@ type configBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *configBiz) Find(id string) (config *Config, raw string, err error) {
|
||||
func (b *configBiz) Find(ctx context.Context, id string) (config *Config, raw string, err error) {
|
||||
var (
|
||||
c swarm.Config
|
||||
r []byte
|
||||
)
|
||||
c, r, err = b.d.ConfigInspect(context.TODO(), id)
|
||||
c, r, err = b.d.ConfigInspect(ctx, id)
|
||||
if err == nil {
|
||||
raw, err = indentJSON(r)
|
||||
}
|
||||
@ -41,8 +41,8 @@ func (b *configBiz) Find(id string) (config *Config, raw string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *configBiz) Search(name string, pageIndex, pageSize int) ([]*Config, int, error) {
|
||||
list, total, err := b.d.ConfigList(context.TODO(), name, pageIndex, pageSize)
|
||||
func (b *configBiz) Search(ctx context.Context, name string, pageIndex, pageSize int) ([]*Config, int, error) {
|
||||
list, total, err := b.d.ConfigList(ctx, name, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -54,15 +54,15 @@ func (b *configBiz) Search(name string, pageIndex, pageSize int) ([]*Config, int
|
||||
return configs, total, nil
|
||||
}
|
||||
|
||||
func (b *configBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.ConfigRemove(context.TODO(), id)
|
||||
func (b *configBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.ConfigRemove(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateConfig(EventActionDelete, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *configBiz) Create(c *Config, user web.User) (err error) {
|
||||
func (b *configBiz) Create(ctx context.Context, c *Config, user web.User) (err error) {
|
||||
spec := swarm.ConfigSpec{
|
||||
Data: []byte(c.Data),
|
||||
}
|
||||
@ -76,14 +76,14 @@ func (b *configBiz) Create(c *Config, user web.User) (err error) {
|
||||
}
|
||||
|
||||
var id string
|
||||
id, err = b.d.ConfigCreate(context.TODO(), &spec)
|
||||
id, err = b.d.ConfigCreate(ctx, &spec)
|
||||
if err == nil {
|
||||
b.eb.CreateConfig(EventActionCreate, id, c.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *configBiz) Update(c *Config, user web.User) (err error) {
|
||||
func (b *configBiz) Update(ctx context.Context, c *Config, user web.User) (err error) {
|
||||
spec := &swarm.ConfigSpec{
|
||||
Data: []byte(c.Data),
|
||||
}
|
||||
@ -95,7 +95,7 @@ func (b *configBiz) Update(c *Config, user web.User) (err error) {
|
||||
Options: toMap(c.Templating.Options),
|
||||
}
|
||||
}
|
||||
err = b.d.ConfigUpdate(context.TODO(), c.ID, c.Version, spec)
|
||||
err = b.d.ConfigUpdate(ctx, c.ID, c.Version, spec)
|
||||
if err == nil {
|
||||
b.eb.CreateConfig(EventActionUpdate, c.ID, c.Name, user)
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ import (
|
||||
)
|
||||
|
||||
type ContainerBiz interface {
|
||||
Search(node, name, status string, pageIndex, pageSize int) ([]*Container, int, error)
|
||||
Find(node, id string) (container *Container, raw string, err error)
|
||||
Delete(node, id, name string, user web.User) (err error)
|
||||
FetchLogs(node, id string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
ExecCreate(node, id string, cmd string) (resp types.IDResponse, err error)
|
||||
ExecAttach(node, id string) (resp types.HijackedResponse, err error)
|
||||
ExecStart(node, id string) error
|
||||
Prune(node string, user web.User) (count int, size uint64, err error)
|
||||
Search(ctx context.Context, node, name, status string, pageIndex, pageSize int) ([]*Container, int, error)
|
||||
Find(ctx context.Context, node, id string) (container *Container, raw string, err error)
|
||||
Delete(ctx context.Context, node, id, name string, user web.User) (err error)
|
||||
FetchLogs(ctx context.Context, node, id string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
ExecCreate(ctx context.Context, node, id string, cmd string) (resp types.IDResponse, err error)
|
||||
ExecAttach(ctx context.Context, node, id string) (resp types.HijackedResponse, err error)
|
||||
ExecStart(ctx context.Context, node, id string) error
|
||||
Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error)
|
||||
}
|
||||
|
||||
func NewContainer(d *docker.Docker, eb EventBiz) ContainerBiz {
|
||||
@ -31,13 +31,13 @@ type containerBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *containerBiz) Find(node, id string) (c *Container, raw string, err error) {
|
||||
func (b *containerBiz) Find(ctx context.Context, node, id string) (c *Container, raw string, err error) {
|
||||
var (
|
||||
cj types.ContainerJSON
|
||||
r []byte
|
||||
)
|
||||
|
||||
cj, r, err = b.d.ContainerInspect(context.TODO(), node, id)
|
||||
cj, r, err = b.d.ContainerInspect(ctx, node, id)
|
||||
if err != nil {
|
||||
if docker.IsErrNotFound(err) {
|
||||
err = nil
|
||||
@ -51,8 +51,8 @@ func (b *containerBiz) Find(node, id string) (c *Container, raw string, err erro
|
||||
return
|
||||
}
|
||||
|
||||
func (b *containerBiz) Search(node, name, status string, pageIndex, pageSize int) (containers []*Container, total int, err error) {
|
||||
list, total, err := b.d.ContainerList(context.TODO(), node, name, status, pageIndex, pageSize)
|
||||
func (b *containerBiz) Search(ctx context.Context, node, name, status string, pageIndex, pageSize int) (containers []*Container, total int, err error) {
|
||||
list, total, err := b.d.ContainerList(ctx, node, name, status, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -64,37 +64,37 @@ func (b *containerBiz) Search(node, name, status string, pageIndex, pageSize int
|
||||
return containers, total, nil
|
||||
}
|
||||
|
||||
func (b *containerBiz) Delete(node, id, name string, user web.User) (err error) {
|
||||
err = b.d.ContainerRemove(context.TODO(), node, id)
|
||||
func (b *containerBiz) Delete(ctx context.Context, node, id, name string, user web.User) (err error) {
|
||||
err = b.d.ContainerRemove(ctx, node, id)
|
||||
if err == nil {
|
||||
b.eb.CreateContainer(EventActionDelete, node, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *containerBiz) ExecCreate(node, id, cmd string) (resp types.IDResponse, err error) {
|
||||
return b.d.ContainerExecCreate(context.TODO(), node, id, cmd)
|
||||
func (b *containerBiz) ExecCreate(ctx context.Context, node, id, cmd string) (resp types.IDResponse, err error) {
|
||||
return b.d.ContainerExecCreate(ctx, node, id, cmd)
|
||||
}
|
||||
|
||||
func (b *containerBiz) ExecAttach(node, id string) (resp types.HijackedResponse, err error) {
|
||||
return b.d.ContainerExecAttach(context.TODO(), node, id)
|
||||
func (b *containerBiz) ExecAttach(ctx context.Context, node, id string) (resp types.HijackedResponse, err error) {
|
||||
return b.d.ContainerExecAttach(ctx, node, id)
|
||||
}
|
||||
|
||||
func (b *containerBiz) ExecStart(node, id string) error {
|
||||
return b.d.ContainerExecStart(context.TODO(), node, id)
|
||||
func (b *containerBiz) ExecStart(ctx context.Context, node, id string) error {
|
||||
return b.d.ContainerExecStart(ctx, node, id)
|
||||
}
|
||||
|
||||
func (b *containerBiz) FetchLogs(node, id string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.ContainerLogs(context.TODO(), node, id, lines, timestamps)
|
||||
func (b *containerBiz) FetchLogs(ctx context.Context, node, id string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.ContainerLogs(ctx, node, id, lines, timestamps)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return stdout.String(), stderr.String(), nil
|
||||
}
|
||||
|
||||
func (b *containerBiz) Prune(node string, user web.User) (count int, size uint64, err error) {
|
||||
func (b *containerBiz) Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error) {
|
||||
var report types.ContainersPruneReport
|
||||
if report, err = b.d.ContainerPrune(context.TODO(), node); err == nil {
|
||||
if report, err = b.d.ContainerPrune(ctx, node); err == nil {
|
||||
count, size = len(report.ContainersDeleted), report.SpaceReclaimed
|
||||
b.eb.CreateContainer(EventActionPrune, node, "", "", user)
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ var builtins = []*dao.Chart{
|
||||
}
|
||||
|
||||
type DashboardBiz interface {
|
||||
FetchData(key string, ids []string, period time.Duration) (data.Map, error)
|
||||
FindDashboard(name, key string) (dashboard *dao.Dashboard, err error)
|
||||
UpdateDashboard(dashboard *dao.Dashboard, user web.User) (err error)
|
||||
FetchData(ctx context.Context, key string, ids []string, period time.Duration) (data.Map, error)
|
||||
FindDashboard(ctx context.Context, name, key string) (dashboard *dao.Dashboard, err error)
|
||||
UpdateDashboard(ctx context.Context, dashboard *dao.Dashboard, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewDashboard(d dao.Interface, mb MetricBiz, eb EventBiz) DashboardBiz {
|
||||
@ -41,29 +41,29 @@ type dashboardBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) FindDashboard(name, key string) (dashboard *dao.Dashboard, err error) {
|
||||
if dashboard, err = b.d.DashboardGet(context.TODO(), name, key); err != nil {
|
||||
func (b *dashboardBiz) FindDashboard(ctx context.Context, name, key string) (dashboard *dao.Dashboard, err error) {
|
||||
if dashboard, err = b.d.DashboardGet(ctx, name, key); err != nil {
|
||||
return
|
||||
}
|
||||
if dashboard == nil {
|
||||
dashboard = b.defaultDashboard(name, key)
|
||||
}
|
||||
err = b.fillCharts(dashboard)
|
||||
err = b.fillCharts(ctx, dashboard)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) UpdateDashboard(dashboard *dao.Dashboard, user web.User) (err error) {
|
||||
func (b *dashboardBiz) UpdateDashboard(ctx context.Context, dashboard *dao.Dashboard, user web.User) (err error) {
|
||||
dashboard.UpdatedAt = now()
|
||||
dashboard.UpdatedBy = newOperator(user)
|
||||
return b.d.DashboardUpdate(context.TODO(), dashboard)
|
||||
return b.d.DashboardUpdate(ctx, dashboard)
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) FetchData(key string, ids []string, period time.Duration) (data.Map, error) {
|
||||
func (b *dashboardBiz) FetchData(ctx context.Context, key string, ids []string, period time.Duration) (data.Map, error) {
|
||||
if !b.mb.Enabled() {
|
||||
return data.Map{}, nil
|
||||
}
|
||||
|
||||
charts, err := b.getCharts(ids)
|
||||
charts, err := b.getCharts(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -82,11 +82,11 @@ func (b *dashboardBiz) FetchData(key string, ids []string, period time.Duration)
|
||||
d := Data{id: c.ID}
|
||||
switch c.Type {
|
||||
case "line", "bar":
|
||||
d.data, d.err = b.fetchMatrixData(c, key, start, end)
|
||||
d.data, d.err = b.fetchMatrixData(ctx, c, key, start, end)
|
||||
case "pie":
|
||||
d.data, d.err = b.fetchVectorData(c, key, end)
|
||||
d.data, d.err = b.fetchVectorData(ctx, c, key, end)
|
||||
case "gauge":
|
||||
d.data, d.err = b.fetchScalarData(c, key, end)
|
||||
d.data, d.err = b.fetchScalarData(ctx, c, key, end)
|
||||
default:
|
||||
d.err = errors.New("invalid chart type: " + c.Type)
|
||||
}
|
||||
@ -107,7 +107,7 @@ func (b *dashboardBiz) FetchData(key string, ids []string, period time.Duration)
|
||||
return ds, nil
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) fetchMatrixData(chart *dao.Chart, key string, start, end time.Time) (md *MatrixData, err error) {
|
||||
func (b *dashboardBiz) fetchMatrixData(ctx context.Context, chart *dao.Chart, key string, start, end time.Time) (md *MatrixData, err error) {
|
||||
var (
|
||||
q string
|
||||
d *MatrixData
|
||||
@ -118,7 +118,7 @@ func (b *dashboardBiz) fetchMatrixData(chart *dao.Chart, key string, start, end
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if d, err = b.mb.GetMatrix(q, m.Legend, start, end); err != nil {
|
||||
if d, err = b.mb.GetMatrix(ctx, q, m.Legend, start, end); err != nil {
|
||||
log.Get("metric").Error(err)
|
||||
} else if i == 0 {
|
||||
md = d
|
||||
@ -130,7 +130,7 @@ func (b *dashboardBiz) fetchMatrixData(chart *dao.Chart, key string, start, end
|
||||
return md, nil
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) fetchVectorData(chart *dao.Chart, key string, end time.Time) (cvd *VectorData, err error) {
|
||||
func (b *dashboardBiz) fetchVectorData(ctx context.Context, chart *dao.Chart, key string, end time.Time) (cvd *VectorData, err error) {
|
||||
var (
|
||||
q string
|
||||
d *VectorData
|
||||
@ -141,7 +141,7 @@ func (b *dashboardBiz) fetchVectorData(chart *dao.Chart, key string, end time.Ti
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if d, err = b.mb.GetVector(q, m.Legend, end); err != nil {
|
||||
if d, err = b.mb.GetVector(ctx, q, m.Legend, end); err != nil {
|
||||
log.Get("metric").Error(err)
|
||||
} else if i == 0 {
|
||||
cvd = d
|
||||
@ -153,13 +153,13 @@ func (b *dashboardBiz) fetchVectorData(chart *dao.Chart, key string, end time.Ti
|
||||
return cvd, nil
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) fetchScalarData(chart *dao.Chart, key string, end time.Time) (*VectorValue, error) {
|
||||
func (b *dashboardBiz) fetchScalarData(ctx context.Context, chart *dao.Chart, key string, end time.Time) (*VectorValue, error) {
|
||||
query, err := b.formatQuery(chart.Metrics[0].Query, chart.Dashboard, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v, err := b.mb.GetScalar(query, end)
|
||||
v, err := b.mb.GetScalar(ctx, query, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (b *dashboardBiz) formatQuery(query, dashboard, key string) (string, error)
|
||||
return "", errs[0]
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) getCharts(ids []string) (charts map[string]*dao.Chart, err error) {
|
||||
func (b *dashboardBiz) getCharts(ctx context.Context, ids []string) (charts map[string]*dao.Chart, err error) {
|
||||
var (
|
||||
customIds []string
|
||||
customCharts []*dao.Chart
|
||||
@ -210,7 +210,7 @@ func (b *dashboardBiz) getCharts(ids []string) (charts map[string]*dao.Chart, er
|
||||
}
|
||||
|
||||
if len(customIds) > 0 {
|
||||
if customCharts, err = b.d.ChartGetBatch(context.TODO(), customIds...); err == nil {
|
||||
if customCharts, err = b.d.ChartGetBatch(ctx, customIds...); err == nil {
|
||||
for _, chart := range customCharts {
|
||||
charts[chart.ID] = chart
|
||||
}
|
||||
@ -219,7 +219,7 @@ func (b *dashboardBiz) getCharts(ids []string) (charts map[string]*dao.Chart, er
|
||||
return
|
||||
}
|
||||
|
||||
func (b *dashboardBiz) fillCharts(d *dao.Dashboard) (err error) {
|
||||
func (b *dashboardBiz) fillCharts(ctx context.Context, d *dao.Dashboard) (err error) {
|
||||
if len(d.Charts) == 0 {
|
||||
return
|
||||
}
|
||||
@ -233,7 +233,7 @@ func (b *dashboardBiz) fillCharts(d *dao.Dashboard) (err error) {
|
||||
ids[i] = c.ID
|
||||
}
|
||||
|
||||
m, err = b.getCharts(ids)
|
||||
m, err = b.getCharts(ctx, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
12
biz/event.go
12
biz/event.go
@ -48,8 +48,8 @@ const (
|
||||
)
|
||||
|
||||
type EventBiz interface {
|
||||
Search(args *dao.EventSearchArgs) (events []*dao.Event, total int, err error)
|
||||
Prune(days int32) (err error)
|
||||
Search(ctx context.Context, args *dao.EventSearchArgs) (events []*dao.Event, total int, err error)
|
||||
Prune(ctx context.Context, days int32) (err error)
|
||||
CreateRegistry(action EventAction, id, name string, user web.User)
|
||||
CreateNode(action EventAction, id, name string, user web.User)
|
||||
CreateNetwork(action EventAction, id, name string, user web.User)
|
||||
@ -74,12 +74,12 @@ type eventBiz struct {
|
||||
d dao.Interface
|
||||
}
|
||||
|
||||
func (b *eventBiz) Search(args *dao.EventSearchArgs) (events []*dao.Event, total int, err error) {
|
||||
return b.d.EventSearch(context.TODO(), args)
|
||||
func (b *eventBiz) Search(ctx context.Context, args *dao.EventSearchArgs) (events []*dao.Event, total int, err error) {
|
||||
return b.d.EventSearch(ctx, args)
|
||||
}
|
||||
|
||||
func (b *eventBiz) Prune(days int32) (err error) {
|
||||
return b.d.EventPrune(context.TODO(), time.Now().Add(-times.Days(days)))
|
||||
func (b *eventBiz) Prune(ctx context.Context, days int32) (err error) {
|
||||
return b.d.EventPrune(ctx, time.Now().Add(-times.Days(days)))
|
||||
}
|
||||
|
||||
func (b *eventBiz) create(et EventType, ea EventAction, args data.Map, user web.User) {
|
||||
|
23
biz/image.go
23
biz/image.go
@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
type ImageBiz interface {
|
||||
Search(node, name string, pageIndex, pageSize int) ([]*Image, int, error)
|
||||
Find(node, name string) (image *Image, raw string, err error)
|
||||
Delete(node, id string, user web.User) (err error)
|
||||
Prune(node string, user web.User) (count int, size uint64, err error)
|
||||
Search(ctx context.Context, node, name string, pageIndex, pageSize int) ([]*Image, int, error)
|
||||
Find(ctx context.Context, node, name string) (image *Image, raw string, err error)
|
||||
Delete(ctx context.Context, node, id string, user web.User) (err error)
|
||||
Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error)
|
||||
}
|
||||
|
||||
func NewImage(d *docker.Docker, eb EventBiz) ImageBiz {
|
||||
@ -27,12 +27,11 @@ type imageBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *imageBiz) Find(node, id string) (img *Image, raw string, err error) {
|
||||
func (b *imageBiz) Find(ctx context.Context, node, id string) (img *Image, raw string, err error) {
|
||||
var (
|
||||
i types.ImageInspect
|
||||
r []byte
|
||||
histories []image.HistoryResponseItem
|
||||
ctx = context.TODO()
|
||||
)
|
||||
|
||||
if i, r, err = b.d.ImageInspect(ctx, node, id); err == nil {
|
||||
@ -49,8 +48,8 @@ func (b *imageBiz) Find(node, id string) (img *Image, raw string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *imageBiz) Search(node, name string, pageIndex, pageSize int) (images []*Image, total int, err error) {
|
||||
list, total, err := b.d.ImageList(context.TODO(), node, name, pageIndex, pageSize)
|
||||
func (b *imageBiz) Search(ctx context.Context, node, name string, pageIndex, pageSize int) (images []*Image, total int, err error) {
|
||||
list, total, err := b.d.ImageList(ctx, node, name, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -62,17 +61,17 @@ func (b *imageBiz) Search(node, name string, pageIndex, pageSize int) (images []
|
||||
return images, total, nil
|
||||
}
|
||||
|
||||
func (b *imageBiz) Delete(node, id string, user web.User) (err error) {
|
||||
err = b.d.ImageRemove(context.TODO(), node, id)
|
||||
func (b *imageBiz) Delete(ctx context.Context, node, id string, user web.User) (err error) {
|
||||
err = b.d.ImageRemove(ctx, node, id)
|
||||
if err == nil {
|
||||
b.eb.CreateImage(EventActionDelete, node, id, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *imageBiz) Prune(node string, user web.User) (count int, size uint64, err error) {
|
||||
func (b *imageBiz) Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error) {
|
||||
var report types.ImagesPruneReport
|
||||
if report, err = b.d.ImagePrune(context.TODO(), node); err == nil {
|
||||
if report, err = b.d.ImagePrune(ctx, node); err == nil {
|
||||
count, size = len(report.ImagesDeleted), report.SpaceReclaimed
|
||||
b.eb.CreateImage(EventActionPrune, node, "", user)
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
|
||||
type MetricBiz interface {
|
||||
Enabled() bool
|
||||
GetMatrix(query, legend string, start, end time.Time) (data *MatrixData, err error)
|
||||
GetScalar(query string, t time.Time) (data float64, err error)
|
||||
GetVector(query, label string, t time.Time) (data *VectorData, err error)
|
||||
GetMatrix(ctx context.Context, query, legend string, start, end time.Time) (data *MatrixData, err error)
|
||||
GetScalar(ctx context.Context, query string, t time.Time) (data float64, err error)
|
||||
GetVector(ctx context.Context, query, label string, t time.Time) (data *VectorData, err error)
|
||||
}
|
||||
|
||||
func NewMetric(setting *misc.Setting) MetricBiz {
|
||||
@ -50,7 +50,7 @@ func (b *metricBiz) Enabled() bool {
|
||||
return b.prometheus != ""
|
||||
}
|
||||
|
||||
func (b *metricBiz) GetMatrix(query, legend string, start, end time.Time) (data *MatrixData, err error) {
|
||||
func (b *metricBiz) GetMatrix(ctx context.Context, query, legend string, start, end time.Time) (data *MatrixData, err error) {
|
||||
if !b.Enabled() {
|
||||
return
|
||||
}
|
||||
@ -61,7 +61,7 @@ func (b *metricBiz) GetMatrix(query, legend string, start, end time.Time) (data
|
||||
}
|
||||
|
||||
period := end.Sub(start)
|
||||
value, _, err := api.QueryRange(context.Background(), query, papi.Range{
|
||||
value, _, err := api.QueryRange(ctx, query, papi.Range{
|
||||
Start: start,
|
||||
End: end,
|
||||
Step: b.calcStep(period),
|
||||
@ -87,7 +87,7 @@ func (b *metricBiz) GetMatrix(query, legend string, start, end time.Time) (data
|
||||
return
|
||||
}
|
||||
|
||||
func (b *metricBiz) GetScalar(query string, t time.Time) (v float64, err error) {
|
||||
func (b *metricBiz) GetScalar(ctx context.Context, query string, t time.Time) (v float64, err error) {
|
||||
if !b.Enabled() {
|
||||
return
|
||||
}
|
||||
@ -97,7 +97,7 @@ func (b *metricBiz) GetScalar(query string, t time.Time) (v float64, err error)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
value, _, err := api.Query(context.Background(), query, t)
|
||||
value, _, err := api.Query(ctx, query, t)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -111,7 +111,7 @@ func (b *metricBiz) GetScalar(query string, t time.Time) (v float64, err error)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (b *metricBiz) GetVector(query, label string, t time.Time) (data *VectorData, err error) {
|
||||
func (b *metricBiz) GetVector(ctx context.Context, query, label string, t time.Time) (data *VectorData, err error) {
|
||||
if !b.Enabled() {
|
||||
return
|
||||
}
|
||||
@ -123,7 +123,7 @@ func (b *metricBiz) GetVector(query, label string, t time.Time) (data *VectorDat
|
||||
}
|
||||
|
||||
var value model.Value
|
||||
value, _, err = api.Query(context.Background(), query, t)
|
||||
value, _, err = api.Query(ctx, query, t)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
type NetworkBiz interface {
|
||||
Search() ([]*Network, error)
|
||||
Find(name string) (network *Network, raw string, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Create(n *Network, user web.User) (err error)
|
||||
Disconnect(networkId, networkName, container string, user web.User) (err error)
|
||||
Search(ctx context.Context) ([]*Network, error)
|
||||
Find(ctx context.Context, name string) (network *Network, raw string, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, n *Network, user web.User) (err error)
|
||||
Disconnect(ctx context.Context, networkId, networkName, container string, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewNetwork(d *docker.Docker, eb EventBiz) NetworkBiz {
|
||||
@ -27,7 +27,7 @@ type networkBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *networkBiz) Create(n *Network, user web.User) (err error) {
|
||||
func (b *networkBiz) Create(ctx context.Context, n *Network, user web.User) (err error) {
|
||||
nc := &types.NetworkCreate{
|
||||
Driver: n.Driver,
|
||||
Scope: n.Scope,
|
||||
@ -48,19 +48,19 @@ func (b *networkBiz) Create(n *Network, user web.User) (err error) {
|
||||
IPRange: c.Range,
|
||||
})
|
||||
}
|
||||
err = b.d.NetworkCreate(context.TODO(), n.Name, nc)
|
||||
err = b.d.NetworkCreate(ctx, n.Name, nc)
|
||||
if err != nil {
|
||||
b.eb.CreateNetwork(EventActionCreate, n.Name, n.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *networkBiz) Find(name string) (network *Network, raw string, err error) {
|
||||
func (b *networkBiz) Find(ctx context.Context, name string) (network *Network, raw string, err error) {
|
||||
var (
|
||||
nr types.NetworkResource
|
||||
r []byte
|
||||
)
|
||||
nr, r, err = b.d.NetworkInspect(context.TODO(), name)
|
||||
nr, r, err = b.d.NetworkInspect(ctx, name)
|
||||
if err == nil {
|
||||
network = newNetwork(&nr)
|
||||
raw, err = indentJSON(r)
|
||||
@ -68,8 +68,8 @@ func (b *networkBiz) Find(name string) (network *Network, raw string, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *networkBiz) Search() ([]*Network, error) {
|
||||
list, err := b.d.NetworkList(context.TODO())
|
||||
func (b *networkBiz) Search(ctx context.Context) ([]*Network, error) {
|
||||
list, err := b.d.NetworkList(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -81,16 +81,16 @@ func (b *networkBiz) Search() ([]*Network, error) {
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
func (b *networkBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.NetworkRemove(context.TODO(), name)
|
||||
func (b *networkBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.NetworkRemove(ctx, name)
|
||||
if err == nil {
|
||||
b.eb.CreateNetwork(EventActionDelete, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *networkBiz) Disconnect(networkId, networkName, container string, user web.User) (err error) {
|
||||
err = b.d.NetworkDisconnect(context.TODO(), networkName, container)
|
||||
func (b *networkBiz) Disconnect(ctx context.Context, networkId, networkName, container string, user web.User) (err error) {
|
||||
err = b.d.NetworkDisconnect(ctx, networkName, container)
|
||||
if err == nil {
|
||||
b.eb.CreateNetwork(EventActionDisconnect, networkId, networkName, user)
|
||||
}
|
||||
|
24
biz/node.go
24
biz/node.go
@ -12,10 +12,10 @@ import (
|
||||
|
||||
type NodeBiz interface {
|
||||
List(agent bool) ([]*docker.Node, error)
|
||||
Search() ([]*Node, error)
|
||||
Find(id string) (node *Node, raw string, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Update(n *Node, user web.User) (err error)
|
||||
Search(ctx context.Context) ([]*Node, error)
|
||||
Find(ctx context.Context, id string) (node *Node, raw string, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Update(ctx context.Context, n *Node, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewNode(d *docker.Docker, eb EventBiz) NodeBiz {
|
||||
@ -27,12 +27,12 @@ type nodeBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *nodeBiz) Find(id string) (node *Node, raw string, err error) {
|
||||
func (b *nodeBiz) Find(ctx context.Context, id string) (node *Node, raw string, err error) {
|
||||
var (
|
||||
sn swarm.Node
|
||||
r []byte
|
||||
)
|
||||
sn, r, err = b.d.NodeInspect(context.TODO(), id)
|
||||
sn, r, err = b.d.NodeInspect(ctx, id)
|
||||
if err == nil {
|
||||
raw, err = indentJSON(r)
|
||||
}
|
||||
@ -60,8 +60,8 @@ func (b *nodeBiz) List(agent bool) ([]*docker.Node, error) {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (b *nodeBiz) Search() ([]*Node, error) {
|
||||
list, err := b.d.NodeList(context.TODO())
|
||||
func (b *nodeBiz) Search(ctx context.Context) ([]*Node, error) {
|
||||
list, err := b.d.NodeList(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -73,22 +73,22 @@ func (b *nodeBiz) Search() ([]*Node, error) {
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
func (b *nodeBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.NodeRemove(context.TODO(), id)
|
||||
func (b *nodeBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.NodeRemove(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateNode(EventActionDelete, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *nodeBiz) Update(n *Node, user web.User) (err error) {
|
||||
func (b *nodeBiz) Update(ctx context.Context, n *Node, user web.User) (err error) {
|
||||
spec := &swarm.NodeSpec{
|
||||
Role: n.Role,
|
||||
Availability: n.Availability,
|
||||
}
|
||||
spec.Name = n.Name
|
||||
spec.Labels = toMap(n.Labels)
|
||||
err = b.d.NodeUpdate(context.TODO(), n.ID, n.Version, spec)
|
||||
err = b.d.NodeUpdate(ctx, n.ID, n.Version, spec)
|
||||
if err == nil {
|
||||
b.eb.CreateNode(EventActionUpdate, n.ID, n.Hostname, user)
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ import (
|
||||
)
|
||||
|
||||
type RegistryBiz interface {
|
||||
Search() ([]*dao.Registry, error)
|
||||
Find(id string) (*dao.Registry, error)
|
||||
GetAuth(url string) (auth string, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Create(registry *dao.Registry, user web.User) (err error)
|
||||
Update(registry *dao.Registry, user web.User) (err error)
|
||||
Search(ctx context.Context) ([]*dao.Registry, error)
|
||||
Find(ctx context.Context, id string) (*dao.Registry, error)
|
||||
GetAuth(ctx context.Context, url string) (auth string, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, registry *dao.Registry, user web.User) (err error)
|
||||
Update(ctx context.Context, registry *dao.Registry, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewRegistry(d dao.Interface, eb EventBiz) RegistryBiz {
|
||||
@ -28,32 +28,32 @@ type registryBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *registryBiz) Create(r *dao.Registry, user web.User) (err error) {
|
||||
func (b *registryBiz) Create(ctx context.Context, r *dao.Registry, user web.User) (err error) {
|
||||
r.ID = createId()
|
||||
r.CreatedAt = now()
|
||||
r.UpdatedAt = r.CreatedAt
|
||||
r.CreatedBy = newOperator(user)
|
||||
r.UpdatedBy = r.CreatedBy
|
||||
|
||||
err = b.d.RegistryCreate(context.TODO(), r)
|
||||
err = b.d.RegistryCreate(ctx, r)
|
||||
if err == nil {
|
||||
b.eb.CreateRegistry(EventActionCreate, r.ID, r.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *registryBiz) Update(r *dao.Registry, user web.User) (err error) {
|
||||
func (b *registryBiz) Update(ctx context.Context, r *dao.Registry, user web.User) (err error) {
|
||||
r.UpdatedAt = now()
|
||||
r.UpdatedBy = newOperator(user)
|
||||
err = b.d.RegistryUpdate(context.TODO(), r)
|
||||
err = b.d.RegistryUpdate(ctx, r)
|
||||
if err == nil {
|
||||
b.eb.CreateRegistry(EventActionUpdate, r.ID, r.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *registryBiz) Search() (registries []*dao.Registry, err error) {
|
||||
registries, err = b.d.RegistryGetAll(context.TODO())
|
||||
func (b *registryBiz) Search(ctx context.Context) (registries []*dao.Registry, err error) {
|
||||
registries, err = b.d.RegistryGetAll(ctx)
|
||||
if err == nil {
|
||||
for _, r := range registries {
|
||||
r.Password = ""
|
||||
@ -62,20 +62,20 @@ func (b *registryBiz) Search() (registries []*dao.Registry, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *registryBiz) Find(id string) (registry *dao.Registry, err error) {
|
||||
registry, err = b.d.RegistryGet(context.TODO(), id)
|
||||
func (b *registryBiz) Find(ctx context.Context, id string) (registry *dao.Registry, err error) {
|
||||
registry, err = b.d.RegistryGet(ctx, id)
|
||||
if err == nil {
|
||||
registry.Password = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *registryBiz) GetAuth(url string) (auth string, err error) {
|
||||
func (b *registryBiz) GetAuth(ctx context.Context, url string) (auth string, err error) {
|
||||
var (
|
||||
r *dao.Registry
|
||||
buf []byte
|
||||
)
|
||||
if r, err = b.d.RegistryGetByURL(context.TODO(), url); err == nil && r != nil {
|
||||
if r, err = b.d.RegistryGetByURL(ctx, url); err == nil && r != nil {
|
||||
cfg := &types.AuthConfig{
|
||||
ServerAddress: r.URL,
|
||||
Username: r.Username,
|
||||
@ -88,8 +88,8 @@ func (b *registryBiz) GetAuth(url string) (auth string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *registryBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.RegistryDelete(context.TODO(), id)
|
||||
func (b *registryBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.RegistryDelete(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateRegistry(EventActionDelete, id, name, user)
|
||||
}
|
||||
|
40
biz/role.go
40
biz/role.go
@ -8,12 +8,12 @@ import (
|
||||
)
|
||||
|
||||
type RoleBiz interface {
|
||||
Search(name string) ([]*dao.Role, error)
|
||||
Find(id string) (role *dao.Role, err error)
|
||||
Create(role *dao.Role, user web.User) (err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Update(r *dao.Role, user web.User) (err error)
|
||||
GetPerms(ids []string) ([]string, error)
|
||||
Search(ctx context.Context, name string) ([]*dao.Role, error)
|
||||
Find(ctx context.Context, id string) (role *dao.Role, err error)
|
||||
Create(ctx context.Context, role *dao.Role, user web.User) (err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Update(ctx context.Context, r *dao.Role, user web.User) (err error)
|
||||
GetPerms(ctx context.Context, ids []string) ([]string, error)
|
||||
}
|
||||
|
||||
func NewRole(d dao.Interface, eb EventBiz) RoleBiz {
|
||||
@ -25,11 +25,11 @@ type roleBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *roleBiz) Search(name string) (roles []*dao.Role, err error) {
|
||||
return b.d.RoleSearch(context.TODO(), name)
|
||||
func (b *roleBiz) Search(ctx context.Context, name string) (roles []*dao.Role, err error) {
|
||||
return b.d.RoleSearch(ctx, name)
|
||||
}
|
||||
|
||||
func (b *roleBiz) Create(role *dao.Role, user web.User) (err error) {
|
||||
func (b *roleBiz) Create(ctx context.Context, role *dao.Role, user web.User) (err error) {
|
||||
r := &dao.Role{
|
||||
ID: createId(),
|
||||
Name: role.Name,
|
||||
@ -40,29 +40,29 @@ func (b *roleBiz) Create(role *dao.Role, user web.User) (err error) {
|
||||
}
|
||||
r.UpdatedAt = r.CreatedAt
|
||||
r.UpdatedBy = r.CreatedBy
|
||||
err = b.d.RoleCreate(context.TODO(), r)
|
||||
err = b.d.RoleCreate(ctx, r)
|
||||
if err == nil {
|
||||
b.eb.CreateRole(EventActionCreate, r.ID, role.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *roleBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.RoleDelete(context.TODO(), id)
|
||||
func (b *roleBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.RoleDelete(ctx, id)
|
||||
if err == nil {
|
||||
go func() {
|
||||
_ = b.d.SessionUpdateDirty(context.TODO(), "", id)
|
||||
_ = b.d.SessionUpdateDirty(ctx, "", id)
|
||||
b.eb.CreateRole(EventActionDelete, id, name, user)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *roleBiz) Find(id string) (role *dao.Role, err error) {
|
||||
return b.d.RoleGet(context.TODO(), id)
|
||||
func (b *roleBiz) Find(ctx context.Context, id string) (role *dao.Role, err error) {
|
||||
return b.d.RoleGet(ctx, id)
|
||||
}
|
||||
|
||||
func (b *roleBiz) Update(role *dao.Role, user web.User) (err error) {
|
||||
func (b *roleBiz) Update(ctx context.Context, role *dao.Role, user web.User) (err error) {
|
||||
r := &dao.Role{
|
||||
ID: role.ID,
|
||||
Name: role.Name,
|
||||
@ -71,21 +71,21 @@ func (b *roleBiz) Update(role *dao.Role, user web.User) (err error) {
|
||||
UpdatedAt: now(),
|
||||
UpdatedBy: newOperator(user),
|
||||
}
|
||||
err = b.d.RoleUpdate(context.TODO(), r)
|
||||
err = b.d.RoleUpdate(ctx, r)
|
||||
if err == nil {
|
||||
go func() {
|
||||
_ = b.d.SessionUpdateDirty(context.TODO(), "", role.ID)
|
||||
_ = b.d.SessionUpdateDirty(ctx, "", role.ID)
|
||||
b.eb.CreateRole(EventActionUpdate, role.ID, role.Name, user)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *roleBiz) GetPerms(ids []string) ([]string, error) {
|
||||
func (b *roleBiz) GetPerms(ctx context.Context, ids []string) ([]string, error) {
|
||||
m := make(map[string]struct{})
|
||||
|
||||
for _, id := range ids {
|
||||
r, err := b.d.RoleGet(context.TODO(), id)
|
||||
r, err := b.d.RoleGet(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type SecretBiz interface {
|
||||
Search(name string, pageIndex, pageSize int) (secrets []*Secret, total int, err error)
|
||||
Find(id string) (secret *Secret, raw string, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
Create(c *Secret, user web.User) (err error)
|
||||
Update(c *Secret, user web.User) (err error)
|
||||
Search(ctx context.Context, name string, pageIndex, pageSize int) (secrets []*Secret, total int, err error)
|
||||
Find(ctx context.Context, id string) (secret *Secret, raw string, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, secret *Secret, user web.User) (err error)
|
||||
Update(ctx context.Context, secret *Secret, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewSecret(d *docker.Docker, eb EventBiz) SecretBiz {
|
||||
@ -26,12 +26,12 @@ type secretBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *secretBiz) Find(id string) (secret *Secret, raw string, err error) {
|
||||
func (b *secretBiz) Find(ctx context.Context, id string) (secret *Secret, raw string, err error) {
|
||||
var (
|
||||
c swarm.Secret
|
||||
r []byte
|
||||
)
|
||||
c, r, err = b.d.SecretInspect(context.TODO(), id)
|
||||
c, r, err = b.d.SecretInspect(ctx, id)
|
||||
if err == nil {
|
||||
raw, err = indentJSON(r)
|
||||
}
|
||||
@ -41,8 +41,8 @@ func (b *secretBiz) Find(id string) (secret *Secret, raw string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *secretBiz) Search(name string, pageIndex, pageSize int) ([]*Secret, int, error) {
|
||||
list, total, err := b.d.SecretList(context.TODO(), name, pageIndex, pageSize)
|
||||
func (b *secretBiz) Search(ctx context.Context, name string, pageIndex, pageSize int) ([]*Secret, int, error) {
|
||||
list, total, err := b.d.SecretList(ctx, name, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -54,15 +54,15 @@ func (b *secretBiz) Search(name string, pageIndex, pageSize int) ([]*Secret, int
|
||||
return secrets, total, nil
|
||||
}
|
||||
|
||||
func (b *secretBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.SecretRemove(context.TODO(), id)
|
||||
func (b *secretBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.SecretRemove(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateSecret(EventActionDelete, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *secretBiz) Create(c *Secret, user web.User) (err error) {
|
||||
func (b *secretBiz) Create(ctx context.Context, c *Secret, user web.User) (err error) {
|
||||
spec := swarm.SecretSpec{
|
||||
Data: []byte(c.Data),
|
||||
}
|
||||
@ -82,14 +82,14 @@ func (b *secretBiz) Create(c *Secret, user web.User) (err error) {
|
||||
}
|
||||
|
||||
var id string
|
||||
id, err = b.d.SecretCreate(context.TODO(), &spec)
|
||||
id, err = b.d.SecretCreate(ctx, &spec)
|
||||
if err != nil {
|
||||
b.eb.CreateSecret(EventActionCreate, id, c.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *secretBiz) Update(c *Secret, user web.User) (err error) {
|
||||
func (b *secretBiz) Update(ctx context.Context, c *Secret, user web.User) (err error) {
|
||||
spec := &swarm.SecretSpec{
|
||||
Data: []byte(c.Data),
|
||||
}
|
||||
@ -107,7 +107,7 @@ func (b *secretBiz) Update(c *Secret, user web.User) (err error) {
|
||||
Options: toMap(c.Templating.Options),
|
||||
}
|
||||
}
|
||||
err = b.d.SecretUpdate(context.TODO(), c.ID, c.Version, spec)
|
||||
err = b.d.SecretUpdate(ctx, c.ID, c.Version, spec)
|
||||
if err == nil {
|
||||
b.eb.CreateSecret(EventActionUpdate, c.ID, c.Name, user)
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ const (
|
||||
)
|
||||
|
||||
type ServiceBiz interface {
|
||||
Search(name, mode string, pageIndex, pageSize int) (services []*ServiceBase, total int, err error)
|
||||
Find(name string, status bool) (service *Service, raw string, err error)
|
||||
Delete(name string, user web.User) (err error)
|
||||
Rollback(name string, user web.User) (err error)
|
||||
Restart(name string, user web.User) (err error)
|
||||
Scale(name string, count, version uint64, user web.User) (err error)
|
||||
Create(s *Service, user web.User) (err error)
|
||||
Update(s *Service, user web.User) (err error)
|
||||
FetchLogs(name string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
Search(ctx context.Context, name, mode string, pageIndex, pageSize int) (services []*ServiceBase, total int, err error)
|
||||
Find(ctx context.Context, name string, status bool) (service *Service, raw string, err error)
|
||||
Delete(ctx context.Context, name string, user web.User) (err error)
|
||||
Rollback(ctx context.Context, name string, user web.User) (err error)
|
||||
Restart(ctx context.Context, name string, user web.User) (err error)
|
||||
Scale(ctx context.Context, name string, count, version uint64, user web.User) (err error)
|
||||
Create(ctx context.Context, s *Service, user web.User) (err error)
|
||||
Update(ctx context.Context, s *Service, user web.User) (err error)
|
||||
FetchLogs(ctx context.Context, name string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
}
|
||||
|
||||
func NewService(d *docker.Docker, rb RegistryBiz, eb EventBiz) ServiceBiz {
|
||||
@ -45,13 +45,13 @@ type serviceBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Find(name string, status bool) (service *Service, raw string, err error) {
|
||||
func (b *serviceBiz) Find(ctx context.Context, name string, status bool) (service *Service, raw string, err error) {
|
||||
var (
|
||||
s swarm.Service
|
||||
r []byte
|
||||
)
|
||||
|
||||
s, r, err = b.d.ServiceInspect(context.TODO(), name, status)
|
||||
s, r, err = b.d.ServiceInspect(ctx, name, status)
|
||||
if err != nil {
|
||||
if docker.IsErrNotFound(err) {
|
||||
err = nil
|
||||
@ -64,12 +64,12 @@ func (b *serviceBiz) Find(name string, status bool) (service *Service, raw strin
|
||||
}
|
||||
if err == nil {
|
||||
service = newService(&s)
|
||||
err = b.fillNetworks(service)
|
||||
err = b.fillNetworks(ctx, service)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) fillNetworks(service *Service) error {
|
||||
func (b *serviceBiz) fillNetworks(ctx context.Context, service *Service) error {
|
||||
if len(service.Endpoint.VIPs) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (b *serviceBiz) fillNetworks(service *Service) error {
|
||||
ids[i] = vip.ID
|
||||
}
|
||||
|
||||
names, err := b.d.NetworkNames(context.TODO(), ids...)
|
||||
names, err := b.d.NetworkNames(ctx, ids...)
|
||||
if err == nil {
|
||||
for i := range service.Endpoint.VIPs {
|
||||
vip := &service.Endpoint.VIPs[i]
|
||||
@ -93,9 +93,9 @@ func (b *serviceBiz) fillNetworks(service *Service) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Search(name, mode string, pageIndex, pageSize int) (services []*ServiceBase, total int, err error) {
|
||||
func (b *serviceBiz) Search(ctx context.Context, name, mode string, pageIndex, pageSize int) (services []*ServiceBase, total int, err error) {
|
||||
var list []swarm.Service
|
||||
list, total, err = b.d.ServiceList(context.TODO(), name, mode, pageIndex, pageSize)
|
||||
list, total, err = b.d.ServiceList(ctx, name, mode, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -107,39 +107,39 @@ func (b *serviceBiz) Search(name, mode string, pageIndex, pageSize int) (service
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Delete(name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRemove(context.TODO(), name)
|
||||
func (b *serviceBiz) Delete(ctx context.Context, name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRemove(ctx, name)
|
||||
if err == nil {
|
||||
b.eb.CreateService(EventActionDelete, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Rollback(name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRollback(context.TODO(), name)
|
||||
func (b *serviceBiz) Rollback(ctx context.Context, name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRollback(ctx, name)
|
||||
if err == nil {
|
||||
b.eb.CreateService(EventActionRollback, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Restart(name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRestart(context.TODO(), name)
|
||||
func (b *serviceBiz) Restart(ctx context.Context, name string, user web.User) (err error) {
|
||||
err = b.d.ServiceRestart(ctx, name)
|
||||
if err == nil {
|
||||
b.eb.CreateService(EventActionRestart, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Scale(name string, count, version uint64, user web.User) (err error) {
|
||||
err = b.d.ServiceScale(context.TODO(), name, count, version)
|
||||
func (b *serviceBiz) Scale(ctx context.Context, name string, count, version uint64, user web.User) (err error) {
|
||||
err = b.d.ServiceScale(ctx, name, count, version)
|
||||
if err == nil {
|
||||
b.eb.CreateService(EventActionScale, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Create(s *Service, user web.User) (err error) {
|
||||
func (b *serviceBiz) Create(ctx context.Context, s *Service, user web.User) (err error) {
|
||||
spec := &swarm.ServiceSpec{TaskTemplate: swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{}}}
|
||||
err = s.MergeTo(spec)
|
||||
if err != nil {
|
||||
@ -159,21 +159,21 @@ func (b *serviceBiz) Create(s *Service, user web.User) (err error) {
|
||||
auth := ""
|
||||
if i := strings.Index(s.Image, "/"); i > 0 {
|
||||
if host := s.Image[:i]; strings.Contains(host, ".") {
|
||||
auth, err = b.rb.GetAuth(host)
|
||||
auth, err = b.rb.GetAuth(ctx, host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = b.d.ServiceCreate(context.TODO(), spec, auth); err == nil {
|
||||
if err = b.d.ServiceCreate(ctx, spec, auth); err == nil {
|
||||
b.eb.CreateService(EventActionCreate, s.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) Update(s *Service, user web.User) (err error) {
|
||||
service, _, err := b.d.ServiceInspect(context.TODO(), s.Name, false)
|
||||
func (b *serviceBiz) Update(ctx context.Context, s *Service, user web.User) (err error) {
|
||||
service, _, err := b.d.ServiceInspect(ctx, s.Name, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -190,14 +190,14 @@ func (b *serviceBiz) Update(s *Service, user web.User) (err error) {
|
||||
spec.Mode.ReplicatedJob.TotalCompletions = &s.Replicas
|
||||
}
|
||||
|
||||
if err = b.d.ServiceUpdate(context.TODO(), spec, s.Version); err == nil {
|
||||
if err = b.d.ServiceUpdate(ctx, spec, s.Version); err == nil {
|
||||
b.eb.CreateService(EventActionUpdate, s.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *serviceBiz) FetchLogs(name string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.ServiceLogs(context.TODO(), name, lines, timestamps)
|
||||
func (b *serviceBiz) FetchLogs(ctx context.Context, name string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.ServiceLogs(ctx, name, lines, timestamps)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
type SessionBiz interface {
|
||||
Find(token string) (session *dao.Session, err error)
|
||||
Create(session *dao.Session) (err error)
|
||||
Update(session *dao.Session) (err error)
|
||||
UpdateExpiry(id string, expiry time.Time) (err error)
|
||||
Find(ctx context.Context, token string) (session *dao.Session, err error)
|
||||
Create(ctx context.Context, session *dao.Session) (err error)
|
||||
Update(ctx context.Context, session *dao.Session) (err error)
|
||||
UpdateExpiry(ctx context.Context, id string, expiry time.Time) (err error)
|
||||
}
|
||||
|
||||
func NewSession(d dao.Interface, rb RoleBiz) SessionBiz {
|
||||
@ -23,22 +23,22 @@ type sessionBiz struct {
|
||||
rb RoleBiz
|
||||
}
|
||||
|
||||
func (b *sessionBiz) Find(token string) (session *dao.Session, err error) {
|
||||
return b.d.SessionGet(context.TODO(), token)
|
||||
func (b *sessionBiz) Find(ctx context.Context, token string) (session *dao.Session, err error) {
|
||||
return b.d.SessionGet(ctx, token)
|
||||
}
|
||||
|
||||
func (b *sessionBiz) Create(session *dao.Session) (err error) {
|
||||
func (b *sessionBiz) Create(ctx context.Context, session *dao.Session) (err error) {
|
||||
session.CreatedAt = time.Now()
|
||||
session.UpdatedAt = session.CreatedAt
|
||||
return b.d.SessionCreate(context.TODO(), session)
|
||||
return b.d.SessionCreate(ctx, session)
|
||||
}
|
||||
|
||||
func (b *sessionBiz) Update(session *dao.Session) (err error) {
|
||||
func (b *sessionBiz) Update(ctx context.Context, session *dao.Session) (err error) {
|
||||
session.Dirty = false
|
||||
session.UpdatedAt = time.Now()
|
||||
return b.d.SessionUpdate(context.TODO(), session)
|
||||
return b.d.SessionUpdate(ctx, session)
|
||||
}
|
||||
|
||||
func (b *sessionBiz) UpdateExpiry(id string, expiry time.Time) (err error) {
|
||||
return b.d.SessionUpdateExpiry(context.TODO(), id, expiry)
|
||||
func (b *sessionBiz) UpdateExpiry(ctx context.Context, id string, expiry time.Time) (err error) {
|
||||
return b.d.SessionUpdateExpiry(ctx, id, expiry)
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
)
|
||||
|
||||
type SettingBiz interface {
|
||||
Find(id string) (options interface{}, err error)
|
||||
Load() (options data.Map, err error)
|
||||
Save(id string, options interface{}, user web.User) (err error)
|
||||
Find(ctx context.Context, id string) (options interface{}, err error)
|
||||
Load(ctx context.Context) (options data.Map, err error)
|
||||
Save(ctx context.Context, id string, options interface{}, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewSetting(d dao.Interface, eb EventBiz) SettingBiz {
|
||||
@ -26,9 +26,9 @@ type settingBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *settingBiz) Find(id string) (options interface{}, err error) {
|
||||
func (b *settingBiz) Find(ctx context.Context, id string) (options interface{}, err error) {
|
||||
var setting *dao.Setting
|
||||
setting, err = b.d.SettingGet(context.TODO(), id)
|
||||
setting, err = b.d.SettingGet(ctx, id)
|
||||
if err == nil && setting != nil {
|
||||
return b.unmarshal(setting.Options)
|
||||
}
|
||||
@ -36,9 +36,9 @@ func (b *settingBiz) Find(id string) (options interface{}, err error) {
|
||||
}
|
||||
|
||||
// Load returns settings of swirl. If not found, default settings will be returned.
|
||||
func (b *settingBiz) Load() (options data.Map, err error) {
|
||||
func (b *settingBiz) Load(ctx context.Context) (options data.Map, err error) {
|
||||
var settings []*dao.Setting
|
||||
settings, err = b.d.SettingGetAll(context.TODO())
|
||||
settings, err = b.d.SettingGetAll(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -54,7 +54,7 @@ func (b *settingBiz) Load() (options data.Map, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *settingBiz) Save(id string, options interface{}, user web.User) (err error) {
|
||||
func (b *settingBiz) Save(ctx context.Context, id string, options interface{}, user web.User) (err error) {
|
||||
setting := &dao.Setting{
|
||||
ID: id,
|
||||
UpdatedAt: time.Now(),
|
||||
@ -65,7 +65,7 @@ func (b *settingBiz) Save(id string, options interface{}, user web.User) (err er
|
||||
|
||||
setting.Options, err = b.marshal(options)
|
||||
if err == nil {
|
||||
err = b.d.SettingUpdate(context.TODO(), setting)
|
||||
err = b.d.SettingUpdate(ctx, setting)
|
||||
}
|
||||
if err == nil && user != nil {
|
||||
b.eb.CreateSetting(EventActionUpdate, user)
|
||||
|
50
biz/stack.go
50
biz/stack.go
@ -13,13 +13,13 @@ import (
|
||||
)
|
||||
|
||||
type StackBiz interface {
|
||||
Search(name, filter string) (stacks []*dao.Stack, err error)
|
||||
Find(name string) (stack *dao.Stack, err error)
|
||||
Delete(name string, user web.User) (err error)
|
||||
Shutdown(name string, user web.User) (err error)
|
||||
Deploy(name string, user web.User) (err error)
|
||||
Create(s *dao.Stack, user web.User) (err error)
|
||||
Update(s *dao.Stack, user web.User) (err error)
|
||||
Search(ctx context.Context, name, filter string) (stacks []*dao.Stack, err error)
|
||||
Find(ctx context.Context, name string) (stack *dao.Stack, err error)
|
||||
Delete(ctx context.Context, name string, user web.User) (err error)
|
||||
Shutdown(ctx context.Context, name string, user web.User) (err error)
|
||||
Deploy(ctx context.Context, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, s *dao.Stack, user web.User) (err error)
|
||||
Update(ctx context.Context, s *dao.Stack, user web.User) (err error)
|
||||
}
|
||||
|
||||
func NewStack(d *docker.Docker, s dao.Interface, eb EventBiz) StackBiz {
|
||||
@ -32,20 +32,20 @@ type stackBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *stackBiz) Search(name, filter string) (stacks []*dao.Stack, err error) {
|
||||
func (b *stackBiz) Search(ctx context.Context, name, filter string) (stacks []*dao.Stack, err error) {
|
||||
var (
|
||||
activeStacks map[string][]string
|
||||
internalStacks []*dao.Stack
|
||||
)
|
||||
|
||||
// load real stacks
|
||||
activeStacks, err = b.d.StackList(context.TODO())
|
||||
activeStacks, err = b.d.StackList(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// load stack definitions
|
||||
internalStacks, err = b.s.StackGetAll(context.TODO())
|
||||
internalStacks, err = b.s.StackGetAll(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -70,8 +70,8 @@ func (b *stackBiz) Search(name, filter string) (stacks []*dao.Stack, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *stackBiz) Find(name string) (s *dao.Stack, err error) {
|
||||
s, err = b.s.StackGet(context.TODO(), name)
|
||||
func (b *stackBiz) Find(ctx context.Context, name string) (s *dao.Stack, err error) {
|
||||
s, err = b.s.StackGet(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if s == nil {
|
||||
@ -105,7 +105,7 @@ func (b *stackBiz) filter(stack *dao.Stack, name, filter string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *stackBiz) Create(s *dao.Stack, user web.User) (err error) {
|
||||
func (b *stackBiz) Create(ctx context.Context, s *dao.Stack, user web.User) (err error) {
|
||||
stack := &dao.Stack{
|
||||
Name: s.Name,
|
||||
Content: s.Content,
|
||||
@ -114,31 +114,31 @@ func (b *stackBiz) Create(s *dao.Stack, user web.User) (err error) {
|
||||
}
|
||||
stack.UpdatedAt = stack.CreatedAt
|
||||
stack.UpdatedBy = stack.CreatedBy
|
||||
err = b.s.StackCreate(context.TODO(), stack)
|
||||
err = b.s.StackCreate(ctx, stack)
|
||||
if err == nil {
|
||||
b.eb.CreateStack(EventActionCreate, stack.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *stackBiz) Update(s *dao.Stack, user web.User) (err error) {
|
||||
func (b *stackBiz) Update(ctx context.Context, s *dao.Stack, user web.User) (err error) {
|
||||
stack := &dao.Stack{
|
||||
Name: s.Name,
|
||||
Content: s.Content,
|
||||
UpdatedAt: now(),
|
||||
UpdatedBy: newOperator(user),
|
||||
}
|
||||
err = b.s.StackUpdate(context.TODO(), stack)
|
||||
err = b.s.StackUpdate(ctx, stack)
|
||||
if err == nil {
|
||||
b.eb.CreateStack(EventActionUpdate, stack.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *stackBiz) Delete(name string, user web.User) (err error) {
|
||||
err = b.d.StackRemove(context.TODO(), name)
|
||||
func (b *stackBiz) Delete(ctx context.Context, name string, user web.User) (err error) {
|
||||
err = b.d.StackRemove(ctx, name)
|
||||
if err == nil {
|
||||
err = b.s.StackDelete(context.TODO(), name)
|
||||
err = b.s.StackDelete(ctx, name)
|
||||
}
|
||||
if err == nil {
|
||||
b.eb.CreateStack(EventActionDelete, name, user)
|
||||
@ -146,16 +146,16 @@ func (b *stackBiz) Delete(name string, user web.User) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *stackBiz) Shutdown(name string, user web.User) (err error) {
|
||||
err = b.d.StackRemove(context.TODO(), name)
|
||||
func (b *stackBiz) Shutdown(ctx context.Context, name string, user web.User) (err error) {
|
||||
err = b.d.StackRemove(ctx, name)
|
||||
if err == nil {
|
||||
b.eb.CreateStack(EventActionShutdown, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *stackBiz) Deploy(name string, user web.User) (err error) {
|
||||
stack, err := b.s.StackGet(context.TODO(), name)
|
||||
func (b *stackBiz) Deploy(ctx context.Context, name string, user web.User) (err error) {
|
||||
stack, err := b.s.StackGet(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if stack == nil {
|
||||
@ -167,7 +167,7 @@ func (b *stackBiz) Deploy(name string, user web.User) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
registries, err := b.s.RegistryGetAll(context.TODO())
|
||||
registries, err := b.s.RegistryGetAll(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -184,7 +184,7 @@ func (b *stackBiz) Deploy(name string, user web.User) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
err = b.d.StackDeploy(context.TODO(), cfg, authes)
|
||||
err = b.d.StackDeploy(ctx, cfg, authes)
|
||||
if err == nil {
|
||||
b.eb.CreateStack(EventActionDeploy, name, user)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cuigh/auxo/app"
|
||||
"github.com/cuigh/auxo/data"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
@ -9,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type SystemBiz interface {
|
||||
Init() (err error)
|
||||
CheckState() (state *SystemState, err error)
|
||||
Init(ctx context.Context) (err error)
|
||||
CheckState(ctx context.Context) (state *SystemState, err error)
|
||||
}
|
||||
|
||||
func NewSystem(d dao.Interface, ub UserBiz, sb SettingBiz, s *misc.Setting) SystemBiz {
|
||||
@ -29,20 +31,20 @@ type systemBiz struct {
|
||||
sb SettingBiz
|
||||
}
|
||||
|
||||
func (b *systemBiz) Init() (err error) {
|
||||
func (b *systemBiz) Init(ctx context.Context) (err error) {
|
||||
if versions.LessThan(b.s.System.Version, app.Version) {
|
||||
// initialize database
|
||||
err = b.d.Init()
|
||||
err = b.d.Init(ctx)
|
||||
if err == nil {
|
||||
err = b.sb.Save("system", data.Map{"version": app.Version}, nil)
|
||||
err = b.sb.Save(ctx, "system", data.Map{"version": app.Version}, nil)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *systemBiz) CheckState() (state *SystemState, err error) {
|
||||
func (b *systemBiz) CheckState(ctx context.Context) (state *SystemState, err error) {
|
||||
var count int
|
||||
count, err = b.ub.Count()
|
||||
count, err = b.ub.Count(ctx)
|
||||
if err == nil {
|
||||
state = &SystemState{Fresh: count == 0}
|
||||
}
|
||||
|
20
biz/task.go
20
biz/task.go
@ -9,9 +9,9 @@ import (
|
||||
)
|
||||
|
||||
type TaskBiz interface {
|
||||
Search(node, service, mode string, pageIndex, pageSize int) (tasks []*Task, total int, err error)
|
||||
Find(id string) (task *Task, raw string, err error)
|
||||
FetchLogs(id string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
Search(ctx context.Context, node, service, mode string, pageIndex, pageSize int) (tasks []*Task, total int, err error)
|
||||
Find(ctx context.Context, id string) (task *Task, raw string, err error)
|
||||
FetchLogs(ctx context.Context, id string, lines int, timestamps bool) (stdout, stderr string, err error)
|
||||
}
|
||||
|
||||
func NewTask(d *docker.Docker) TaskBiz {
|
||||
@ -22,14 +22,14 @@ type taskBiz struct {
|
||||
d *docker.Docker
|
||||
}
|
||||
|
||||
func (b *taskBiz) Find(id string) (task *Task, raw string, err error) {
|
||||
func (b *taskBiz) Find(ctx context.Context, id string) (task *Task, raw string, err error) {
|
||||
var (
|
||||
t swarm.Task
|
||||
s swarm.Service
|
||||
r []byte
|
||||
)
|
||||
|
||||
t, r, err = b.d.TaskInspect(context.TODO(), id)
|
||||
t, r, err = b.d.TaskInspect(ctx, id)
|
||||
if err != nil {
|
||||
if docker.IsErrNotFound(err) {
|
||||
err = nil
|
||||
@ -43,7 +43,7 @@ func (b *taskBiz) Find(id string) (task *Task, raw string, err error) {
|
||||
task = newTask(&t, m)
|
||||
|
||||
// Fill service name
|
||||
if s, _, _ = b.d.ServiceInspect(context.TODO(), t.ServiceID, false); s.Spec.Name == "" {
|
||||
if s, _, _ = b.d.ServiceInspect(ctx, t.ServiceID, false); s.Spec.Name == "" {
|
||||
task.ServiceName = task.ServiceID
|
||||
} else {
|
||||
task.ServiceName = s.Spec.Name
|
||||
@ -52,9 +52,9 @@ func (b *taskBiz) Find(id string) (task *Task, raw string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *taskBiz) Search(node, service, state string, pageIndex, pageSize int) (tasks []*Task, total int, err error) {
|
||||
func (b *taskBiz) Search(ctx context.Context, node, service, state string, pageIndex, pageSize int) (tasks []*Task, total int, err error) {
|
||||
var list []swarm.Task
|
||||
list, total, err = b.d.TaskList(context.TODO(), node, service, state, pageIndex, pageSize)
|
||||
list, total, err = b.d.TaskList(ctx, node, service, state, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -72,8 +72,8 @@ func (b *taskBiz) Search(node, service, state string, pageIndex, pageSize int) (
|
||||
return
|
||||
}
|
||||
|
||||
func (b *taskBiz) FetchLogs(id string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.TaskLogs(context.TODO(), id, lines, timestamps)
|
||||
func (b *taskBiz) FetchLogs(ctx context.Context, id string, lines int, timestamps bool) (string, string, error) {
|
||||
stdout, stderr, err := b.d.TaskLogs(ctx, id, lines, timestamps)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
76
biz/user.go
76
biz/user.go
@ -26,18 +26,18 @@ const (
|
||||
)
|
||||
|
||||
type UserBiz interface {
|
||||
Search(name, loginName, filter string, pageIndex, pageSize int) (users []*dao.User, total int, err error)
|
||||
Create(user *dao.User, ctxUser web.User) (id string, err error)
|
||||
Update(user *dao.User, ctxUser web.User) (err error)
|
||||
FindByID(id string) (user *dao.User, err error)
|
||||
FindByName(loginName string) (user *dao.User, err error)
|
||||
FindByToken(token string) (user *dao.User, err error)
|
||||
FindPrivacy(loginName string) (privacy *UserPrivacy, err error)
|
||||
Count() (count int, err error)
|
||||
Delete(id, name string, user web.User) (err error)
|
||||
SetStatus(id string, status int32, user web.User) (err error)
|
||||
ModifyPassword(oldPwd, newPwd string, user web.User) (err error)
|
||||
ModifyProfile(user *dao.User, ctxUser web.User) (err error)
|
||||
Search(ctx context.Context, name, loginName, filter string, pageIndex, pageSize int) (users []*dao.User, total int, err error)
|
||||
Create(ctx context.Context, user *dao.User, ctxUser web.User) (id string, err error)
|
||||
Update(ctx context.Context, user *dao.User, ctxUser web.User) (err error)
|
||||
FindByID(ctx context.Context, id string) (user *dao.User, err error)
|
||||
FindByName(ctx context.Context, loginName string) (user *dao.User, err error)
|
||||
FindByToken(ctx context.Context, token string) (user *dao.User, err error)
|
||||
FindPrivacy(ctx context.Context, loginName string) (privacy *UserPrivacy, err error)
|
||||
Count(ctx context.Context) (count int, err error)
|
||||
Delete(ctx context.Context, id, name string, user web.User) (err error)
|
||||
SetStatus(ctx context.Context, id string, status int32, user web.User) (err error)
|
||||
ModifyPassword(ctx context.Context, oldPwd, newPwd string, user web.User) (err error)
|
||||
ModifyProfile(ctx context.Context, user *dao.User, ctxUser web.User) (err error)
|
||||
}
|
||||
|
||||
func NewUser(d dao.Interface, eb EventBiz) UserBiz {
|
||||
@ -49,7 +49,7 @@ type userBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *userBiz) Search(name, loginName, filter string, pageIndex, pageSize int) (users []*dao.User, total int, err error) {
|
||||
func (b *userBiz) Search(ctx context.Context, name, loginName, filter string, pageIndex, pageSize int) (users []*dao.User, total int, err error) {
|
||||
var args = &dao.UserSearchArgs{
|
||||
Name: name,
|
||||
LoginName: loginName,
|
||||
@ -67,24 +67,24 @@ func (b *userBiz) Search(name, loginName, filter string, pageIndex, pageSize int
|
||||
args.Status = UserStatusBlocked
|
||||
}
|
||||
|
||||
return b.d.UserSearch(context.TODO(), args)
|
||||
return b.d.UserSearch(ctx, args)
|
||||
}
|
||||
|
||||
func (b *userBiz) FindByID(id string) (user *dao.User, err error) {
|
||||
return b.d.UserGet(context.TODO(), id)
|
||||
func (b *userBiz) FindByID(ctx context.Context, id string) (user *dao.User, err error) {
|
||||
return b.d.UserGet(ctx, id)
|
||||
}
|
||||
|
||||
func (b *userBiz) FindByName(loginName string) (user *dao.User, err error) {
|
||||
return b.d.UserGetByName(context.TODO(), loginName)
|
||||
func (b *userBiz) FindByName(ctx context.Context, loginName string) (user *dao.User, err error) {
|
||||
return b.d.UserGetByName(ctx, loginName)
|
||||
}
|
||||
|
||||
func (b *userBiz) FindByToken(token string) (user *dao.User, err error) {
|
||||
return b.d.UserGetByToken(context.TODO(), token)
|
||||
func (b *userBiz) FindByToken(ctx context.Context, token string) (user *dao.User, err error) {
|
||||
return b.d.UserGetByToken(ctx, token)
|
||||
}
|
||||
|
||||
func (b *userBiz) FindPrivacy(loginName string) (privacy *UserPrivacy, err error) {
|
||||
func (b *userBiz) FindPrivacy(ctx context.Context, loginName string) (privacy *UserPrivacy, err error) {
|
||||
var u *dao.User
|
||||
u, err = b.d.UserGetByName(context.TODO(), loginName)
|
||||
u, err = b.d.UserGetByName(ctx, loginName)
|
||||
if u != nil {
|
||||
privacy = &UserPrivacy{
|
||||
ID: u.ID,
|
||||
@ -98,7 +98,7 @@ func (b *userBiz) FindPrivacy(loginName string) (privacy *UserPrivacy, err error
|
||||
return
|
||||
}
|
||||
|
||||
func (b *userBiz) Create(user *dao.User, ctxUser web.User) (id string, err error) {
|
||||
func (b *userBiz) Create(ctx context.Context, user *dao.User, ctxUser web.User) (id string, err error) {
|
||||
user.Tokens = data.Options{data.Option{Name: "test", Value: "abc123"}}
|
||||
user.ID = createId()
|
||||
user.Status = UserStatusActive
|
||||
@ -115,46 +115,46 @@ func (b *userBiz) Create(user *dao.User, ctxUser web.User) (id string, err error
|
||||
}
|
||||
}
|
||||
|
||||
if err = b.d.UserCreate(context.TODO(), user); err == nil && ctxUser != nil {
|
||||
if err = b.d.UserCreate(ctx, user); err == nil && ctxUser != nil {
|
||||
b.eb.CreateUser(EventActionCreate, user.LoginName, user.Name, ctxUser)
|
||||
}
|
||||
id = user.ID
|
||||
return
|
||||
}
|
||||
|
||||
func (b *userBiz) Update(user *dao.User, ctxUser web.User) (err error) {
|
||||
func (b *userBiz) Update(ctx context.Context, user *dao.User, ctxUser web.User) (err error) {
|
||||
user.UpdatedAt = now()
|
||||
user.UpdatedBy = newOperator(ctxUser)
|
||||
if err = b.d.UserUpdate(context.TODO(), user); err == nil {
|
||||
if err = b.d.UserUpdate(ctx, user); err == nil {
|
||||
go func() {
|
||||
_ = b.d.SessionUpdateDirty(context.TODO(), user.ID, "")
|
||||
_ = b.d.SessionUpdateDirty(ctx, user.ID, "")
|
||||
b.eb.CreateUser(EventActionUpdate, user.LoginName, user.Name, ctxUser)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *userBiz) SetStatus(id string, status int32, user web.User) (err error) {
|
||||
func (b *userBiz) SetStatus(ctx context.Context, id string, status int32, user web.User) (err error) {
|
||||
u := &dao.User{
|
||||
ID: id,
|
||||
Status: status,
|
||||
UpdatedAt: now(),
|
||||
UpdatedBy: newOperator(user),
|
||||
}
|
||||
return b.d.UserUpdateStatus(context.TODO(), u)
|
||||
return b.d.UserUpdateStatus(ctx, u)
|
||||
}
|
||||
|
||||
func (b *userBiz) Delete(id, name string, user web.User) (err error) {
|
||||
err = b.d.UserDelete(context.TODO(), id)
|
||||
func (b *userBiz) Delete(ctx context.Context, id, name string, user web.User) (err error) {
|
||||
err = b.d.UserDelete(ctx, id)
|
||||
if err == nil {
|
||||
b.eb.CreateUser(EventActionDelete, id, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *userBiz) ModifyPassword(oldPwd, newPwd string, user web.User) (err error) {
|
||||
func (b *userBiz) ModifyPassword(ctx context.Context, oldPwd, newPwd string, user web.User) (err error) {
|
||||
var u *dao.User
|
||||
u, err = b.d.UserGet(context.TODO(), user.ID())
|
||||
u, err = b.d.UserGet(ctx, user.ID())
|
||||
if err != nil {
|
||||
return err
|
||||
} else if u == nil {
|
||||
@ -171,18 +171,18 @@ func (b *userBiz) ModifyPassword(oldPwd, newPwd string, user web.User) (err erro
|
||||
|
||||
u.UpdatedAt = now()
|
||||
u.UpdatedBy = newOperator(user)
|
||||
return b.d.UserUpdatePassword(context.TODO(), u)
|
||||
return b.d.UserUpdatePassword(ctx, u)
|
||||
}
|
||||
|
||||
func (b *userBiz) ModifyProfile(u *dao.User, user web.User) (err error) {
|
||||
func (b *userBiz) ModifyProfile(ctx context.Context, u *dao.User, user web.User) (err error) {
|
||||
u.ID = user.ID()
|
||||
u.UpdatedAt = now()
|
||||
u.UpdatedBy = newOperator(user)
|
||||
return b.d.UserUpdateProfile(context.TODO(), u)
|
||||
return b.d.UserUpdateProfile(ctx, u)
|
||||
}
|
||||
|
||||
func (b *userBiz) Count() (count int, err error) {
|
||||
return b.d.UserCount(context.TODO())
|
||||
func (b *userBiz) Count(ctx context.Context) (count int, err error) {
|
||||
return b.d.UserCount(ctx)
|
||||
}
|
||||
|
||||
type UserPrivacy struct {
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type VolumeBiz interface {
|
||||
Search(node, name string, pageIndex, pageSize int) ([]*Volume, int, error)
|
||||
Find(node, name string) (volume *Volume, raw string, err error)
|
||||
Delete(node, name string, user web.User) (err error)
|
||||
Create(volume *Volume, user web.User) (err error)
|
||||
Prune(node string, user web.User) (count int, size uint64, err error)
|
||||
Search(ctx context.Context, node, name string, pageIndex, pageSize int) ([]*Volume, int, error)
|
||||
Find(ctx context.Context, node, name string) (volume *Volume, raw string, err error)
|
||||
Delete(ctx context.Context, node, name string, user web.User) (err error)
|
||||
Create(ctx context.Context, volume *Volume, user web.User) (err error)
|
||||
Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error)
|
||||
}
|
||||
|
||||
func NewVolume(d *docker.Docker, eb EventBiz) VolumeBiz {
|
||||
@ -28,13 +28,13 @@ type volumeBiz struct {
|
||||
eb EventBiz
|
||||
}
|
||||
|
||||
func (b *volumeBiz) Find(node, name string) (volume *Volume, raw string, err error) {
|
||||
func (b *volumeBiz) Find(ctx context.Context, node, name string) (volume *Volume, raw string, err error) {
|
||||
var (
|
||||
v types.Volume
|
||||
r []byte
|
||||
)
|
||||
|
||||
if v, r, err = b.d.VolumeInspect(context.TODO(), node, name); err == nil {
|
||||
if v, r, err = b.d.VolumeInspect(ctx, node, name); err == nil {
|
||||
raw, err = indentJSON(r)
|
||||
}
|
||||
|
||||
@ -44,8 +44,8 @@ func (b *volumeBiz) Find(node, name string) (volume *Volume, raw string, err err
|
||||
return
|
||||
}
|
||||
|
||||
func (b *volumeBiz) Search(node, name string, pageIndex, pageSize int) (volumes []*Volume, total int, err error) {
|
||||
list, total, err := b.d.VolumeList(context.TODO(), node, name, pageIndex, pageSize)
|
||||
func (b *volumeBiz) Search(ctx context.Context, node, name string, pageIndex, pageSize int) (volumes []*Volume, total int, err error) {
|
||||
list, total, err := b.d.VolumeList(ctx, node, name, pageIndex, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -57,15 +57,15 @@ func (b *volumeBiz) Search(node, name string, pageIndex, pageSize int) (volumes
|
||||
return volumes, total, nil
|
||||
}
|
||||
|
||||
func (b *volumeBiz) Delete(node, name string, user web.User) (err error) {
|
||||
err = b.d.VolumeRemove(context.TODO(), node, name)
|
||||
func (b *volumeBiz) Delete(ctx context.Context, node, name string, user web.User) (err error) {
|
||||
err = b.d.VolumeRemove(ctx, node, name)
|
||||
if err == nil {
|
||||
b.eb.CreateVolume(EventActionDelete, node, name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *volumeBiz) Create(vol *Volume, user web.User) (err error) {
|
||||
func (b *volumeBiz) Create(ctx context.Context, vol *Volume, user web.User) (err error) {
|
||||
options := &volume.VolumeCreateBody{
|
||||
Name: vol.Name,
|
||||
Driver: vol.Driver,
|
||||
@ -78,16 +78,16 @@ func (b *volumeBiz) Create(vol *Volume, user web.User) (err error) {
|
||||
options.Driver = vol.Driver
|
||||
}
|
||||
|
||||
err = b.d.VolumeCreate(context.TODO(), vol.Node, options)
|
||||
err = b.d.VolumeCreate(ctx, vol.Node, options)
|
||||
if err == nil {
|
||||
b.eb.CreateVolume(EventActionDelete, vol.Node, vol.Name, user)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *volumeBiz) Prune(node string, user web.User) (count int, size uint64, err error) {
|
||||
func (b *volumeBiz) Prune(ctx context.Context, node string, user web.User) (count int, size uint64, err error) {
|
||||
var report types.VolumesPruneReport
|
||||
report, err = b.d.VolumePrune(context.TODO(), node)
|
||||
report, err = b.d.VolumePrune(ctx, node)
|
||||
if err == nil {
|
||||
count, size = len(report.VolumesDeleted), report.SpaceReclaimed
|
||||
b.eb.CreateVolume(EventActionPrune, node, "", user)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@ -50,7 +51,7 @@ func New(addr string) (dao.Interface, error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (d *Dao) Init() error {
|
||||
func (d *Dao) Init(ctx context.Context) error {
|
||||
buckets := []string{"chart", "dashboard", "event", "registry", "role", "setting", "stack", "user" /*"perm","session","template"*/}
|
||||
return d.db.Update(func(tx *bolt.Tx) error {
|
||||
for _, bucket := range buckets {
|
||||
|
@ -20,7 +20,7 @@ func Register(name string, builder Builder) {
|
||||
|
||||
// Interface is the interface that wraps all dao methods.
|
||||
type Interface interface {
|
||||
Init() error
|
||||
Init(ctx context.Context) error
|
||||
|
||||
RoleGet(ctx context.Context, id string) (*Role, error)
|
||||
RoleSearch(ctx context.Context, name string) (roles []*Role, err error)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/cuigh/auxo/app"
|
||||
"github.com/cuigh/auxo/log"
|
||||
"github.com/cuigh/swirl/dao"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@ -79,7 +80,7 @@ func open(addr string) (*mongo.Database, error) {
|
||||
opts := &options.ClientOptions{}
|
||||
opts.ApplyURI(addr)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := misc.Context(10 * time.Second)
|
||||
defer cancel()
|
||||
|
||||
client, err := mongo.Connect(ctx, opts.SetAppName(app.Name))
|
||||
@ -89,10 +90,10 @@ func open(addr string) (*mongo.Database, error) {
|
||||
return client.Database(db), nil
|
||||
}
|
||||
|
||||
func (d *Dao) Init() (err error) {
|
||||
func (d *Dao) Init(ctx context.Context) (err error) {
|
||||
for name, models := range indexes {
|
||||
c := d.db.Collection(name)
|
||||
_, err = c.Indexes().CreateMany(context.TODO(), models)
|
||||
_, err = c.Indexes().CreateMany(ctx, models)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -138,7 +139,7 @@ func (d *Dao) search(ctx context.Context, coll string, opts searchOptions, recor
|
||||
if opts.sorter != nil {
|
||||
findOpts.SetSort(opts.sorter)
|
||||
}
|
||||
cur, err = c.Find(context.TODO(), opts.filter, findOpts)
|
||||
cur, err = c.Find(ctx, opts.filter, findOpts)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -121,12 +121,15 @@ func (d *Docker) loadCache() (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agents, err := d.loadAgents(context.TODO(), c)
|
||||
ctx, cancel := misc.Context(time.Minute)
|
||||
defer cancel()
|
||||
|
||||
agents, err := d.loadAgents(ctx, c)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load agents")
|
||||
}
|
||||
|
||||
nodes, err := d.loadNodes(context.TODO(), c)
|
||||
nodes, err := d.loadNodes(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ func (d *Docker) ServiceRollback(ctx context.Context, name string) error {
|
||||
options := types.ServiceUpdateOptions{
|
||||
Rollback: "previous",
|
||||
}
|
||||
resp, err := c.ServiceUpdate(context.Background(), name, service.Version, service.Spec, options)
|
||||
resp, err := c.ServiceUpdate(ctx, name, service.Version, service.Spec, options)
|
||||
if err == nil && len(resp.Warnings) > 0 {
|
||||
d.logger.Warnf("service '%s' was rollbacked but got warnings: %v", name, resp.Warnings)
|
||||
}
|
||||
@ -151,7 +151,7 @@ func (d *Docker) ServiceRestart(ctx context.Context, name string) error {
|
||||
}
|
||||
|
||||
service.Spec.TaskTemplate.ForceUpdate++
|
||||
resp, err := c.ServiceUpdate(context.Background(), name, service.Version, service.Spec, types.ServiceUpdateOptions{})
|
||||
resp, err := c.ServiceUpdate(ctx, name, service.Version, service.Spec, types.ServiceUpdateOptions{})
|
||||
if err == nil && len(resp.Warnings) > 0 {
|
||||
d.logger.Warnf("service '%s' was restarted but got warnings: %v", name, resp.Warnings)
|
||||
}
|
||||
@ -180,7 +180,7 @@ func (d *Docker) ServiceScale(ctx context.Context, name string, count, version u
|
||||
if version > 0 {
|
||||
ver = swarm.Version{Index: version}
|
||||
}
|
||||
resp, err := c.ServiceUpdate(context.Background(), name, ver, spec, types.ServiceUpdateOptions{})
|
||||
resp, err := c.ServiceUpdate(ctx, name, ver, spec, types.ServiceUpdateOptions{})
|
||||
if err == nil && len(resp.Warnings) > 0 {
|
||||
d.logger.Warnf("service %s was scaled but got warnings: %v", name, resp.Warnings)
|
||||
}
|
||||
|
12
main.go
12
main.go
@ -6,6 +6,7 @@ import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cuigh/auxo/app"
|
||||
"github.com/cuigh/auxo/app/container"
|
||||
@ -98,7 +99,10 @@ func findFilters(names ...string) []web.Filter {
|
||||
|
||||
func initSystem() error {
|
||||
return container.Call(func(b biz.SystemBiz) error {
|
||||
return b.Init()
|
||||
ctx, cancel := misc.Context(time.Minute)
|
||||
defer cancel()
|
||||
|
||||
return b.Init(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,7 +113,11 @@ func loadSetting(sb biz.SettingBiz) *misc.Setting {
|
||||
b []byte
|
||||
s = &misc.Setting{}
|
||||
)
|
||||
if opts, err = sb.Load(); err == nil {
|
||||
|
||||
ctx, cancel := misc.Context(30 * time.Second)
|
||||
defer cancel()
|
||||
|
||||
if opts, err = sb.Load(ctx); err == nil {
|
||||
if b, err = json.Marshal(opts); err == nil {
|
||||
err = json.Unmarshal(b, s)
|
||||
}
|
||||
|
11
misc/misc.go
11
misc/misc.go
@ -1,6 +1,11 @@
|
||||
package misc
|
||||
|
||||
import "github.com/cuigh/auxo/errors"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cuigh/auxo/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrInvalidToken = 1001
|
||||
@ -24,3 +29,7 @@ func Page(count, pageIndex, pageSize int) (start, end int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Context(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
return context.WithTimeout(context.Background(), timeout)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package scaler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -14,6 +13,7 @@ import (
|
||||
"github.com/cuigh/auxo/util/run"
|
||||
"github.com/cuigh/swirl/biz"
|
||||
"github.com/cuigh/swirl/docker"
|
||||
"github.com/cuigh/swirl/misc"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
)
|
||||
@ -60,10 +60,13 @@ func (s *Scaler) Start() {
|
||||
}
|
||||
|
||||
run.Schedule(time.Minute, func() {
|
||||
ctx, cancel := misc.Context(time.Minute)
|
||||
defer cancel()
|
||||
|
||||
args := filters.NewArgs()
|
||||
args.Add("mode", "replicated")
|
||||
args.Add("label", labelScale)
|
||||
services, err := s.d.ServiceSearch(context.TODO(), args)
|
||||
services, err := s.d.ServiceSearch(ctx, args)
|
||||
if err != nil {
|
||||
log.Get("scaler").Error("scaler > Failed to search service: ", err)
|
||||
return
|
||||
@ -91,8 +94,8 @@ func (s *Scaler) tryScale(service *swarm.Service, opts data.Options) {
|
||||
window = 3 * time.Minute
|
||||
policy = policyAny
|
||||
args data.Options
|
||||
ctx = context.TODO()
|
||||
)
|
||||
|
||||
for _, opt := range opts {
|
||||
switch opt.Name {
|
||||
case "min":
|
||||
@ -120,6 +123,9 @@ func (s *Scaler) tryScale(service *swarm.Service, opts data.Options) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := misc.Context(time.Minute)
|
||||
defer cancel()
|
||||
|
||||
logger := log.Get("scaler")
|
||||
replicas := *service.Spec.Mode.Replicated.Replicas
|
||||
if result.Type == scaleUp {
|
||||
@ -203,8 +209,11 @@ type cpuChecker struct {
|
||||
}
|
||||
|
||||
func (c *cpuChecker) Check(service string, low, high float64) (scaleType, float64) {
|
||||
ctx, cancel := misc.Context(time.Minute)
|
||||
defer cancel()
|
||||
|
||||
query := fmt.Sprintf(`avg(rate(container_cpu_user_seconds_total{container_label_com_docker_swarm_service_name="%s"}[1m]) * 100)`, service)
|
||||
vector, err := c.mb.GetVector(query, "", time.Now())
|
||||
vector, err := c.mb.GetVector(ctx, query, "", time.Now())
|
||||
if err != nil {
|
||||
log.Get("scaler").Error("scaler > Failed to query metrics: ", err)
|
||||
return scaleNone, 0
|
||||
|
@ -1,6 +1,7 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -54,18 +55,18 @@ func (c *Identifier) Apply(next web.HandlerFunc) web.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Identifier) Identify(loginName, password string) (identify Identity, err error) {
|
||||
func (c *Identifier) Identify(ctx context.Context, loginName, password string) (identify Identity, err error) {
|
||||
var (
|
||||
u security.User
|
||||
s *dao.Session
|
||||
)
|
||||
|
||||
u, err = c.signIn(loginName, password)
|
||||
u, err = c.signIn(ctx, loginName, password)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
s, err = c.createSession(u)
|
||||
s, err = c.createSession(ctx, u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -78,8 +79,8 @@ func (c *Identifier) Identify(loginName, password string) (identify Identity, er
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Identifier) signIn(loginName, password string) (user security.User, err error) {
|
||||
privacy, err := c.ub.FindPrivacy(loginName)
|
||||
func (c *Identifier) signIn(ctx context.Context, loginName, password string) (user security.User, err error) {
|
||||
privacy, err := c.ub.FindPrivacy(ctx, loginName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -89,7 +90,7 @@ func (c *Identifier) signIn(loginName, password string) (user security.User, err
|
||||
}
|
||||
|
||||
for _, login := range c.realms {
|
||||
user, err = login(privacy, loginName, password)
|
||||
user, err = login(ctx, privacy, loginName, password)
|
||||
if user != nil && err == nil {
|
||||
return
|
||||
}
|
||||
@ -111,7 +112,10 @@ func (c *Identifier) extractToken(ctx web.Context) (token string) {
|
||||
}
|
||||
|
||||
func (c *Identifier) identifyBySession(token string) web.User {
|
||||
session, err := c.sb.Find(token)
|
||||
ctx, cancel := misc.Context(30 * time.Second)
|
||||
defer cancel()
|
||||
|
||||
session, err := c.sb.Find(ctx, token)
|
||||
if err != nil {
|
||||
c.logger.Error("failed to find session: ", err)
|
||||
return nil
|
||||
@ -120,19 +124,22 @@ func (c *Identifier) identifyBySession(token string) web.User {
|
||||
}
|
||||
|
||||
if session.Dirty {
|
||||
if err = c.updateSession(session); err != nil {
|
||||
if err = c.updateSession(ctx, session); err != nil {
|
||||
c.logger.Error("failed to refresh session: ", err)
|
||||
return nil
|
||||
}
|
||||
} else if time.Now().Add(time.Minute * 5).After(session.Expiry) {
|
||||
c.renewSession(session)
|
||||
c.renewSession(ctx, session)
|
||||
}
|
||||
|
||||
return c.createUser(session)
|
||||
}
|
||||
|
||||
func (c *Identifier) identifyByToken(token string) web.User {
|
||||
u, err := c.ub.FindByToken(token)
|
||||
ctx, cancel := misc.Context(30 * time.Second)
|
||||
defer cancel()
|
||||
|
||||
u, err := c.ub.FindByToken(ctx, token)
|
||||
if err != nil {
|
||||
c.logger.Errorf("failed to find user by token '%s': %s", token, err)
|
||||
return nil
|
||||
@ -140,7 +147,7 @@ func (c *Identifier) identifyByToken(token string) web.User {
|
||||
return nil
|
||||
}
|
||||
|
||||
perms, err := c.rb.GetPerms(u.Roles)
|
||||
perms, err := c.rb.GetPerms(ctx, u.Roles)
|
||||
if err != nil {
|
||||
c.logger.Error("failed to load perms: ", err)
|
||||
return nil
|
||||
@ -165,7 +172,7 @@ func (c *Identifier) createUser(s *dao.Session) web.User {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Identifier) createSession(user security.User) (s *dao.Session, err error) {
|
||||
func (c *Identifier) createSession(ctx context.Context, user security.User) (s *dao.Session, err error) {
|
||||
s = &dao.Session{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UserID: user.ID(),
|
||||
@ -173,21 +180,21 @@ func (c *Identifier) createSession(user security.User) (s *dao.Session, err erro
|
||||
Expiry: time.Now().Add(misc.Options.TokenExpiry),
|
||||
}
|
||||
s.MaxExpiry = s.Expiry.Add(24 * time.Hour)
|
||||
if err = c.fillSession(s); err == nil {
|
||||
err = c.sb.Create(s)
|
||||
if err = c.fillSession(ctx, s); err == nil {
|
||||
err = c.sb.Create(ctx, s)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Identifier) updateSession(s *dao.Session) (err error) {
|
||||
if err = c.fillSession(s); err == nil {
|
||||
err = c.sb.Update(s)
|
||||
func (c *Identifier) updateSession(ctx context.Context, s *dao.Session) (err error) {
|
||||
if err = c.fillSession(ctx, s); err == nil {
|
||||
err = c.sb.Update(ctx, s)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Identifier) fillSession(s *dao.Session) (err error) {
|
||||
u, err := c.ub.FindByID(s.UserID)
|
||||
func (c *Identifier) fillSession(ctx context.Context, s *dao.Session) (err error) {
|
||||
u, err := c.ub.FindByID(ctx, s.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if u == nil {
|
||||
@ -197,7 +204,7 @@ func (c *Identifier) fillSession(s *dao.Session) (err error) {
|
||||
if u.Admin {
|
||||
s.Perms = []string{"*"}
|
||||
} else {
|
||||
s.Perms, err = c.rb.GetPerms(u.Roles)
|
||||
s.Perms, err = c.rb.GetPerms(ctx, u.Roles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -210,12 +217,12 @@ func (c *Identifier) fillSession(s *dao.Session) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Identifier) renewSession(s *dao.Session) {
|
||||
func (c *Identifier) renewSession(ctx context.Context, s *dao.Session) {
|
||||
expiry := time.Now().Add(misc.Options.TokenExpiry)
|
||||
if expiry.After(s.MaxExpiry) {
|
||||
expiry = s.MaxExpiry
|
||||
}
|
||||
err := c.sb.UpdateExpiry(s.ID, expiry)
|
||||
err := c.sb.UpdateExpiry(ctx, s.ID, expiry)
|
||||
if err != nil {
|
||||
c.logger.Errorf("failed to renew token '%s': %s", s.ID, err)
|
||||
}
|
||||
@ -235,10 +242,10 @@ func queryExtractor(ctx web.Context) (token string) {
|
||||
return ctx.Query("token")
|
||||
}
|
||||
|
||||
type RealmFunc func(u *biz.UserPrivacy, loginName, password string) (security.User, error)
|
||||
type RealmFunc func(ctx context.Context, u *biz.UserPrivacy, loginName, password string) (security.User, error)
|
||||
|
||||
func internalRealm() RealmFunc {
|
||||
return func(u *biz.UserPrivacy, loginName, password string) (security.User, error) {
|
||||
return func(ctx context.Context, u *biz.UserPrivacy, loginName, password string) (security.User, error) {
|
||||
if u == nil || u.Type != biz.UserTypeInternal {
|
||||
return nil, nil
|
||||
}
|
||||
@ -267,7 +274,7 @@ func ldapRealm(s *misc.Setting, ub biz.UserBiz) RealmFunc {
|
||||
r = ldap.New(s.LDAP.Address, s.LDAP.BaseDN, s.LDAP.UserDN, opts...)
|
||||
}
|
||||
|
||||
return func(u *biz.UserPrivacy, loginName, password string) (security.User, error) {
|
||||
return func(ctx context.Context, u *biz.UserPrivacy, loginName, password string) (security.User, error) {
|
||||
if r == nil || (u != nil && u.Type != biz.UserTypeLDAP) {
|
||||
return nil, nil
|
||||
}
|
||||
@ -282,7 +289,7 @@ func ldapRealm(s *misc.Setting, ub biz.UserBiz) RealmFunc {
|
||||
lu = user.(*ldap.User)
|
||||
)
|
||||
if u == nil {
|
||||
id, err = ub.Create(&dao.User{
|
||||
id, err = ub.Create(ctx, &dao.User{
|
||||
Type: biz.UserTypeLDAP,
|
||||
LoginName: loginName,
|
||||
Name: lu.Name(),
|
||||
|
@ -19,7 +19,7 @@ class Ajax {
|
||||
constructor() {
|
||||
this.ajax = axios.create({
|
||||
baseURL: import.meta.env.MODE === 'development' ? '/api' : '/api',
|
||||
timeout: 10000,
|
||||
timeout: 30000,
|
||||
// withCredentials: true,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user