mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 00:55:54 +08:00
fix: fix the pat middleware (#7402)
This commit is contained in:
parent
d831c1cb88
commit
1f9b13dc35
@ -29,10 +29,20 @@ func (p *Pat) Wrap(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
for _, header := range p.headers {
|
for _, header := range p.headers {
|
||||||
values = append(values, r.Header.Get(header))
|
values = append(values, r.Header.Get(header))
|
||||||
|
}
|
||||||
|
|
||||||
if header == "SIGNOZ-API-KEY" {
|
ctx, err := p.uuid.ContextFromRequest(r.Context(), values...)
|
||||||
patToken = values[0]
|
if err != nil {
|
||||||
err := p.db.NewSelect().Model(&pat).Where("token = ?", patToken).Scan(r.Context())
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
patToken, ok := authtypes.UUIDFromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = p.db.NewSelect().Model(&pat).Where("token = ?", patToken).Scan(r.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
@ -58,18 +68,7 @@ func (p *Pat) Wrap(next http.Handler) http.Handler {
|
|||||||
OrgID: user.OrgID,
|
OrgID: user.OrgID,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := authtypes.NewContextWithClaims(r.Context(), jwt)
|
ctx = authtypes.NewContextWithClaims(ctx, jwt)
|
||||||
r = r.WithContext(ctx)
|
|
||||||
|
|
||||||
// Mark to update last used since SIGNOZ-API-KEY is present and successful
|
|
||||||
updateLastUsed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx, err := p.uuid.ContextFromRequest(r.Context(), values...)
|
|
||||||
if err != nil {
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user