未验证 提交 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
import (
"fmt"
"time"
)
type QueryData struct {
Start int64 `json:"start"`
End int64 `json:"end"`
......@@ -97,10 +102,34 @@ type XcludeResp struct {
}
type IndexByFullTagsRecv struct {
Endpoints []string `json:"endpoints"`
Nids []string `json:"nids"`
Metric string `json:"metric"`
Tagkv []TagPair `json:"tagkv"`
Endpoints []string `json:"endpoints"`
Nids []string `json:"nids"`
Metric string `json:"metric"`
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 {
......
......@@ -237,8 +237,7 @@ func (p *Authenticator) DeleteSession(sid string) error {
if !p.extraMode {
pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid)
return nil
return models.SessionDelete(s.Sid)
}
return deleteSession(s)
}
......@@ -490,10 +489,12 @@ func checkPassword(cf *models.AuthConfig, passwd string) error {
func deleteSession(s *models.Session) error {
pkgcache.Delete("sid." + s.Sid)
models.SessionDelete(s.Sid)
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 {
......
......@@ -733,9 +733,15 @@ func pwdRulesGet(c *gin.Context) {
}
func sessionDestory(c *gin.Context) (sid string, err error) {
if sid, err = session.Destroy(c.Writer, c.Request); sid != "" {
auth.DeleteSession(sid)
if sid, err = session.GetSid(c.Request); 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
}
......@@ -46,6 +46,10 @@ func Destroy(w http.ResponseWriter, r *http.Request) (string, error) {
return DefaultSession.Destroy(w, r)
}
func GetSid(r *http.Request) (string, error) {
return DefaultSession.GetSid(r)
}
func Get(sid string) (*SessionStore, error) {
return DefaultSession.Get(sid)
}
......@@ -99,7 +103,7 @@ type Manager struct {
func (p *Manager) Start(w http.ResponseWriter, r *http.Request) (store *SessionStore, err error) {
var sid string
if sid, err = p.getSid(r); err != nil {
if sid, err = p.GetSid(r); err != nil {
return
}
......@@ -172,7 +176,7 @@ func (p *Manager) All() int {
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
cookie, err = r.Cookie(p.config.CookieName)
......
......@@ -268,6 +268,11 @@ func (p *Client) QueryIndexByFullTags(inputs []dataobj.IndexByFullTagsRecv) ([]d
var resp dataobj.IndexByFullTagsResp
for i, input := range inputs {
if err := input.Validate(); err != nil {
logger.Errorf("input validate err %s", err)
continue
}
resp = p.queryIndexByFullTags(session, input)
list[i] = resp
count += resp.Count
......
......@@ -231,8 +231,8 @@ func (cfg M3dbSection) queryIndexByFullTagsOptions(input dataobj.IndexByFullTags
}
return query, index.QueryOptions{
StartInclusive: indexStartTime(),
EndExclusive: time.Now(),
StartInclusive: input.StartInclusive,
EndExclusive: input.EndExclusive,
SeriesLimit: cfg.SeriesLimit,
DocsLimit: cfg.DocsLimit,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册