diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b0247a..661c987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * feat: Refactor UI with vue3. * feat: Add support to agent. Swirl can connect to any container even in swarm mode now. +* feat: Support token authentication. * feat: Switch to official MongoDB driver. * feat: Allow set chart margins. * fix: Some args are incorrect when generating service command line. diff --git a/README.md b/README.md index 3f2296f..641b8c2 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ web: swirl: db_type: mongo db_address: mongodb://localhost:27017/swirl -# token_key: 80fe9a6d5c6d5dd39f27cd37a77faf8a # token_expiry: 30m # docker_api_version: '1.41' # docker_endpoint: tcp://docker-proxy:2375 diff --git a/api/container.go b/api/container.go index aed1a79..cca79ac 100644 --- a/api/container.go +++ b/api/container.go @@ -8,7 +8,6 @@ import ( "github.com/cuigh/auxo/log" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" - "github.com/cuigh/swirl/docker" "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" ) @@ -72,10 +71,9 @@ func containerFind(b biz.ContainerBiz) web.HandlerFunc { id := ctx.Query("id") container, raw, err := b.Find(node, id) if err != nil { - if docker.IsErrNotFound(err) { - return web.NewError(http.StatusNotFound, err.Error()) - } return err + } else if container == nil { + return web.NewError(http.StatusNotFound) } return success(ctx, data.Map{"container": container, "raw": raw}) } @@ -127,9 +125,11 @@ func containerConnect(b biz.ContainerBiz) web.HandlerFunc { cmd = ctx.Query("cmd") ) - _, _, err := b.Find(node, id) + container, _, err := b.Find(node, id) if err != nil { return err + } else if container == nil { + return web.NewError(http.StatusNotFound) } conn, _, _, err := ws.UpgradeHTTP(ctx.Request(), ctx.Response()) diff --git a/api/service.go b/api/service.go index 7f2347e..cef7bcc 100644 --- a/api/service.go +++ b/api/service.go @@ -6,7 +6,6 @@ import ( "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" - "github.com/cuigh/swirl/docker" ) // ServiceHandler encapsulates service related handlers. @@ -73,10 +72,9 @@ func serviceFind(b biz.ServiceBiz) web.HandlerFunc { status := ctx.Query("status") == "true" service, raw, err := b.Find(name, status) if err != nil { - if docker.IsErrNotFound(err) { - return web.NewError(http.StatusNotFound, err.Error()) - } return err + } else if service == nil { + return web.NewError(http.StatusNotFound) } return success(ctx, data.Map{"service": service, "raw": raw}) } @@ -153,6 +151,7 @@ func serviceSave(b biz.ServiceBiz) web.HandlerFunc { func serviceDeploy(b biz.ServiceBiz) web.HandlerFunc { return func(ctx web.Context) error { + //mode := ctx.Query("mode") // update/replace service := &biz.Service{} err := ctx.Bind(service, true) if err != nil { diff --git a/api/task.go b/api/task.go index e5cace5..8b54c52 100644 --- a/api/task.go +++ b/api/task.go @@ -6,7 +6,6 @@ import ( "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" - "github.com/cuigh/swirl/docker" ) // TaskHandler encapsulates node related handlers. @@ -60,10 +59,9 @@ func taskFind(b biz.TaskBiz) web.HandlerFunc { id := ctx.Query("id") task, raw, err := b.Find(id) if err != nil { - if docker.IsErrNotFound(err) { - return web.NewError(http.StatusNotFound, err.Error()) - } return err + } else if task == nil { + return web.NewError(http.StatusNotFound) } return success(ctx, data.Map{"task": task, "raw": raw}) } diff --git a/biz/container.go b/biz/container.go index 8b9c8d2..dbe2634 100644 --- a/biz/container.go +++ b/biz/container.go @@ -37,11 +37,15 @@ func (b *containerBiz) Find(node, id string) (c *Container, raw string, err erro r []byte ) - if cj, r, err = b.d.ContainerInspect(context.TODO(), node, id); err == nil { - raw, err = indentJSON(r) + cj, r, err = b.d.ContainerInspect(context.TODO(), node, id) + if err != nil { + if docker.IsErrNotFound(err) { + err = nil + } + return } - if err == nil { + if raw, err = indentJSON(r); err == nil { c = newContainerDetail(&cj) } return diff --git a/biz/service.go b/biz/service.go index 7ece3fe..3557600 100644 --- a/biz/service.go +++ b/biz/service.go @@ -50,7 +50,15 @@ func (b *serviceBiz) Find(name string, status bool) (service *Service, raw strin s swarm.Service r []byte ) + s, r, err = b.d.ServiceInspect(context.TODO(), name, status) + if err != nil { + if docker.IsErrNotFound(err) { + err = nil + } + return + } + if err == nil { raw, err = indentJSON(r) } diff --git a/biz/task.go b/biz/task.go index 56360f7..a5919c4 100644 --- a/biz/task.go +++ b/biz/task.go @@ -30,10 +30,14 @@ func (b *taskBiz) Find(id string) (task *Task, raw string, err error) { ) t, r, err = b.d.TaskInspect(context.TODO(), id) - if err == nil { - raw, err = indentJSON(r) + if err != nil { + if docker.IsErrNotFound(err) { + err = nil + } + return } + raw, err = indentJSON(r) if err == nil { m, _ := b.d.NodeMap() task = newTask(&t, m)