mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Sync: Move ActiveTokenCount to a new service (#52991)
* Move ActiveTokenCount to a new service * Fixing tests * fix `RootSystem` Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>
This commit is contained in:
co-authored by
Artur Wierzbicki
parent
1eb3513781
commit
085ae014cd
@@ -42,14 +42,26 @@ type UserAuthTokenService struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (s *UserAuthTokenService) ActiveTokenCount(ctx context.Context) (int64, error) {
|
||||
type ActiveAuthTokenService struct {
|
||||
cfg *setting.Cfg
|
||||
sqlStore sqlstore.Store
|
||||
}
|
||||
|
||||
func ProvideActiveAuthTokenService(cfg *setting.Cfg, sqlStore sqlstore.Store) *ActiveAuthTokenService {
|
||||
return &ActiveAuthTokenService{
|
||||
cfg: cfg,
|
||||
sqlStore: sqlStore,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *ActiveAuthTokenService) ActiveTokenCount(ctx context.Context) (int64, error) {
|
||||
var count int64
|
||||
var err error
|
||||
err = s.SQLStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
err = a.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
var model userAuthToken
|
||||
count, err = dbSession.Where(`created_at > ? AND rotated_at > ? AND revoked_at = 0`,
|
||||
s.createdAfterParam(),
|
||||
s.rotatedAfterParam()).
|
||||
getTime().Add(-a.cfg.LoginMaxLifetime).Unix(),
|
||||
getTime().Add(-a.cfg.LoginMaxInactiveLifetime).Unix()).
|
||||
Count(&model)
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user