Chore: Add loginattempt service (#53687)

* Chore: Add loginattempt service

* Inject loginattemptservice into httpserver
This commit is contained in:
Kat Yang
2022-08-17 08:34:23 +02:00
committed by GitHub
parent c23a9d78ab
commit 7c5ddaea58
6 changed files with 67 additions and 1 deletions
@@ -0,0 +1,13 @@
package loginattempt
import (
"context"
"github.com/grafana/grafana/pkg/models"
)
type Service interface {
CreateLoginAttempt(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error
DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error
GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error
}
@@ -0,0 +1,46 @@
package loginattemptimpl
import (
"context"
"github.com/grafana/grafana/pkg/models"
loginattempt "github.com/grafana/grafana/pkg/services/login_attempt"
"github.com/grafana/grafana/pkg/services/sqlstore"
)
type Service struct {
// TODO remove sqlstore
sqlStore *sqlstore.SQLStore
}
func ProvideService(
ss *sqlstore.SQLStore,
) loginattempt.Service {
return &Service{
sqlStore: ss,
}
}
func (s *Service) CreateLoginAttempt(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
err := s.sqlStore.CreateLoginAttempt(ctx, cmd)
if err != nil {
return err
}
return nil
}
func (s *Service) DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error {
err := s.sqlStore.DeleteOldLoginAttempts(ctx, cmd)
if err != nil {
return err
}
return nil
}
func (s *Service) GetUserLoginAttemptCount(ctx context.Context, cmd *models.GetUserLoginAttemptCountQuery) error {
err := s.sqlStore.GetUserLoginAttemptCount(ctx, cmd)
if err != nil {
return err
}
return nil
}
@@ -0,0 +1 @@
package loginattemptimpl
@@ -0,0 +1 @@
package loginattemptimpl