1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00
This commit is contained in:
shylinux 2021-10-20 02:39:31 +08:00
parent 81d087ddae
commit 221b84ff29
3 changed files with 33 additions and 32 deletions

View File

@ -68,7 +68,10 @@ func init() {
m.Cmd(mdb.INSERT, TOTP, "", mdb.HASH, m.OptionSimple(kit.MDB_NAME, SECRET, PERIOD, NUMBER))
}},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
mdb.HashSelect(m.Spawn(), arg...).Table(func(index int, value map[string]string, head []string) {
mdb.HashSelect(m.Spawn(c), arg...).Table(func(index int, value map[string]string, head []string) {
if len(arg) > 0 {
m.OptionFields("detail")
}
m.Push(kit.MDB_TIME, m.Time())
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
@ -81,6 +84,7 @@ func init() {
m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD])))
}
})
m.PushAction(mdb.REMOVE)
}},
}})
}

View File

@ -19,38 +19,35 @@ const (
const APP = "app"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
APP: {Name: APP, Help: "服务配置", Value: kit.Data(
kit.MDB_SHORT, APPID, kit.MDB_FIELD, "time,appid,appmm,duty,token,expire",
LARK, "https://open.feishu.cn/",
)},
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Conf(APP, kit.Keym(LARK)))
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
APP: {Name: APP, Help: "服务配置", Value: kit.Data(
kit.MDB_SHORT, APPID, kit.MDB_FIELD, "time,appid,appmm,duty,token,expire",
LARK, "https://open.feishu.cn/",
)},
}, Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Config(LARK))
}},
APP: {Name: "app appid auto token login", Help: "应用", Action: ice.MergeAction(map[string]*ice.Action{
LOGIN: {Name: "login appid appmm duty", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(APP), "", mdb.HASH, arg)
}},
APP: {Name: "app appid auto token login", Help: "应用", Action: map[string]*ice.Action{
LOGIN: {Name: "login appid appmm duty", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(APP), "", mdb.HASH, arg)
}},
TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(APP, m.Option(APPID), ice.OptionFields(m.Conf(APP, kit.META_FIELD)))
if now := time.Now().Unix(); msg.Append(TOKEN) == "" || now > kit.Int64(msg.Append(EXPIRE)) {
sub := m.Cmd(web.SPIDE, LARK, web.SPIDE_POST, "/open-apis/auth/v3/tenant_access_token/internal/",
APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM))
TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(APP, m.Option(APPID))
if now := time.Now().Unix(); msg.Append(TOKEN) == "" || now > kit.Int64(msg.Append(EXPIRE)) {
res := m.Cmd(web.SPIDE, LARK, "/open-apis/auth/v3/tenant_access_token/internal/",
APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM))
m.Cmd(mdb.MODIFY, m.Prefix(APP), "", mdb.HASH, m.OptionSimple(APPID),
TOKEN, sub.Append("tenant_access_token"), EXPIRE, now+kit.Int64(sub.Append(EXPIRE)))
m.Echo(sub.Append("tenant_access_token"))
return
}
m.Echo(msg.Append(TOKEN))
}},
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Fields(len(arg), m.Conf(APP, kit.META_FIELD))
m.Cmdy(mdb.SELECT, m.Prefix(APP), "", mdb.HASH, APPID, arg)
m.Cmd(mdb.MODIFY, m.Prefix(APP), "", mdb.HASH, m.OptionSimple(APPID),
TOKEN, res.Append("tenant_access_token"), EXPIRE, now+kit.Int64(res.Append(EXPIRE)))
m.Echo(res.Append("tenant_access_token"))
return
}
m.Echo(msg.Append(TOKEN))
}},
},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
mdb.HashSelect(m, arg...)
}},
},
})
}

View File

@ -279,7 +279,7 @@ func (m *Message) Spawn(arg ...interface{}) *Message {
data: map[string]interface{}{},
message: m, root: m.root,
source: m.target, target: m.target,
source: m.target, target: m.target, _key: m._key,
W: m.W, R: m.R, O: m.O, I: m.I,
}