mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-14 13:24:34 +02:00
* tests: don't run crowdsec if not necessary * make listen_uri report the random port number when 0 is requested * move apiserver.getTLSAuthType() -> csconfig.TLSCfg.GetAuthType() * move apiserver.isEnrolled() -> apiclient.ApiClient.IsEnrolled() * extract function apiserver.recoverFromPanic() * simplify and move APIServer.GetTLSConfig() -> TLSCfg.GetTLSConfig() * moved TLSCfg type to csconfig/tls.go * APIServer.InitController(): early return / happy path * extract function apiserver.newGinLogger() * lapi tests * update unit test * lint (testify) * lint (whitespace, variable names) * update docker tests
32 lines
755 B
Go
32 lines
755 B
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-openapi/strfmt"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
|
)
|
|
|
|
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, types.PasswordAuthType)
|
|
if err != nil {
|
|
c.HandleDBErrors(gctx, err)
|
|
return
|
|
}
|
|
|
|
gctx.Status(http.StatusCreated)
|
|
}
|