2020-11-30 09:37:17 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/go-openapi/strfmt"
|
2023-12-14 13:54:11 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
2020-11-30 09:37:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Controller) CreateMachine(gctx *gin.Context) {
|
|
|
|
var input models.WatcherRegistrationRequest
|
2024-01-15 10:44:38 +00:00
|
|
|
|
|
|
|
if err := gctx.ShouldBindJSON(&input); err != nil {
|
2020-11-30 09:37:17 +00:00
|
|
|
gctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 10:44:38 +00:00
|
|
|
|
|
|
|
if err := input.Validate(strfmt.Default); err != nil {
|
2020-11-30 09:37:17 +00:00
|
|
|
c.HandleDBErrors(gctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-15 10:44:38 +00:00
|
|
|
if _, err := c.DBClient.CreateMachine(input.MachineID, input.Password, gctx.ClientIP(), false, false, types.PasswordAuthType); err != nil {
|
2020-11-30 09:37:17 +00:00
|
|
|
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
|
|
|
}
|