machines.go 691 B

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