Implement SSH signing retrieval
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a2a2f7dc87
commit
ba6e1490c3
2 changed files with 87 additions and 8 deletions
38
keys.go
38
keys.go
|
@ -50,6 +50,44 @@ func declareAPIKeysRoutes(router *gin.RouterGroup) {
|
|||
|
||||
c.Data(http.StatusOK, "application/pgp-keys", ret)
|
||||
})
|
||||
|
||||
usersRoutes.GET("/allowed_signers", func(c *gin.Context) {
|
||||
var u *User
|
||||
if user, ok := c.Get("user"); ok {
|
||||
u = user.(*User)
|
||||
} else {
|
||||
u = c.MustGet("LoggedUser").(*User)
|
||||
}
|
||||
|
||||
user, err := GitLab_getUser(c.Request.Context(), u)
|
||||
if err != nil {
|
||||
log.Println("Unable to GitLab_getUser:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve your GitLab user. Please try again in a few moment."})
|
||||
return
|
||||
}
|
||||
|
||||
keys, err := GitLab_getUserSSHKeys(c.Request.Context(), u)
|
||||
if err != nil {
|
||||
log.Println("Unable to GitLab_getUserSSHKeys:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve your keys from GitLab. Please try again in a few moment."})
|
||||
return
|
||||
}
|
||||
|
||||
var ret string
|
||||
for _, k := range keys {
|
||||
if k.UsageType != "auth_and_signing" && k.UsageType != "signing" {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(user.Email) > 0 {
|
||||
ret += fmt.Sprintf("%s %s\n", user.Email, k.Key)
|
||||
} else {
|
||||
ret += fmt.Sprintf("*@epita.fr %s\n", k.Key)
|
||||
}
|
||||
}
|
||||
|
||||
c.Data(http.StatusOK, "text/plain", []byte(ret))
|
||||
})
|
||||
}
|
||||
|
||||
func declareAPIAuthKeysRoutes(router *gin.RouterGroup) {
|
||||
|
|
Reference in a new issue