2020-11-30 09:37:17 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/go-openapi/strfmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Controller) CreateMachine(gctx *gin.Context) {
|
|
|
|
var err error
|
|
|
|
var input models.WatcherRegistrationRequest
|
|
|
|
if err = gctx.ShouldBindJSON(&input); err != nil {
|
|
|
|
gctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err = input.Validate(strfmt.Default); err != nil {
|
|
|
|
c.HandleDBErrors(gctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.DBClient.CreateMachine(input.MachineID, input.Password, gctx.ClientIP(), false, false)
|
|
|
|
if err != nil {
|
|
|
|
c.HandleDBErrors(gctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-30 15:15:07 +00:00
|
|
|
gctx.Status(http.StatusCreated)
|
2020-11-30 09:37:17 +00:00
|
|
|
return
|
|
|
|
}
|