1
0
forked from x/ContextOS

add mdb.temp_expire

Change-Id: Idf617556626a8004938e8fcca2889681107102c1
This commit is contained in:
shaoying 2019-03-17 18:50:09 +08:00
parent 89b2883789
commit 3694db8a41
4 changed files with 60 additions and 39 deletions

View File

@ -1454,13 +1454,20 @@ func (m *Message) Free(cbs ...func(msg *Message) (done bool)) *Message {
}
func (m *Message) Cmdm(args ...interface{}) *Message {
// 执行命令
msg := m.Search(kit.Format(m.Magic("session", "current.ctx")), true)[0]
if msg == nil {
msg = m.Spawn()
m.Log("info", "current: %v", m.Magic("session", "current"))
arg := []string{}
if pod := kit.Format(m.Magic("session", "current.pod")); pod != "" {
arg = append(arg, "context", "ssh", "sh", "node", pod)
}
msg.Cmd(args...).CopyTo(m)
m.Magic("session", "current.ctx", msg.target.Name)
if ctx := kit.Format(m.Magic("session", "current.ctx")); ctx != "" {
arg = append(arg, "context", ctx)
}
arg = append(arg, kit.Trans(args...)...)
// 执行命令
m.Spawn().Cmd(arg).CopyTo(m)
// m.Magic("session", "current.ctx", msg.target.Name)
return m
}
func (m *Message) Cmdy(args ...interface{}) *Message {

View File

@ -63,8 +63,9 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
"address": &ctx.Config{Name: "address", Value: "", Help: "默认地址"},
"driver": &ctx.Config{Name: "driver(mysql)", Value: "mysql", Help: "默认驱动"},
"temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"},
"temp_view": &ctx.Config{Name: "temp_view", Value: map[string]interface{}{}, Help: "缓存数据"},
"temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"},
"temp_view": &ctx.Config{Name: "temp_view", Value: map[string]interface{}{}, Help: "缓存数据"},
"temp_expire": &ctx.Config{Name: "temp_expire(s)", Value: "3000", Help: "缓存数据"},
"note": &ctx.Config{Name: "note", Value: map[string]interface{}{
"faa01a8fc2fc92dae3fbc02ac1b4ec75": map[string]interface{}{
@ -343,6 +344,26 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
}},
"temp": &ctx.Command{Name: "temp [type [meta [data]]] [tid [node|ship|data] [chain... [select ...]]]", Form: map[string]int{"select": -1, "limit": 1}, Help: "缓存数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 0 && arg[0] == "check" {
h := ""
for i := 1; i < len(arg)-1; i += 2 {
switch arg[i] {
case "url", "trans":
h = ""
}
if h = m.Cmdx("aaa.hash", arg[i], arg[i+1], h); !m.Confs("temp", h) {
return
}
expire := kit.Time(m.Conf("temp", []string{h, "create_time"})) + kit.Int(m.Confx("temp_expire")) - kit.Time(m.Time())
m.Log("info", "expire: %ds", expire)
if expire < 0 {
return
}
}
m.Echo(h)
return
}
if len(arg) > 2 { // 添加数据
if temp := m.Confm("temp", arg[0]); temp == nil {
h := m.Cmdx("aaa.hash", arg[0], arg[1])

View File

@ -353,35 +353,25 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}
if m.Options("remote_code") {
m.Option("username", m.Option("user.name"))
if m.Option("username", m.Option("user.name")); !m.Confs("trust", m.Option("node.route")) {
// 用户签名
hash, _ := kit.Hash("rand", m.Option("text.time", m.Time("stamp")), m.Option("node.route"))
m.Option("user.cert", m.Cmd("aaa.auth", "username", m.Option("user.name"), "cert").Append("meta"))
m.Option("user.sign", m.Spawn().Cmdx("ssh.remote", m.Option("user.route"), "sync", "check", "user", m.Option("node.route"), hash))
// 检查会话
m.Option("sessid", "")
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "session").Table(func(line map[string]string) {
if m.Cmds("aaa.auth", line["key"], "username", m.Option("user.name")) {
m.Option("sessid", line["key"])
// 代理验签
if !m.Options("user.cert") || !m.Options("user.sign") || !m.Cmds("aaa.rsa", "verify", m.Option("user.cert"), m.Option("user.sign"), hash) {
m.Log("warn", "user error")
m.Echo("no right of %s", m.Option("text.route"))
return
}
})
} else {
m.Log("info", "skip verify user of node %s", m.Option("node.route"))
}
if !m.Options("sessid") {
if !m.Confs("trust", m.Option("node.route")) {
// 用户签名
hash, _ := kit.Hash("rand", m.Option("text.time", m.Time("stamp")), m.Option("node.route"))
m.Option("user.cert", m.Cmd("aaa.auth", "username", m.Option("user.name"), "cert").Append("meta"))
m.Option("user.sign", m.Spawn().Cmdx("ssh.remote", m.Option("user.route"), "sync", "check", "user", m.Option("node.route"), hash))
// 代理验签
if !m.Options("user.cert") || !m.Options("user.sign") || !m.Cmds("aaa.rsa", "verify", m.Option("user.cert"), m.Option("user.sign"), hash) {
m.Log("warn", "user error")
m.Echo("no right of %s", m.Option("text.route"))
return
}
} else {
m.Log("info", "skip verify user %s", m.Option("user.name"))
}
// 创建会话
m.Option("sessid", m.Cmdx("aaa.sess", "nodes", "username", m.Option("user.name")))
// 创建会话
if m.Option("sessid", m.Cmd("aaa.auth", "username", m.Option("user.name"), "session").Append("key")); !m.Options("sessid") {
m.Option("sessid", m.Cmdx("aaa.sess", "web", "username", m.Option("user.name")))
m.Cmd("aaa.auth", m.Option("sessid"), "nodes", m.Option("node.route"))
}

View File

@ -110,9 +110,6 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
if msg.Options("ticket") {
msg.Option("uuid", msg.Option(msg.Conf("login", "cas_uuid")))
msg.Option("username", cas.Username(r))
if lark := msg.Find("web.chat.lark"); lark != nil {
msg.Option("username", lark.Cmdx("user", msg.Option("email"), "id"))
}
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("web.session", "login", "uuid"), Path: "/"})
http.Redirect(w, r, merge(msg, r.Header.Get("index_url"), "ticket", ""), http.StatusTemporaryRedirect)
@ -470,7 +467,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
return
}},
"get": &ctx.Command{Name: "get [which] name [method GET|POST] url arg...", Help: "访问服务, method: 请求方法, url: 请求地址, arg: 请求参数",
Form: map[string]int{"which": 1, "method": 1, "headers": 2, "content_type": 1, "file": 2, "body": 1, "parse": 1, "temp": -1, "save": 1},
Form: map[string]int{"which": 1, "method": 1, "headers": 2, "content_type": 1, "file": 2, "body": 1, "parse": 1, "temp": -1, "save": 1, "temp_expire": 1},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Cmdy("web.spide")
@ -541,6 +538,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}
}
if m.Options("temp_expire") {
if h := m.Cmdx("mdb.temp", "check", "url", uri+uri_arg); h != "" {
m.Cmdy("mdb.temp", h, "data", "data", m.Meta["temp"])
return
}
}
req, e := http.NewRequest(method, uri, body)
m.Assert(e)
m.Log("info", "%s %s", req.Method, req.URL)
@ -1000,7 +1004,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
// args = kit.Trans(list)
}
m.Log("fuck", "what %v", args)
if msg.Cmd(args); m.Options("bench") {
name_alias := "action." + kit.Select(msg.Option("componet_name"), msg.Option("componet_name_alias"))