未验证 提交 b9aacf28 编写于 作者: Y yubo 提交者: GitHub

add start,end for transfer.index.fullmatch get (#494)

* add start,end with transfer.index.fullmatch get

* bugfix: should cleanup token before destory session when auth.extra.mode.enable
上级 54512491
package dataobj package dataobj
import (
"fmt"
"time"
)
type QueryData struct { type QueryData struct {
Start int64 `json:"start"` Start int64 `json:"start"`
End int64 `json:"end"` End int64 `json:"end"`
...@@ -97,10 +102,34 @@ type XcludeResp struct { ...@@ -97,10 +102,34 @@ type XcludeResp struct {
} }
type IndexByFullTagsRecv struct { type IndexByFullTagsRecv struct {
Endpoints []string `json:"endpoints"` Endpoints []string `json:"endpoints"`
Nids []string `json:"nids"` Nids []string `json:"nids"`
Metric string `json:"metric"` Metric string `json:"metric"`
Tagkv []TagPair `json:"tagkv"` Tagkv []TagPair `json:"tagkv"`
Start int64 `json:"start" description:"inclusive"`
End int64 `json:"end" description:"exclusive"`
StartInclusive time.Time `json:"-"`
EndExclusive time.Time `json:"-"`
}
func (p *IndexByFullTagsRecv) Validate() error {
if p.End == 0 {
p.EndExclusive = time.Now()
} else {
p.EndExclusive = time.Unix(p.End, 0)
}
if p.Start == 0 {
p.StartInclusive = p.EndExclusive.Add(-time.Hour * 25)
} else {
p.StartInclusive = time.Unix(p.Start, 0)
}
if p.StartInclusive.After(p.EndExclusive) {
return fmt.Errorf("start is after end")
}
return nil
} }
type IndexByFullTagsResp struct { type IndexByFullTagsResp struct {
......
...@@ -237,8 +237,7 @@ func (p *Authenticator) DeleteSession(sid string) error { ...@@ -237,8 +237,7 @@ func (p *Authenticator) DeleteSession(sid string) error {
if !p.extraMode { if !p.extraMode {
pkgcache.Delete("sid." + s.Sid) pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid) return models.SessionDelete(s.Sid)
return nil
} }
return deleteSession(s) return deleteSession(s)
} }
...@@ -490,10 +489,12 @@ func checkPassword(cf *models.AuthConfig, passwd string) error { ...@@ -490,10 +489,12 @@ func checkPassword(cf *models.AuthConfig, passwd string) error {
func deleteSession(s *models.Session) error { func deleteSession(s *models.Session) error {
pkgcache.Delete("sid." + s.Sid) pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid)
pkgcache.Delete("access-token." + s.AccessToken) pkgcache.Delete("access-token." + s.AccessToken)
models.TokenDelete(s.AccessToken)
return nil if err := models.SessionDelete(s.Sid); err != nil {
return err
}
return models.TokenDelete(s.AccessToken)
} }
func deleteSessionByToken(t *models.Token) error { func deleteSessionByToken(t *models.Token) error {
......
...@@ -733,9 +733,15 @@ func pwdRulesGet(c *gin.Context) { ...@@ -733,9 +733,15 @@ func pwdRulesGet(c *gin.Context) {
} }
func sessionDestory(c *gin.Context) (sid string, err error) { func sessionDestory(c *gin.Context) (sid string, err error) {
if sid, err = session.Destroy(c.Writer, c.Request); sid != "" { if sid, err = session.GetSid(c.Request); sid == "" {
auth.DeleteSession(sid) return
}
if e := auth.DeleteSession(sid); e != nil {
logger.Debugf("auth.deleteSession sid %s err %v", sid, e)
} }
session.Destroy(c.Writer, c.Request)
return return
} }
...@@ -46,6 +46,10 @@ func Destroy(w http.ResponseWriter, r *http.Request) (string, error) { ...@@ -46,6 +46,10 @@ func Destroy(w http.ResponseWriter, r *http.Request) (string, error) {
return DefaultSession.Destroy(w, r) return DefaultSession.Destroy(w, r)
} }
func GetSid(r *http.Request) (string, error) {
return DefaultSession.GetSid(r)
}
func Get(sid string) (*SessionStore, error) { func Get(sid string) (*SessionStore, error) {
return DefaultSession.Get(sid) return DefaultSession.Get(sid)
} }
...@@ -99,7 +103,7 @@ type Manager struct { ...@@ -99,7 +103,7 @@ type Manager struct {
func (p *Manager) Start(w http.ResponseWriter, r *http.Request) (store *SessionStore, err error) { func (p *Manager) Start(w http.ResponseWriter, r *http.Request) (store *SessionStore, err error) {
var sid string var sid string
if sid, err = p.getSid(r); err != nil { if sid, err = p.GetSid(r); err != nil {
return return
} }
...@@ -172,7 +176,7 @@ func (p *Manager) All() int { ...@@ -172,7 +176,7 @@ func (p *Manager) All() int {
return p.all() return p.all()
} }
func (p *Manager) getSid(r *http.Request) (sid string, err error) { func (p *Manager) GetSid(r *http.Request) (sid string, err error) {
var cookie *http.Cookie var cookie *http.Cookie
cookie, err = r.Cookie(p.config.CookieName) cookie, err = r.Cookie(p.config.CookieName)
......
...@@ -268,6 +268,11 @@ func (p *Client) QueryIndexByFullTags(inputs []dataobj.IndexByFullTagsRecv) ([]d ...@@ -268,6 +268,11 @@ func (p *Client) QueryIndexByFullTags(inputs []dataobj.IndexByFullTagsRecv) ([]d
var resp dataobj.IndexByFullTagsResp var resp dataobj.IndexByFullTagsResp
for i, input := range inputs { for i, input := range inputs {
if err := input.Validate(); err != nil {
logger.Errorf("input validate err %s", err)
continue
}
resp = p.queryIndexByFullTags(session, input) resp = p.queryIndexByFullTags(session, input)
list[i] = resp list[i] = resp
count += resp.Count count += resp.Count
......
...@@ -231,8 +231,8 @@ func (cfg M3dbSection) queryIndexByFullTagsOptions(input dataobj.IndexByFullTags ...@@ -231,8 +231,8 @@ func (cfg M3dbSection) queryIndexByFullTagsOptions(input dataobj.IndexByFullTags
} }
return query, index.QueryOptions{ return query, index.QueryOptions{
StartInclusive: indexStartTime(), StartInclusive: input.StartInclusive,
EndExclusive: time.Now(), EndExclusive: input.EndExclusive,
SeriesLimit: cfg.SeriesLimit, SeriesLimit: cfg.SeriesLimit,
DocsLimit: cfg.DocsLimit, DocsLimit: cfg.DocsLimit,
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册