-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
pkg "github.com/inseefrlab/onyxia-api/pkg" | ||
) | ||
|
||
func NoAuthMiddleware() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
c.Set("user", pkg.UserInfo{ | ||
Email: "[email protected]", | ||
ID: "johndoe", | ||
Name: "John Doe", | ||
Groups: []string{}, | ||
IP: c.RemoteIP(), | ||
Projects: []pkg.Project{{Name: "todo"}}, | ||
}) | ||
c.Next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,9 @@ import ( | |
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
pkg "github.com/inseefrlab/onyxia-api/pkg" | ||
) | ||
|
||
type Project struct { | ||
ID string `json:"id"` | ||
Namespace string `json:"namespace"` | ||
Name string `json:"name"` | ||
VaultTopDir string `json:"vaultTopDir"` | ||
} | ||
|
||
type UserInfo struct { | ||
Email string `json:"email,omitempty"` | ||
ID string `json:"idep,omitempty"` | ||
Name string `json:"nomComplet,omitempty"` | ||
IP string `json:"ip,omitempty"` | ||
Groups []string `json:"groups,omitempty"` | ||
Projects []Project `json:"projects"` | ||
} | ||
|
||
// @Summary Get user info | ||
// @Schemes | ||
// @Description Get user info and projects | ||
|
@@ -30,29 +15,8 @@ type UserInfo struct { | |
// @Success 200 | ||
// @Router /user/info [get] | ||
func userInfo(c *gin.Context) { | ||
claims, _ := c.Get("claims") | ||
var userInfo UserInfo | ||
if claims == nil { | ||
userInfo = UserInfo{ | ||
Email: "[email protected]", | ||
ID: "johndoe", | ||
Name: "John Doe", | ||
Groups: []string{}, | ||
IP: c.RemoteIP(), | ||
Projects: []Project{{Name: "todo"}}, | ||
} | ||
} else { | ||
typedClaims := claims.(Claims) | ||
userInfo = UserInfo{ | ||
Email: typedClaims.Email, | ||
ID: typedClaims.ID, | ||
Name: typedClaims.Name, | ||
Groups: typedClaims.Groups, | ||
IP: c.RemoteIP(), | ||
Projects: []Project{{Name: "todo"}}, | ||
} | ||
} | ||
c.JSON(http.StatusOK, userInfo) | ||
user, _ := c.Get("user") | ||
c.JSON(http.StatusOK, user.(pkg.UserInfo)) | ||
} | ||
|
||
func registerUserHandlers(r *gin.RouterGroup) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package pkg | ||
|
||
type Project struct { | ||
ID string `json:"id"` | ||
Namespace string `json:"namespace"` | ||
Name string `json:"name"` | ||
VaultTopDir string `json:"vaultTopDir"` | ||
} | ||
|
||
type UserInfo struct { | ||
Email string `json:"email,omitempty"` | ||
ID string `json:"idep,omitempty"` | ||
Name string `json:"nomComplet,omitempty"` | ||
IP string `json:"ip,omitempty"` | ||
Groups []string `json:"groups,omitempty"` | ||
Projects []Project `json:"projects"` | ||
} |