diff --git a/app/localdb/localdb.go b/app/localdb/localdb.go index d5c8e24..9cbc0a7 100644 --- a/app/localdb/localdb.go +++ b/app/localdb/localdb.go @@ -43,10 +43,9 @@ func SaveDB(localDBPath string, db DB) error { } func (localdb DB) GetPool(poolname string) (common.Pool, []string, int, error) { - pool := common.Pool{} pool, ok := localdb.data[poolname] if !ok { - return pool, []string{}, http.StatusNotFound, fmt.Errorf("Pool %s not in localdb", poolname) + return pool, []string{}, http.StatusNotFound, fmt.Errorf("pool %s not in localdb", poolname) } return pool, []string{}, http.StatusOK, nil } diff --git a/app/main.go b/app/main.go index 744c6f2..881553f 100644 --- a/app/main.go +++ b/app/main.go @@ -149,7 +149,7 @@ func Run() { router.GET("/pools/:poolid", func(c *gin.Context) { poolid, ok := c.Params.Get("poolid") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } @@ -170,7 +170,7 @@ func Run() { router.POST("/pools/:poolid", func(c *gin.Context) { poolid, ok := c.Params.Get("poolid") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } @@ -191,7 +191,7 @@ func Run() { router.DELETE("/pools/:poolid", func(c *gin.Context) { poolid, ok := c.Params.Get("poolid") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } @@ -212,7 +212,7 @@ func Run() { router.GET("/groups/:groupname", func(c *gin.Context) { groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } @@ -238,7 +238,7 @@ func Run() { router.POST("/groups/:groupname", func(c *gin.Context) { groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -265,7 +265,7 @@ func Run() { router.DELETE("/groups/:groupname", func(c *gin.Context) { groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -292,13 +292,13 @@ func Run() { router.POST("/pools/:poolid/groups/:groupname", func(c *gin.Context) { poolid, ok := c.Params.Get("poolid") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -325,13 +325,13 @@ func Run() { router.DELETE("/pools/:poolid/groups/:groupname", func(c *gin.Context) { poolid, ok := c.Params.Get("poolid") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -358,7 +358,7 @@ func Run() { router.GET("/users/:username", func(c *gin.Context) { username_str, ok := c.Params.Get("username") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter poolid")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter poolid")}) return } @@ -384,7 +384,7 @@ func Run() { router.POST("/users/:username", func(c *gin.Context) { username_str, ok := c.Params.Get("username") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -424,7 +424,7 @@ func Run() { router.DELETE("/users/:username", func(c *gin.Context) { username_str, ok := c.Params.Get("username") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } @@ -451,13 +451,13 @@ func Run() { router.POST("/groups/:groupname/users/:username", func(c *gin.Context) { groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } username_str, ok := c.Params.Get("username") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter username")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter username")}) return } @@ -490,13 +490,13 @@ func Run() { router.DELETE("/groups/:groupname/users/:username", func(c *gin.Context) { groupname_str, ok := c.Params.Get("groupname") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupname")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter groupname")}) return } username_str, ok := c.Params.Get("username") if !ok { - c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter username")}) + c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("missing required path parameter username")}) return } diff --git a/app/pve/pve.go b/app/pve/pve.go index 6b640c8..e70002f 100644 --- a/app/pve/pve.go +++ b/app/pve/pve.go @@ -153,9 +153,7 @@ func (pve ProxmoxClient) GetGroup(groupname common.Groupname) (common.Group, []s group.Groupname, _ = common.ParseGroupname(pvegroup.GroupID) - for _, userid := range pvegroup.Members { - members = append(members, userid) - } + members = append(members, pvegroup.Members...) return group, members, http.StatusOK, nil } @@ -306,7 +304,7 @@ func (pve ProxmoxClient) DelUserFromGroup(username common.Username, groupname co idx := slices.Index(user.Groups, groupname.ToString()) if idx < 0 { - return http.StatusBadRequest, fmt.Errorf("Did not find group %s in user groups {%+v}.", groupname.ToString(), user.Groups) + return http.StatusBadRequest, fmt.Errorf("did not find group %s in user groups {%+v}", groupname.ToString(), user.Groups) } newGroups := slices.Delete(user.Groups, idx, idx) diff --git a/app/utils.go b/app/utils.go index fc89840..987083f 100644 --- a/app/utils.go +++ b/app/utils.go @@ -29,7 +29,7 @@ func GetUserSessionFromContext(c *gin.Context) (*UserSession, int, error) { session := sessions.Default(c) SessionUUID := session.Get("SessionUUID") if SessionUUID == nil { - return nil, http.StatusUnauthorized, fmt.Errorf("No auth session found") + return nil, http.StatusUnauthorized, fmt.Errorf("no auth session found") } uuid := SessionUUID.(string) usersession := UserSessions[uuid]