fix: user reg
ci-agent / build (push) Failing after 3m0s

This commit is contained in:
d3m0k1d
2026-04-04 18:49:05 +03:00
parent 398c688fed
commit a71fde67e4
9 changed files with 1647 additions and 362 deletions
+31
View File
@@ -49,6 +49,37 @@ func (ag *AuthGroup) Login(c *gin.Context) {
c.JSON(http.StatusOK, resp)
}
// RegisterUser registers a new user with all permissions set to false.
// @Summary Register user
// @Description Registers a new user with login, password, name, last name. All permissions are set to false.
// @Tags auth
// @Accept json
// @Param request body repository.UserRegister true "Registration data"
// @Success 200 {object} map[string]string
// @Failure 400 {object} map[string]string
// @Failure 409 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /auth/register [post]
func (ag *AuthGroup) RegisterUser(c *gin.Context) {
var req repository.UserRegister
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
return
}
if ag.Repo.ExistsByLogin(req.Login) {
c.JSON(http.StatusConflict, gin.H{"error": "login already exists"})
return
}
if _, err := ag.Repo.RegisterUser(req); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to register user"})
return
}
c.JSON(http.StatusOK, gin.H{"message": "user registered"})
}
// CreateToken creates a new user.
// @Summary Create user
// @Description Creates a new user with permissions
+16 -14
View File
@@ -21,6 +21,22 @@ func NewScriptHandlers(svc *service.ScriptService, cmder *commander.Commander) S
return ScriptHandlers{svc: svc, cmder: cmder}
}
type RunScriptIn struct {
AgentID string `json:"agent_id" binding:"required"`
InterpreterID int64 `json:"interpreter_id" binding:"required"`
ScriptText string `json:"script_text" binding:"required"`
Stdin *string `json:"stdin"`
}
type RunScriptOut struct {
ID int64 `json:"id"`
Command []string `json:"command"`
Stdin *string `json:"stdin"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
Status int32 `json:"status"`
}
// RunScript executes a script on a target agent.
// @Summary Run a script on an agent
// @Description Resolves interpreter argv[] and sends the full command to the agent
@@ -32,12 +48,6 @@ func NewScriptHandlers(svc *service.ScriptService, cmder *commander.Commander) S
// @Router /scripts/run [post]
func (self *ScriptHandlers) RunScript(c *gin.Context) {
err := func() error {
type RunScriptIn struct {
AgentID string `json:"agent_id" binding:"required"`
InterpreterID int64 `json:"interpreter_id" binding:"required"`
ScriptText string `json:"script_text" binding:"required"`
Stdin *string `json:"stdin"`
}
var in RunScriptIn
if err := c.Bind(&in); err != nil {
return err
@@ -67,14 +77,6 @@ func (self *ScriptHandlers) RunScript(c *gin.Context) {
return err
}
type RunScriptOut struct {
ID int64 `json:"id"`
Command []string `json:"command"`
Stdin *string `json:"stdin"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
Status int32 `json:"status"`
}
c.JSON(http.StatusCreated, RunScriptOut{
ID: job.ID,
Command: job.Command,