From a958d7de24056274800a834a460c840396625fe3 Mon Sep 17 00:00:00 2001 From: cuigh Date: Wed, 8 Nov 2017 18:36:13 +0800 Subject: [PATCH] Update auxo to latest version --- biz/biz.go | 2 +- biz/docker/stack.go | 16 ++++++++-------- biz/docker/task.go | 7 +++++-- biz/user.go | 4 ++-- config/app.yml | 20 ++++++++++---------- controller/common.go | 17 +++++++++-------- controller/config.go | 6 +++--- controller/container.go | 14 +++++++------- controller/event.go | 2 +- controller/home.go | 8 ++++---- controller/image.go | 8 ++++---- controller/network.go | 6 +++--- controller/node.go | 8 ++++---- controller/profile.go | 2 +- controller/registry.go | 2 +- controller/role.go | 8 ++++---- controller/secret.go | 6 +++--- controller/service.go | 30 +++++++++++++++--------------- controller/setting.go | 2 +- controller/stack.go | 10 +++++----- controller/task.go | 8 ++++---- controller/template.go | 22 ++++++++++++---------- controller/user.go | 12 ++++++------ controller/volume.go | 8 ++++---- main.go | 21 ++++++++++++--------- misc/util.go | 9 --------- model/auth.go | 8 ++++---- model/docker.go | 22 +++++++++++----------- model/event.go | 15 ++++++--------- model/service.go | 12 ++++++------ views/_layouts/default.jet | 12 ++++++------ views/_layouts/empty.jet | 10 +++++----- views/container/raw.jet | 4 ++-- views/image/raw.jet | 4 ++-- views/network/raw.jet | 4 ++-- views/node/raw.jet | 4 ++-- views/service/raw.jet | 4 ++-- views/stack/archive/detail.jet | 4 ++-- views/stack/archive/edit.jet | 6 +++--- views/stack/archive/new.jet | 6 +++--- views/task/raw.jet | 4 ++-- views/volume/raw.jet | 4 ++-- 42 files changed, 189 insertions(+), 192 deletions(-) diff --git a/biz/biz.go b/biz/biz.go index d23fc1b..aef9d0f 100644 --- a/biz/biz.go +++ b/biz/biz.go @@ -8,7 +8,7 @@ import ( func do(fn func(d dao.Interface)) { d, err := dao.Get() if err != nil { - panic(errors.Wrap("failed to load storage engine", err)) + panic(errors.Wrap(err, "failed to load storage engine")) } fn(d) diff --git a/biz/docker/stack.go b/biz/docker/stack.go index 80d206a..678898c 100644 --- a/biz/docker/stack.go +++ b/biz/docker/stack.go @@ -165,7 +165,7 @@ func StackRemove(name string) error { } if len(errs) > 0 { - return errors.Multi(errs...) + return errors.List(errs...) } return nil }) @@ -264,7 +264,7 @@ func createNetworks(ctx context.Context, cli *client.Client, namespace compose.N mgr.Logger().Infof("Creating network %s", name) if _, err = cli.NetworkCreate(ctx, name, createOpts); err != nil { - return errors.Wrap("failed to create network "+internalName, err) + return errors.Wrap(err, "failed to create network "+internalName) } } return nil @@ -277,12 +277,12 @@ func createSecrets(ctx context.Context, cli *client.Client, secrets []swarm.Secr case err == nil: // secret already exists, then we update that if err = cli.SecretUpdate(ctx, secret.ID, secret.Meta.Version, secretSpec); err != nil { - return errors.Wrap("failed to update secret "+secretSpec.Name, err) + return errors.Wrap(err, "failed to update secret "+secretSpec.Name) } case client.IsErrSecretNotFound(err): // secret does not exist, then we create a new one. if _, err = cli.SecretCreate(ctx, secretSpec); err != nil { - return errors.Wrap("failed to create secret "+secretSpec.Name, err) + return errors.Wrap(err, "failed to create secret "+secretSpec.Name) } default: return err @@ -298,12 +298,12 @@ func createConfigs(ctx context.Context, cli *client.Client, configs []swarm.Conf case err == nil: // config already exists, then we update that if err = cli.ConfigUpdate(ctx, config.ID, config.Meta.Version, configSpec); err != nil { - errors.Wrap("failed to update config "+configSpec.Name, err) + errors.Wrap(err, "failed to update config "+configSpec.Name) } case client.IsErrConfigNotFound(err): // config does not exist, then we create a new one. if _, err = cli.ConfigCreate(ctx, configSpec); err != nil { - errors.Wrap("failed to create config "+configSpec.Name, err) + errors.Wrap(err, "failed to create config "+configSpec.Name) } default: return err @@ -377,7 +377,7 @@ func deployServices( updateOpts, ) if err != nil { - return errors.Wrap("failed to update service "+name, err) + return errors.Wrap(err, "failed to update service "+name) } for _, warning := range response.Warnings { @@ -394,7 +394,7 @@ func deployServices( //} if _, err = cli.ServiceCreate(ctx, serviceSpec, createOpts); err != nil { - return errors.Wrap("failed to create service "+name, err) + return errors.Wrap(err, "failed to create service "+name) } } } diff --git a/biz/docker/task.go b/biz/docker/task.go index 44c4ef3..edc9794 100644 --- a/biz/docker/task.go +++ b/biz/docker/task.go @@ -6,7 +6,6 @@ import ( "math" "sort" - "github.com/cuigh/auxo/util/choose" "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" "github.com/docker/docker/api/types" @@ -57,7 +56,11 @@ func TaskList(args *model.TaskListArgs) (infos []*model.TaskInfo, totalCount int for _, t := range tasks { if _, ok := nodes[t.NodeID]; !ok { if n, _, e := cli.NodeInspectWithRaw(ctx, t.NodeID); e == nil { - nodes[t.NodeID] = choose.String(n.Spec.Name == "", n.Description.Hostname, n.Spec.Name) + if n.Spec.Name == "" { + nodes[t.NodeID] = n.Description.Hostname + } else { + nodes[t.NodeID] = n.Spec.Name + } } else { nodes[t.NodeID] = "" } diff --git a/biz/user.go b/biz/user.go index 64fd802..b7ce0de 100644 --- a/biz/user.go +++ b/biz/user.go @@ -288,9 +288,9 @@ func (b *userBiz) Identify(token string) (user web.User) { } // Authorize check permission of user -func (b *userBiz) Authorize(user web.User, handler string) bool { +func (b *userBiz) Authorize(user web.User, h web.HandlerInfo) bool { if au, ok := user.(*model.AuthUser); ok { - return au.IsAllowed(handler) + return au.IsAllowed(h.Name()) } return false } diff --git a/config/app.yml b/config/app.yml index c5c858a..bca1134 100644 --- a/config/app.yml +++ b/config/app.yml @@ -1,20 +1,20 @@ name: swirl +banner: false web: address: ':8001' - authorize_mode: '*' + authorize: '?' swirl: db_type: mongo db_address: localhost:27017/swirl # docker_endpoint: tcp://docker-proxy:2375 -#log: -# loggers: -# - level: info -# writers: console -# writers: -# - name: console -# type: console -# format: json -# layout: '[{L}]{T}: {M} - {F:S}{N}' \ No newline at end of file +log: + loggers: + - level: info + writers: console + writers: + - name: console + type: console + layout: '[{L}]{T}: {M}{N}' \ No newline at end of file diff --git a/controller/common.go b/controller/common.go index a7a2f2c..28470d5 100644 --- a/controller/common.go +++ b/controller/common.go @@ -1,19 +1,20 @@ package controller import ( + "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/model" ) -func newModel(ctx web.Context) web.Map { - return web.Map{ +func newModel(ctx web.Context) data.Map { + return data.Map{ "ContextUser": ctx.User(), } } -func newPagerModel(ctx web.Context, totalCount, size, page int) web.Map { +func newPagerModel(ctx web.Context, totalCount, size, page int) data.Map { pager := model.NewPager(ctx.Request().RequestURI, totalCount, size, page) - return newModel(ctx).Add("Pager", pager) + return newModel(ctx).Set("Pager", pager) } func ajaxResult(ctx web.Context, err error) error { @@ -21,14 +22,14 @@ func ajaxResult(ctx web.Context, err error) error { return err } - return ctx.JSON(web.Map{ + return ctx.JSON(data.Map{ "success": err == nil, }) } -func ajaxSuccess(ctx web.Context, data interface{}) error { - return ctx.JSON(web.Map{ +func ajaxSuccess(ctx web.Context, value interface{}) error { + return ctx.JSON(data.Map{ "success": true, - "data": data, + "data": value, }) } diff --git a/controller/config.go b/controller/config.go index c43ef33..159407f 100644 --- a/controller/config.go +++ b/controller/config.go @@ -41,8 +41,8 @@ func configList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, page). - Add("Name", name). - Add("Configs", configs) + Set("Name", name). + Set("Configs", configs) return ctx.Render("config/list", m) } @@ -75,7 +75,7 @@ func configEdit(ctx web.Context) error { if err != nil { return err } - m := newModel(ctx).Add("Config", cfg) + m := newModel(ctx).Set("Config", cfg) return ctx.Render("config/edit", m) } diff --git a/controller/container.go b/controller/container.go index c035f9f..2c59e75 100644 --- a/controller/container.go +++ b/controller/container.go @@ -47,9 +47,9 @@ func containerList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, args.PageIndex). - Add("Name", args.Name). - Add("Filter", args.Filter). - Add("Containers", containers) + Set("Name", args.Name). + Set("Filter", args.Filter). + Set("Containers", containers) return ctx.Render("container/list", m) } @@ -60,7 +60,7 @@ func containerDetail(ctx web.Context) error { return err } - m := newModel(ctx).Add("Container", container) + m := newModel(ctx).Set("Container", container) return ctx.Render("container/detail", m) } @@ -76,7 +76,7 @@ func containerRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Container", container).Add("Raw", j) + m := newModel(ctx).Set("Container", container).Set("Raw", j) return ctx.Render("container/raw", m) } @@ -94,8 +94,8 @@ func containerLogs(ctx web.Context) error { return err } - m := newModel(ctx).Add("Container", container).Add("Line", line).Add("Timestamps", timestamps). - Add("Stdout", stdout.String()).Add("Stderr", stderr.String()) + m := newModel(ctx).Set("Container", container).Set("Line", line).Set("Timestamps", timestamps). + Set("Stdout", stdout.String()).Set("Stderr", stderr.String()) return ctx.Render("container/logs", m) } diff --git a/controller/event.go b/controller/event.go index fd0003c..1f3d7e8 100644 --- a/controller/event.go +++ b/controller/event.go @@ -35,6 +35,6 @@ func eventList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, args.PageIndex). - Add("Events", events).Add("Args", args) + Set("Events", events).Set("Args", args) return ctx.Render("system/event/list", m) } diff --git a/controller/home.go b/controller/home.go index 543192f..6d2af19 100644 --- a/controller/home.go +++ b/controller/home.go @@ -39,22 +39,22 @@ func homeIndex(ctx web.Context) (err error) { if count, err = docker.NodeCount(); err != nil { return } - m.Add("NodeCount", count) + m.Set("NodeCount", count) if count, err = docker.NetworkCount(); err != nil { return } - m.Add("NetworkCount", count) + m.Set("NetworkCount", count) if count, err = docker.ServiceCount(); err != nil { return } - m.Add("ServiceCount", count) + m.Set("ServiceCount", count) if count, err = docker.StackCount(); err != nil { return } - m.Add("StackCount", count) + m.Set("StackCount", count) return ctx.Render("index", m) } diff --git a/controller/image.go b/controller/image.go index 5a71db5..e22633f 100644 --- a/controller/image.go +++ b/controller/image.go @@ -37,8 +37,8 @@ func imageList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, page). - Add("Name", name). - Add("Images", images) + Set("Name", name). + Set("Images", images) return ctx.Render("image/list", m) } @@ -54,7 +54,7 @@ func imageDetail(ctx web.Context) error { return err } - m := newModel(ctx).Add("Image", image).Add("Histories", histories) + m := newModel(ctx).Set("Image", image).Set("Histories", histories) return ctx.Render("image/detail", m) } @@ -70,7 +70,7 @@ func imageRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Image", image).Add("Raw", j) + m := newModel(ctx).Set("Image", image).Set("Raw", j) return ctx.Render("image/raw", m) } diff --git a/controller/network.go b/controller/network.go index e24c062..663f205 100644 --- a/controller/network.go +++ b/controller/network.go @@ -38,7 +38,7 @@ func networkList(ctx web.Context) error { return err } - m := newModel(ctx).Add("Networks", networks) + m := newModel(ctx).Set("Networks", networks) return ctx.Render("network/list", m) } @@ -85,7 +85,7 @@ func networkDetail(ctx web.Context) error { if err != nil { return err } - m := newModel(ctx).Add("Network", network) + m := newModel(ctx).Set("Network", network) return ctx.Render("network/detail", m) } @@ -101,6 +101,6 @@ func networkRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Network", name).Add("Raw", j) + m := newModel(ctx).Set("Network", name).Set("Raw", j) return ctx.Render("network/raw", m) } diff --git a/controller/node.go b/controller/node.go index 403e4f3..6f2999d 100644 --- a/controller/node.go +++ b/controller/node.go @@ -35,7 +35,7 @@ func nodeList(ctx web.Context) error { return err } - m := newModel(ctx).Add("Nodes", nodes) + m := newModel(ctx).Set("Nodes", nodes) return ctx.Render("node/list", m) } @@ -57,7 +57,7 @@ func nodeDetail(ctx web.Context) error { return err } - m := newModel(ctx).Add("Node", node).Add("Tasks", tasks) + m := newModel(ctx).Set("Node", node).Set("Tasks", tasks) return ctx.Render("node/detail", m) } @@ -73,7 +73,7 @@ func nodeRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("ID", id).Add("Node", node).Add("Raw", j) + m := newModel(ctx).Set("ID", id).Set("Node", node).Set("Raw", j) return ctx.Render("node/raw", m) } @@ -84,7 +84,7 @@ func nodeEdit(ctx web.Context) error { return err } - m := newModel(ctx).Add("Node", node) + m := newModel(ctx).Set("Node", node) return ctx.Render("node/edit", m) } diff --git a/controller/profile.go b/controller/profile.go index f9558fc..5d628dc 100644 --- a/controller/profile.go +++ b/controller/profile.go @@ -30,7 +30,7 @@ func profileIndex(ctx web.Context) error { return err } - m := newModel(ctx).Add("User", user) + m := newModel(ctx).Set("User", user) return ctx.Render("profile/index", m) } diff --git a/controller/registry.go b/controller/registry.go index 3cccc99..41dd8b6 100644 --- a/controller/registry.go +++ b/controller/registry.go @@ -30,7 +30,7 @@ func registryList(ctx web.Context) error { return err } - m := newModel(ctx).Add("Registries", registries) + m := newModel(ctx).Set("Registries", registries) return ctx.Render("registry/list", m) } diff --git a/controller/role.go b/controller/role.go index 174ab0c..069b108 100644 --- a/controller/role.go +++ b/controller/role.go @@ -37,12 +37,12 @@ func roleIndex(ctx web.Context) error { return err } - m := newModel(ctx).Add("Roles", roles) + m := newModel(ctx).Set("Roles", roles) return ctx.Render("system/role/list", m) } func roleNew(ctx web.Context) error { - m := newModel(ctx).Add("Perms", misc.Perms) + m := newModel(ctx).Set("Perms", misc.Perms) return ctx.Render("system/role/new", m) } @@ -75,7 +75,7 @@ func roleDetail(ctx web.Context) error { for _, p := range role.Perms { perms[p] = model.Placeholder } - m := newModel(ctx).Add("Role", role).Add("Perms", misc.Perms).Add("CheckedPerms", perms) + m := newModel(ctx).Set("Role", role).Set("Perms", misc.Perms).Set("CheckedPerms", perms) return ctx.Render("system/role/detail", m) } @@ -93,7 +93,7 @@ func roleEdit(ctx web.Context) error { for _, p := range role.Perms { perms[p] = model.Placeholder } - m := newModel(ctx).Add("Role", role).Add("Perms", misc.Perms).Add("CheckedPerms", perms) + m := newModel(ctx).Set("Role", role).Set("Perms", misc.Perms).Set("CheckedPerms", perms) return ctx.Render("system/role/edit", m) } diff --git a/controller/secret.go b/controller/secret.go index 2a73090..0878611 100644 --- a/controller/secret.go +++ b/controller/secret.go @@ -40,8 +40,8 @@ func secretList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, page). - Add("Name", name). - Add("Secrets", secrets) + Set("Name", name). + Set("Secrets", secrets) return ctx.Render("secret/list", m) } @@ -82,7 +82,7 @@ func secretEdit(ctx web.Context) error { if err != nil { return err } - m := newModel(ctx).Add("Secret", secret) + m := newModel(ctx).Set("Secret", secret) return ctx.Render("secret/edit", m) } diff --git a/controller/service.go b/controller/service.go index acbe8da..47e0f88 100644 --- a/controller/service.go +++ b/controller/service.go @@ -5,7 +5,6 @@ import ( "strconv" "strings" - "github.com/cuigh/auxo/data/set" "github.com/cuigh/auxo/errors" "github.com/cuigh/auxo/net/web" "github.com/cuigh/auxo/util/cast" @@ -13,6 +12,7 @@ import ( "github.com/cuigh/swirl/biz/docker" "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" + "mtime.com/auxo/data/set" ) // ServiceController is a controller of docker service @@ -56,8 +56,8 @@ func serviceList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, page). - Add("Name", name). - Add("Services", services) + Set("Name", name). + Set("Services", services) return ctx.Render("service/list", m) } @@ -87,7 +87,7 @@ func serviceDetail(ctx web.Context) error { return err } - m := newModel(ctx).Add("Service", info).Add("Tasks", tasks).Add("Command", cmd) + m := newModel(ctx).Set("Service", info).Set("Tasks", tasks).Set("Command", cmd) return ctx.Render("service/detail", m) } @@ -103,7 +103,7 @@ func serviceRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Service", name).Add("Raw", j) + m := newModel(ctx).Set("Service", name).Set("Raw", j) return ctx.Render("service/raw", m) } @@ -116,8 +116,8 @@ func serviceLogs(ctx web.Context) error { return err } - m := newModel(ctx).Add("Service", name).Add("Line", line).Add("Timestamps", timestamps). - Add("Stdout", stdout.String()).Add("Stderr", stderr.String()) + m := newModel(ctx).Set("Service", name).Set("Line", line).Set("Timestamps", timestamps). + Set("Stdout", stdout.String()).Set("Stderr", stderr.String()) return ctx.Render("service/logs", m) } @@ -177,9 +177,9 @@ func serviceNew(ctx web.Context) error { } checkedNetworks := set.FromSlice(service.Networks, func(i int) interface{} { return service.Networks[i] }) - m := newModel(ctx).Add("Service", service).Add("Registries", registries). - Add("Networks", networks).Add("CheckedNetworks", checkedNetworks). - Add("Secrets", secrets).Add("Configs", configs) + m := newModel(ctx).Set("Service", service).Set("Registries", registries). + Set("Networks", networks).Set("CheckedNetworks", checkedNetworks). + Set("Secrets", secrets).Set("Configs", configs) return ctx.Render("service/new", m) } @@ -194,9 +194,9 @@ func serviceCreate(ctx web.Context) error { var registry *model.Registry registry, err = biz.Registry.Get(info.Registry) if err != nil { - return errors.Wrap("Load registry info failed", err) + return errors.Wrap(err, "load registry info failed") } else if registry == nil { - return errors.New("Can't load registry info") + return errors.New("can't load registry info") } info.Image = registry.URL + "/" + info.Image @@ -232,9 +232,9 @@ func serviceEdit(ctx web.Context) error { stack := service.Spec.Labels["com.docker.stack.namespace"] checkedNetworks := set.FromSlice(service.Endpoint.VirtualIPs, func(i int) interface{} { return service.Endpoint.VirtualIPs[i].NetworkID }) - m := newModel(ctx).Add("Service", model.NewServiceInfo(service)).Add("Stack", stack). - Add("Networks", networks).Add("CheckedNetworks", checkedNetworks). - Add("Secrets", secrets).Add("Configs", configs) + m := newModel(ctx).Set("Service", model.NewServiceInfo(service)).Set("Stack", stack). + Set("Networks", networks).Set("CheckedNetworks", checkedNetworks). + Set("Secrets", secrets).Set("Configs", configs) return ctx.Render("service/edit", m) } diff --git a/controller/setting.go b/controller/setting.go index 4d36bcf..c9a8e37 100644 --- a/controller/setting.go +++ b/controller/setting.go @@ -26,7 +26,7 @@ func settingIndex(ctx web.Context) error { return err } - m := newModel(ctx).Add("Setting", setting) + m := newModel(ctx).Set("Setting", setting) return ctx.Render("system/setting/index", m) } diff --git a/controller/stack.go b/controller/stack.go index 83523e5..68e4ff6 100644 --- a/controller/stack.go +++ b/controller/stack.go @@ -44,7 +44,7 @@ func stackTaskList(ctx web.Context) error { return err } - m := newModel(ctx).Add("Stacks", stacks) + m := newModel(ctx).Set("Stacks", stacks) return ctx.Render("stack/task/list", m) } @@ -74,8 +74,8 @@ func stackArchiveList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, args.PageIndex). - Add("Name", args.Name). - Add("Archives", archives) + Set("Name", args.Name). + Set("Archives", archives) return ctx.Render("stack/archive/list", m) } @@ -89,7 +89,7 @@ func stackArchiveDetail(ctx web.Context) error { return web.ErrNotFound } - m := newModel(ctx).Add("Archive", archive) + m := newModel(ctx).Set("Archive", archive) return ctx.Render("stack/archive/detail", m) } @@ -103,7 +103,7 @@ func stackArchiveEdit(ctx web.Context) error { return web.ErrNotFound } - m := newModel(ctx).Add("Archive", archive) + m := newModel(ctx).Set("Archive", archive) return ctx.Render("stack/archive/edit", m) } diff --git a/controller/task.go b/controller/task.go index 74f1a7e..c2f24c3 100644 --- a/controller/task.go +++ b/controller/task.go @@ -40,8 +40,8 @@ func taskList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, args.PageSize, args.PageIndex). - Add("Args", args). - Add("Tasks", tasks) + Set("Args", args). + Set("Tasks", tasks) return ctx.Render("task/list", m) } @@ -52,7 +52,7 @@ func taskDetail(ctx web.Context) error { return err } - m := newModel(ctx).Add("Task", task) + m := newModel(ctx).Set("Task", task) return ctx.Render("task/detail", m) } @@ -68,6 +68,6 @@ func taskRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Task", task).Add("Raw", j) + m := newModel(ctx).Set("Task", task).Set("Raw", j) return ctx.Render("task/raw", m) } diff --git a/controller/template.go b/controller/template.go index 98d8917..fafdb2a 100644 --- a/controller/template.go +++ b/controller/template.go @@ -3,7 +3,7 @@ package controller import ( "encoding/json" - "github.com/cuigh/auxo/data/set" + "github.com/cuigh/auxo/data" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/biz" "github.com/cuigh/swirl/biz/docker" @@ -49,8 +49,8 @@ func templateList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, args.PageIndex). - Add("Name", args.Name). - Add("Templates", tpls) + Set("Name", args.Name). + Set("Templates", tpls) return ctx.Render("service/template/list", m) } @@ -72,9 +72,9 @@ func templateNew(ctx web.Context) error { if err != nil { return err } - m := newModel(ctx).Add("Action", "New").Add("Service", service).Add("Registries", registries). - Add("Networks", networks).Add("CheckedNetworks", set.Set{}). - Add("Secrets", secrets).Add("Configs", configs) + m := newModel(ctx).Set("Action", "New").Set("Service", service).Set("Registries", registries). + Set("Networks", networks).Set("CheckedNetworks", data.Set{}). + Set("Secrets", secrets).Set("Configs", configs) return ctx.Render("service/template/edit", m) } @@ -140,11 +140,13 @@ func templateEdit(ctx web.Context) error { if err != nil { return err } - checkedNetworks := set.FromSlice(service.Networks, func(i int) interface{} { return service.Networks[i] }) - m := newModel(ctx).Add("Action", "Edit").Add("Service", service).Add("Registries", registries). - Add("Networks", networks).Add("CheckedNetworks", checkedNetworks). - Add("Secrets", secrets).Add("Configs", configs) + checkedNetworks := data.NewSet() + checkedNetworks.AddSlice(service.Networks, func(i int) interface{} { return service.Networks[i] }) + + m := newModel(ctx).Set("Action", "Edit").Set("Service", service).Set("Registries", registries). + Set("Networks", networks).Set("CheckedNetworks", checkedNetworks). + Set("Secrets", secrets).Set("Configs", configs) return ctx.Render("service/template/edit", m) } diff --git a/controller/user.go b/controller/user.go index 32aa9c0..03ab239 100644 --- a/controller/user.go +++ b/controller/user.go @@ -52,9 +52,9 @@ func userIndex(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, args.PageIndex). - Add("Query", args.Query). - Add("Filter", args.Filter). - Add("Users", users) + Set("Query", args.Query). + Set("Filter", args.Filter). + Set("Users", users) return ctx.Render("system/user/list", m) } @@ -64,7 +64,7 @@ func userNew(ctx web.Context) error { return err } - m := newModel(ctx).Add("Roles", roles) + m := newModel(ctx).Set("Roles", roles) return ctx.Render("system/user/new", m) } @@ -106,7 +106,7 @@ func userDetail(ctx web.Context) error { } } - m := newModel(ctx).Add("User", user).Add("Roles", roles) + m := newModel(ctx).Set("User", user).Set("Roles", roles) return ctx.Render("system/user/detail", m) } @@ -129,7 +129,7 @@ func userEdit(ctx web.Context) error { for _, id := range user.Roles { userRoles[id] = model.Placeholder } - m := newModel(ctx).Add("User", user).Add("Roles", roles).Add("UserRoles", userRoles) + m := newModel(ctx).Set("User", user).Set("Roles", roles).Set("UserRoles", userRoles) return ctx.Render("system/user/edit", m) } diff --git a/controller/volume.go b/controller/volume.go index 1dc5152..122bc61 100644 --- a/controller/volume.go +++ b/controller/volume.go @@ -44,8 +44,8 @@ func volumeList(ctx web.Context) error { } m := newPagerModel(ctx, totalCount, model.PageSize, page). - //Add("Name", name). - Add("Volumes", volumes) + //Set("Name", name). + Set("Volumes", volumes) return ctx.Render("volume/list", m) } @@ -93,7 +93,7 @@ func volumeDetail(ctx web.Context) error { if err != nil { return err } - m := newModel(ctx).Add("Volume", volume) + m := newModel(ctx).Set("Volume", volume) return ctx.Render("volume/detail", m) } @@ -109,6 +109,6 @@ func volumeRaw(ctx web.Context) error { return err } - m := newModel(ctx).Add("Volume", name).Add("Raw", j) + m := newModel(ctx).Set("Volume", name).Set("Raw", j) return ctx.Render("volume/raw", m) } diff --git a/main.go b/main.go index 579a3ac..6c0fefb 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,8 @@ import ( "github.com/cuigh/auxo/app/flag" "github.com/cuigh/auxo/config" "github.com/cuigh/auxo/net/web" - "github.com/cuigh/auxo/net/web/auth" - "github.com/cuigh/auxo/net/web/middleware" + "github.com/cuigh/auxo/net/web/filter" + "github.com/cuigh/auxo/net/web/filter/auth" "github.com/cuigh/auxo/net/web/renderer/jet" "github.com/cuigh/swirl/biz" "github.com/cuigh/swirl/controller" @@ -23,7 +23,7 @@ func main() { misc.BindOptions() app.Name = "Swirl" - app.Version = "0.6" + app.Version = "0.6.1" app.Desc = "A web management UI for Docker, focused on swarm cluster" app.Action = func(ctx *app.Context) { misc.LoadOptions() @@ -49,7 +49,7 @@ func server() *web.Server { ws := web.Auto() - // set render/validator.. + // set render ws.Renderer = jet.New().SetDebug(config.GetBool("debug")). AddFunc("time", misc.FormatTime(setting.TimeZone.Offset)). AddFunc("i18n", misc.Message(setting.Language)). @@ -57,17 +57,20 @@ func server() *web.Server { AddVariable("language", setting.Language). AddVariable("version", app.Version). AddVariable("go_version", runtime.Version()) - //ws.Validator = valid.New() // register global filters - ws.Filter(middleware.Recover()) + ws.Use(filter.NewRecover()) // register static handlers - ws.Static("", filepath.Join(filepath.Dir(app.GetPath()), "assets")) + ws.Static("/assets", filepath.Join(filepath.Dir(app.GetPath()), "assets")) // create biz group - form := auth.NewForm(biz.User.Identify, &auth.FormConfig{Timeout: time.Minute * 30, SlidingExpiration: true}) - g := ws.Group("", form.Middleware, middleware.Authorize(biz.User.Authorize)) + form := &auth.Form{ + Identifier: biz.User.Identify, + Timeout: time.Minute * 30, + SlidingExpiration: true, + } + g := ws.Group("", form, filter.NewAuthorizer(biz.User.Authorize)) // register auth handlers g.Post("/login", form.LoginJSON(biz.User.Login)).SetAuthorize(web.AuthAnonymous) diff --git a/misc/util.go b/misc/util.go index 4c43e82..ef7bb87 100644 --- a/misc/util.go +++ b/misc/util.go @@ -12,12 +12,6 @@ import ( ) var Funcs = map[string]interface{}{ - "limit": func(s string, length int) string { - if len(s) > length { - return s[:length] + "..." - } - return s - }, //"time": func(t time.Time) string { // return t.Local().Format("2006-01-02 15:04:05") //}, @@ -41,9 +35,6 @@ var Funcs = map[string]interface{}{ "trimPrefix": func(s, prefix string) string { return strings.TrimPrefix(s, prefix) }, - "slice": func(values ...interface{}) interface{} { - return values - }, } func Message(lang string) func(key string, args ...interface{}) string { diff --git a/model/auth.go b/model/auth.go index 2965088..2998bc3 100644 --- a/model/auth.go +++ b/model/auth.go @@ -50,10 +50,10 @@ type User struct { type UserListArgs struct { // admins, active, blocked - Filter string `query:"filter"` - Query string `query:"query"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Filter string `bind:"filter"` + Query string `bind:"query"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } type Session struct { diff --git a/model/docker.go b/model/docker.go index a19eba3..b20239d 100644 --- a/model/docker.go +++ b/model/docker.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/cuigh/auxo/data/size" + "github.com/cuigh/auxo/byte/size" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/swarm" @@ -487,12 +487,12 @@ type ConfigUpdateInfo struct { } type TaskListArgs struct { - Service string `query:"service"` - Node string `query:"node"` - Name string `query:"name"` - State string `query:"state"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Service string `bind:"service"` + Node string `bind:"node"` + Name string `bind:"name"` + State string `bind:"state"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } type TaskInfo struct { @@ -594,10 +594,10 @@ func NewImageListInfo(image types.ImageSummary) *ImageListInfo { type ContainerListArgs struct { // created|restarting|running|removing|paused|exited|dead - Filter string `query:"filter"` - Name string `query:"name"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Filter string `bind:"filter"` + Name string `bind:"name"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } type ContainerListInfo struct { diff --git a/model/event.go b/model/event.go index 0c354f1..685d2e1 100644 --- a/model/event.go +++ b/model/event.go @@ -8,7 +8,6 @@ import ( type EventType string const ( - // swarm EventTypeRegistry EventType = "Registry" EventTypeNode EventType = "Node" EventTypeNetwork EventType = "Network" @@ -19,10 +18,8 @@ const ( EventTypeSecret EventType = "Secret" EventTypeConfig EventType = "Config" - // local EventTypeVolume EventType = "Volume" - // system EventTypeAuthentication EventType = "Authentication" EventTypeRole EventType = "Role" EventTypeUser EventType = "User" @@ -32,8 +29,8 @@ const ( type EventAction string const ( - EventActionLogin EventAction = "Login" - EventActionLogout EventAction = "Logout" + EventActionLogin EventAction = "Login" + //EventActionLogout EventAction = "Logout" EventActionCreate EventAction = "Create" EventActionDelete EventAction = "Delete" EventActionUpdate EventAction = "Update" @@ -78,8 +75,8 @@ func (e *Event) URL(et EventType, code string) string { } type EventListArgs struct { - Type string `query:"type"` - Name string `query:"name"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Type string `bind:"type"` + Name string `bind:"name"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } diff --git a/model/service.go b/model/service.go index 94c110a..6e55240 100644 --- a/model/service.go +++ b/model/service.go @@ -13,9 +13,9 @@ type Archive struct { } type ArchiveListArgs struct { - Name string `query:"name"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Name string `bind:"name"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } type Template struct { @@ -29,7 +29,7 @@ type Template struct { } type TemplateListArgs struct { - Name string `query:"name"` - PageIndex int `query:"page"` - PageSize int `query:"size"` + Name string `bind:"name"` + PageIndex int `bind:"page"` + PageSize int `bind:"size"` } diff --git a/views/_layouts/default.jet b/views/_layouts/default.jet index 31a2357..5a5efab 100644 --- a/views/_layouts/default.jet +++ b/views/_layouts/default.jet @@ -6,9 +6,9 @@ - - - + + + {{ block style() }}{{end}} @@ -16,7 +16,7 @@