mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add loginattempt service (#53687)
* Chore: Add loginattempt service * Inject loginattemptservice into httpserver
This commit is contained in:
parent
c23a9d78ab
commit
7c5ddaea58
@ -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")
|
||||
|
@ -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,
|
||||
|
13
pkg/services/login_attempt/login_attempt.go
Normal file
13
pkg/services/login_attempt/login_attempt.go
Normal 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
|
||||
}
|
46
pkg/services/login_attempt/loginattemptimpl/login_attempt.go
Normal file
46
pkg/services/login_attempt/loginattemptimpl/login_attempt.go
Normal 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
|
||||
}
|
1
pkg/services/login_attempt/loginattemptimpl/store.go
Normal file
1
pkg/services/login_attempt/loginattemptimpl/store.go
Normal file
@ -0,0 +1 @@
|
||||
package loginattemptimpl
|
@ -0,0 +1 @@
|
||||
package loginattemptimpl
|
Loading…
Reference in New Issue
Block a user