diff --git a/docs/rest_api.md b/docs/rest_api.md index 8eecb98e56d259860ad15452638e750d1a681b96..1410e3a5fd78e5f778cda3e45baee5aa630c35c6 100644 --- a/docs/rest_api.md +++ b/docs/rest_api.md @@ -4,29 +4,28 @@ | Route | Description | Method | Input | Output | |--- |--- |--- |--- |--- | -| `/login` | login (return access token) | POST | common.params.Login | common.params.Login | -| `/token/refresh` | obtain a new access token | GET | | common.params.Token | -| `/version` | obtain version number | GET | | common.params.Version | +| `/login` | login (return access token) | POST | common.params.Login | common.params.Token | +| `/token/refresh` | obtain a new access token | GET | - | common.params.Token | +| `/version` | obtain version number | GET | - | common.params.Version | ### User management -| Route | Description | Method | Input | Req. user cap. | Output | -|--- |--- |--- |--- |--- |--- | -| `/users` | create a user | POST | email,firstname,lastname,pwd,caps | `USER_CREATE` | | -| `/users/{email}` | delete a user | DELETE | | `USER_DESTROY` | | -| `/users/{email}/caps` | set caps for a user | PUT | caps | `USER_SET_CAPS` | | -| `/users/{email}/unlock` | unlock a user | PUT | | `USER_UNLOCK` | | -| `/users/{email}/resetpwd` | reset a user's pwd | PUT | | `USER_RESETPWD` | new pwd | -| `/users/pwd` | set current user's pwd | PUT | pwd | | | -| `/users` | list users | GET | | `USER_LIST` | | -| `/users/{email}` | list a user | GET | | `USER_LIST` | | -| `/users/whoami` | list current user | GET | | | | +| Route | Description | Method | Input | Req. user cap. | Output | +|--- |--- |--- |--- |--- |--- | +| `/users` | create a user | POST | common.params.UserWithPwd | `USER_CREATE` | - | +| `/users/{email}` | delete a user | DELETE | - | `USER_DESTROY` | - | +| `/users/{email}/caps` | set caps for a user | PUT | common.params.UserSetCaps | `USER_SET_CAPS` | - | +| `/users/{email}/unlock` | unlock a user | PUT | - | `USER_UNLOCK` | - | +| `/users/{email}/resetpwd` | reset a user's pwd | PUT | - | `USER_RESETPWD` | common.params.UserSetPwd | +| `/users/pwd` | set current user's pwd | PUT | common.params.UserSetPwd | - | - | +| `/users` | list users | GET | - | `USER_LIST` | []common.params.UserWithoutPwd | +| `/users/whoami` | list current user | GET | - | | common.params.UserWithoutPwd | - Open question: shall we forbid the deletion of a user if they still own templates or VMs? ### VM management -| Route | Description | Method | Input | Req. user cap. | Op. | Req. VM access cap. | Output | +| Route | Description | Method | Input | Req. user cap. | Op. | Req. VM access cap. | Output | |--- |--- |--- |--- |--- |--- |--- |--- | | `/vms` | returns VMs that can be listed | GET | | `VM_LIST_ANY` | OR | `VM_LIST` | | | `/vms/{id}` | returns the specified VM | GET | | `VM_LIST_ANY` | OR | `VM_LIST` | | @@ -41,7 +40,7 @@ | `/vms/exportdir` | returns VMs that can have a dir downloaded | GET | | `VM_READFS_ANY` | OR | `VM_READFS` | | | `/vms/importfiles` | returns VMs allowing files upload | GET | | `VM_WRITEFS_ANY` | OR | `VM_WRITEFS` | | -| Route | Description | Method | Input | Req. user cap. | Op. | Req. VM access cap. | Output | +| Route | Description | Method | Input | Req. user cap. | Op. | Req. VM access cap. | Output | |--- |--- |--- |--- |--- |--- |--- |--- | | `/vms` | create a VM | POST | name,cpus,ram,nic,usb,template | `VM_CREATE` | | | | | `/vms/{id}` | delete a VM | DELETE | | `VM_DESTROY_ANY` | OR | `VM_DESTROY` | | @@ -58,7 +57,7 @@ ### Template management -| Route | Description | Method | Input | Req. user cap. | Output | +| Route | Description | Method | Input | Req. user cap. | Output | |--- |--- |--- |--- |--- |--- | | `/templates` | returns templates that can be listed | GET | | `TPL_LIST_ANY` OR `TPL_LIST` | | | `/templates/{id}` | returns a template | GET | | `TPL_LIST_ANY` OR `TPL_LIST` | | diff --git a/src/client/cmdUser/userAdd.go b/src/client/cmdUser/userAdd.go index 793ddaa3464d35a3e49a7227ffb202b3cabc570d..b7321b7ccc28c7c639f90e7961dc548cd5211f5e 100644 --- a/src/client/cmdUser/userAdd.go +++ b/src/client/cmdUser/userAdd.go @@ -55,7 +55,7 @@ List of user capabilities: i = 0 } } - u.PrintErr(usage) + u.PrintlnErr(usage) } func (cmd *Add)Run(args []string) int { @@ -79,8 +79,10 @@ func (cmd *Add)Run(args []string) int { } if err := cmd.runRequest(cargs); err != nil { - u.PrintlnErr(err.Error()) + u.PrintlnErr("FAILED creating user "+cargs.Email+": "+err.Error()) statusCode = 1 + } else { + u.Println("Successfully created user "+cargs.Email) } } else if argc == 1 { // Detected syntax: file.csv diff --git a/src/server/router/helper.go b/src/server/router/helper.go index dea451098945bb0ff24f565b7e1d6df8d98bd10f..874852e23c77a504695ad233b14bee0b61be1e1a 100644 --- a/src/server/router/helper.go +++ b/src/server/router/helper.go @@ -10,11 +10,11 @@ const ( msgInsufficientCaps = "Permission denied: insufficient capabilities" ) -func jsonMsg(msg string) map[string]interface{} { - // The following 2 lines are identical: - //return map[string]interface{}{"message": msg} - return echo.Map{"message": msg} -} +// func jsonMsg(msg string) map[string]interface{} { +// // The following 2 lines are identical: +// //return map[string]interface{}{"message": msg} +// return echo.Map{"message": msg} +// } // Decodes and validates a json object in the response's body. func decodeJson(c echo.Context, object any) error { diff --git a/src/server/router/routerTemplates.go b/src/server/router/routerTemplates.go index ebeacd8348942bd17012c12a788a6002906c31d1..298e1b8b717d46a711dcbb1cdeb4348e03d68b33 100644 --- a/src/server/router/routerTemplates.go +++ b/src/server/router/routerTemplates.go @@ -236,7 +236,7 @@ func (r *RouterTemplates)DeleteTemplate(c echo.Context) error { if err := r.tpl.DeleteTemplate(tplID, r.vms); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } else if user.HasCapability(caps.CAP_TPL_DESTROY) { template, err := r.tpl.GetTemplate(tplID) if err != nil { @@ -247,7 +247,7 @@ func (r *RouterTemplates)DeleteTemplate(c echo.Context) error { if err := r.tpl.DeleteTemplate(tplID, r.vms); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } } @@ -284,7 +284,7 @@ func (r *RouterTemplates)EditTemplate(c echo.Context) error { if err := r.tpl.EditTemplate(tplID, p.Name, p.Access); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } else if user.HasCapability(caps.CAP_TPL_EDIT) { template, err := r.tpl.GetTemplate(tplID) if err != nil { @@ -297,7 +297,7 @@ func (r *RouterTemplates)EditTemplate(c echo.Context) error { if err := r.tpl.EditTemplate(tplID, p.Name, p.Access); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } } diff --git a/src/server/router/routerUsers.go b/src/server/router/routerUsers.go index 4d294786909a27e7e547942b69c7d2eea23944e6..5858fb046e9925cf5aa99a67cc133dd7679436a2 100644 --- a/src/server/router/routerUsers.go +++ b/src/server/router/routerUsers.go @@ -34,7 +34,7 @@ func (r *RouterUsers)GetUsers(c echo.Context) error { list := []params.UserWithoutPwd{} for _, u := range r.users.GetUsers() { - user := params.UserWithoutPwd{u.Email, u.FirstName, u.LastName, u.Caps} + user := params.UserWithoutPwd{Email: u.Email, FirstName: u.FirstName, LastName: u.LastName, Caps: u.Caps} list = append(list, user) } @@ -49,7 +49,8 @@ func (r *RouterUsers)GetLoggedUser(c echo.Context) error { return echo.NewHTTPError(http.StatusUnauthorized, err.Error()) } - return c.JSONPretty(http.StatusOK, user, " ") + userWithoutPwd := params.UserWithoutPwd{Email: user.Email, FirstName: user.FirstName, LastName: user.LastName, Caps: user.Caps} + return c.JSONPretty(http.StatusOK, userWithoutPwd, " ") } // Deletes a user by its ID. @@ -75,7 +76,7 @@ func (r *RouterUsers)DeleteUserByEmail(c echo.Context) error { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Creates a user. @@ -112,7 +113,7 @@ func (r *RouterUsers)CreateUser(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusCreated, newUser, " ") + return c.JSON(http.StatusCreated, "") } // Update a user's capabilities. @@ -154,7 +155,7 @@ func (r *RouterUsers)SetUserCaps(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Update the logged user's password. @@ -185,7 +186,7 @@ func (r *RouterUsers)SetUserPwd(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Unlock a user. @@ -211,7 +212,7 @@ func (r *RouterUsers)UnlockUser(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Reset a user's password. diff --git a/src/server/router/routerVMs.go b/src/server/router/routerVMs.go index 92a6e50076950169491b7293b91fc55f51da2419..a7222299ce9b09946c12e40d569d4767b88fdc66 100644 --- a/src/server/router/routerVMs.go +++ b/src/server/router/routerVMs.go @@ -311,7 +311,7 @@ func (r *RouterVMs)DeleteVM(c echo.Context) error { if err := r.vms.DeleteVM(vm.GetID()); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -326,7 +326,7 @@ func (r *RouterVMs)StartVM(c echo.Context) error { if err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -346,7 +346,7 @@ func (r *RouterVMs)StartVMWithCreds(c echo.Context) error { if err := r.vms.StartVMWithCreds(vm.GetID(), p.Port, true, p.Pwd); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -360,7 +360,7 @@ func (r *RouterVMs)KillVM(c echo.Context) error { if err := r.vms.KillVM(vm.GetID()); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -374,7 +374,7 @@ func (r *RouterVMs)ShutdownVM(c echo.Context) error { if err := r.vms.ShutdownVM(vm.GetID()); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -388,7 +388,7 @@ func (r *RouterVMs)RebootVM(c echo.Context) error { if err := r.vms.RebootVM(vm.GetID()); err != nil { return echo.NewHTTPError(http.StatusNotFound, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") }) } @@ -451,7 +451,7 @@ func (r *RouterVMs)SetVMAccessForUser(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Delete a VM Access for a given user. @@ -480,7 +480,7 @@ func (r *RouterVMs)DeleteVMAccessForUser(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ") + return c.JSON(http.StatusOK, "") } // Exports a VM's directory into a compressed archive. @@ -559,7 +559,7 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - return c.JSONPretty(http.StatusCreated, jsonMsg("OK"), " ") + return c.JSON(http.StatusCreated, "") }) } diff --git a/src/server/version/version.go b/src/server/version/version.go index e421af59c5762c91e65461b0fceb490058b9bc44..f406b364bdec025db6d2c29b5eaed18fc66f35af 100644 --- a/src/server/version/version.go +++ b/src/server/version/version.go @@ -7,7 +7,7 @@ import ( const ( major = 1 minor = 10 - bugfix = 0 + bugfix = 1 ) var version params.Version = params.NewVersion(major, minor, bugfix)