machines.go 802 B

123456789101112131415161718192021222324252627282930313233
  1. package v1
  2. import (
  3. "net/http"
  4. "github.com/crowdsecurity/crowdsec/pkg/models"
  5. "github.com/crowdsecurity/crowdsec/pkg/types"
  6. "github.com/gin-gonic/gin"
  7. "github.com/go-openapi/strfmt"
  8. )
  9. func (c *Controller) CreateMachine(gctx *gin.Context) {
  10. defer types.CatchPanic("crowdsec/controllersV1/CreateMachine")
  11. var err error
  12. var input models.WatcherRegistrationRequest
  13. if err = gctx.ShouldBindJSON(&input); err != nil {
  14. gctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
  15. return
  16. }
  17. if err = input.Validate(strfmt.Default); err != nil {
  18. c.HandleDBErrors(gctx, err)
  19. return
  20. }
  21. _, err = c.DBClient.CreateMachine(input.MachineID, input.Password, gctx.ClientIP(), false, false)
  22. if err != nil {
  23. c.HandleDBErrors(gctx, err)
  24. return
  25. }
  26. gctx.Status(http.StatusCreated)
  27. return
  28. }