mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 05:12:01 +08:00

* fix: support multitenancy in org * fix: register and login working now * fix: changes to migration * fix: migrations run both on sqlite and postgres * fix: remove user flags from fe and be * fix: remove ingestion keys from update * fix: multitenancy support for apdex settings * fix: render ts for users correctly * fix: fix migration to run for new tenants * fix: clean up migrations * fix: address comments * Update pkg/sqlmigration/013_update_organization.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: fix build * fix: force invites with org id * Update pkg/query-service/auth/auth.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: address comments * fix: address comments * fix: provier with their own dialect * fix: update dialects * fix: remove unwanted change * Update pkg/query-service/app/http_handler.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: different files for types --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.signoz.io/signoz/ee/query-service/app/api"
|
|
baseauth "go.signoz.io/signoz/pkg/query-service/auth"
|
|
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
|
"go.signoz.io/signoz/pkg/types"
|
|
"go.signoz.io/signoz/pkg/types/authtypes"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func GetUserFromRequestContext(ctx context.Context, apiHandler *api.APIHandler) (*types.GettableUser, error) {
|
|
patToken, ok := authtypes.UUIDFromContext(ctx)
|
|
if ok && patToken != "" {
|
|
zap.L().Debug("Received a non-zero length PAT token")
|
|
ctx := context.Background()
|
|
dao := apiHandler.AppDao()
|
|
|
|
pat, err := dao.GetPAT(ctx, patToken)
|
|
if err == nil && pat != nil {
|
|
zap.L().Debug("Found valid PAT: ", zap.Any("pat", pat))
|
|
if pat.ExpiresAt < time.Now().Unix() && pat.ExpiresAt != 0 {
|
|
zap.L().Info("PAT has expired: ", zap.Any("pat", pat))
|
|
return nil, fmt.Errorf("PAT has expired")
|
|
}
|
|
group, apiErr := dao.GetGroupByName(ctx, pat.Role)
|
|
if apiErr != nil {
|
|
zap.L().Error("Error while getting group for PAT: ", zap.Any("apiErr", apiErr))
|
|
return nil, apiErr
|
|
}
|
|
user, err := dao.GetUser(ctx, pat.UserID)
|
|
if err != nil {
|
|
zap.L().Error("Error while getting user for PAT: ", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
telemetry.GetInstance().SetPatTokenUser()
|
|
dao.UpdatePATLastUsed(ctx, patToken, time.Now().Unix())
|
|
user.User.GroupID = group.ID
|
|
user.User.ID = pat.Id
|
|
return &types.GettableUser{
|
|
User: user.User,
|
|
Role: pat.Role,
|
|
}, nil
|
|
}
|
|
if err != nil {
|
|
zap.L().Error("Error while getting user for PAT: ", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
}
|
|
return baseauth.GetUserFromReqContext(ctx)
|
|
}
|