diff --git a/misc/git/git.shy b/misc/git/git.shy index 4306ca03..61a4d0c1 100644 --- a/misc/git/git.shy +++ b/misc/git/git.shy @@ -34,4 +34,5 @@ field "统计量" web.code.git.total field "趋势图" web.code.git.trend args `icebergs` field "架构图" web.code.git.spide args `icebergs` field "状态机" web.code.git.status +field "服务器" web.code.git.server diff --git a/misc/git/server.go b/misc/git/server.go index 91cec364..cd3208d0 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -1,11 +1,15 @@ package git import ( + "path" + "github.com/AaronO/go-git-http" "github.com/AaronO/go-git-http/auth" - ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/aaa" + "github.com/shylinux/icebergs/base/cli" + "github.com/shylinux/icebergs/base/mdb" + "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" ) @@ -15,12 +19,37 @@ const SERVER = "server" func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - SERVER: {Name: SERVER, Help: "服务器", Value: kit.Data(kit.MDB_PATH, ".ish/pluged")}, + SERVER: {Name: SERVER, Help: "服务器", Value: kit.Data(kit.MDB_PATH, "usr/local")}, }, Commands: map[string]*ice.Command{ web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Render(ice.RENDER_VOID) }}, + + SERVER: {Name: "server path auto create", Help: "server", Action: map[string]*ice.Action{ + mdb.CREATE: {Name: "create name", Help: "添加", Hand: func(m *ice.Message, arg ...string) { + m.Option(cli.CMD_DIR, path.Join(m.Conf(SERVER, kit.META_PATH), REPOS)) + m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", m.Option(kit.MDB_NAME)) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option(nfs.DIR_ROOT, path.Join(m.Conf(SERVER, kit.META_PATH), REPOS)) + m.Cmdy(nfs.DIR, "./") + m.EchoScript("git remote add origin https://shylinux.com/code/git/repos/volcanos") + }}, + + "/repos/": {Name: "/github.com/", Help: "/github.com/", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + auth.Authenticator(func(info auth.AuthInfo) (bool, error) { + if !aaa.UserLogin(m, info.Username, info.Password) { + return false, nil + } + + if info.Push && aaa.UserRole(m, info.Username) == aaa.VOID { + return false, nil + } + + return true, nil + })(githttp.New(kit.Path(m.Conf(SERVER, kit.META_PATH)))).ServeHTTP(m.W, m.R) + }}, "/github.com/": {Name: "/github.com/", Help: "/github.com/", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { auth.Authenticator(func(info auth.AuthInfo) (bool, error) { if !aaa.UserLogin(m, info.Username, info.Password) {