controller.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package v1
  2. import (
  3. "context"
  4. middlewares "github.com/crowdsecurity/crowdsec/pkg/apiserver/middlewares/v1"
  5. "github.com/crowdsecurity/crowdsec/pkg/csconfig"
  6. "github.com/crowdsecurity/crowdsec/pkg/csplugin"
  7. "github.com/crowdsecurity/crowdsec/pkg/database"
  8. "github.com/crowdsecurity/crowdsec/pkg/models"
  9. )
  10. type Controller struct {
  11. Ectx context.Context
  12. DBClient *database.Client
  13. APIKeyHeader string
  14. Middlewares *middlewares.Middlewares
  15. Profiles []*csconfig.ProfileCfg
  16. CAPIChan chan []*models.Alert
  17. PluginChannel chan csplugin.ProfileAlert
  18. ConsoleConfig csconfig.ConsoleConfig
  19. }
  20. func New(dbClient *database.Client, ctx context.Context, profiles []*csconfig.ProfileCfg, capiChan chan []*models.Alert, pluginChannel chan csplugin.ProfileAlert, consoleConfig csconfig.ConsoleConfig) (*Controller, error) {
  21. var err error
  22. v1 := &Controller{
  23. Ectx: ctx,
  24. DBClient: dbClient,
  25. APIKeyHeader: middlewares.APIKeyHeader,
  26. Profiles: profiles,
  27. CAPIChan: capiChan,
  28. PluginChannel: pluginChannel,
  29. ConsoleConfig: consoleConfig,
  30. }
  31. v1.Middlewares, err = middlewares.NewMiddlewares(dbClient)
  32. if err != nil {
  33. return v1, err
  34. }
  35. return v1, nil
  36. }