require.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package require
  2. import (
  3. "fmt"
  4. "github.com/crowdsecurity/crowdsec/pkg/csconfig"
  5. )
  6. func LAPI(c *csconfig.Config) error {
  7. if err := c.LoadAPIServer(); err != nil {
  8. return fmt.Errorf("failed to load Local API: %w", err)
  9. }
  10. if c.DisableAPI {
  11. return fmt.Errorf("local API is disabled -- this command must be run on the local API machine")
  12. }
  13. return nil
  14. }
  15. func CAPI(c *csconfig.Config) error {
  16. if c.API.Server.OnlineClient == nil {
  17. return fmt.Errorf("no configuration for Central API (CAPI) in '%s'", *c.FilePath)
  18. }
  19. return nil
  20. }
  21. func PAPI(c *csconfig.Config) error {
  22. if c.API.Server.OnlineClient.Credentials.PapiURL == "" {
  23. return fmt.Errorf("no PAPI URL in configuration")
  24. }
  25. return nil
  26. }
  27. func Enrolled(c *csconfig.Config) error {
  28. if c.API.Server.OnlineClient.Credentials == nil {
  29. return fmt.Errorf("the Central API (CAPI) must be configured with 'cscli capi register'")
  30. }
  31. return nil
  32. }
  33. func DB(c *csconfig.Config) error {
  34. if err := c.LoadDBConfig(); err != nil {
  35. return fmt.Errorf("this command requires direct database access (must be run on the local API machine): %w", err)
  36. }
  37. return nil
  38. }
  39. func Profiles(c *csconfig.Config) error {
  40. if err := c.API.Server.LoadProfiles(); err != nil {
  41. return fmt.Errorf("while loading profiles: %w", err)
  42. }
  43. return nil
  44. }
  45. func Notifications(c *csconfig.Config) error {
  46. if c.ConfigPaths.NotificationDir == "" {
  47. return fmt.Errorf("config_paths.notification_dir is not set in crowdsec config")
  48. }
  49. return nil
  50. }