Chore: Add loginattempt service (#53687)

* Chore: Add loginattempt service

* Inject loginattemptservice into httpserver
This commit is contained in:
Kat Yang 2022-08-17 02:34:23 -04:00 committed by GitHub
parent c23a9d78ab
commit 7c5ddaea58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 1 deletions

View File

@ -67,6 +67,7 @@ import (
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/services/correlations"
loginAttempt "github.com/grafana/grafana/pkg/services/login_attempt"
publicdashboardsApi "github.com/grafana/grafana/pkg/services/publicdashboards/api"
"github.com/grafana/grafana/pkg/services/query"
"github.com/grafana/grafana/pkg/services/queryhistory"
@ -178,6 +179,7 @@ type HTTPServer struct {
secretsMigrator secrets.Migrator
userService user.Service
tempUserService tempUser.Service
loginAttemptService loginAttempt.Service
}
type ServerOptions struct {
@ -213,7 +215,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardVersionService dashver.Service,
starService star.Service, csrfService csrf.Service, coremodels *registry.Base,
playlistService playlist.Service, apiKeyService apikey.Service, kvStore kvstore.KVStore, secretsMigrator secrets.Migrator, secretsPluginManager plugins.SecretsPluginManager,
publicDashboardsApi *publicdashboardsApi.Api, userService user.Service, tempUserService tempUser.Service) (*HTTPServer, error) {
publicDashboardsApi *publicdashboardsApi.Api, userService user.Service, tempUserService tempUser.Service, loginAttemptService loginAttempt.Service) (*HTTPServer, error) {
web.Env = cfg.Env
m := web.New()
@ -302,6 +304,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
secretsMigrator: secretsMigrator,
userService: userService,
tempUserService: tempUserService,
loginAttemptService: loginAttemptService,
}
if hs.Listener != nil {
hs.log.Debug("Using provided listener")

View File

@ -74,6 +74,7 @@ import (
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
authinfodatabase "github.com/grafana/grafana/pkg/services/login/authinfoservice/database"
"github.com/grafana/grafana/pkg/services/login/loginservice"
"github.com/grafana/grafana/pkg/services/login_attempt/loginattemptimpl"
"github.com/grafana/grafana/pkg/services/ngalert"
ngimage "github.com/grafana/grafana/pkg/services/ngalert/image"
ngmetrics "github.com/grafana/grafana/pkg/services/ngalert/metrics"
@ -313,6 +314,7 @@ var wireBasicSet = wire.NewSet(
userimpl.ProvideService,
orgimpl.ProvideService,
tempuserimpl.ProvideService,
loginattemptimpl.ProvideService,
datasourceservice.ProvideDataSourceMigrationService,
secretsStore.ProvidePluginSecretMigrationService,
secretsMigrations.ProvideSecretMigrationService,

View File

@ -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
}

View File

@ -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
}

View File

@ -0,0 +1 @@
package loginattemptimpl

View File

@ -0,0 +1 @@
package loginattemptimpl