github.com/crowdsecurity/crowdsec@v1.6.1/pkg/apiserver/controllers/v1/machines.go (about)

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