controller.go 1.3 KB

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