(c *gin.Context)
| 17 | } |
| 18 | |
| 19 | func AddMyPublicKey(c *gin.Context) { |
| 20 | userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User) |
| 21 | if !ok || userObj.IsGuest() { |
| 22 | common.ErrorStrResp(c, "user invalid", 401) |
| 23 | return |
| 24 | } |
| 25 | var req SSHKeyAddReq |
| 26 | if err := c.ShouldBind(&req); err != nil { |
| 27 | common.ErrorStrResp(c, "request invalid", 400) |
| 28 | return |
| 29 | } |
| 30 | if req.Title == "" { |
| 31 | common.ErrorStrResp(c, "request invalid", 400) |
| 32 | return |
| 33 | } |
| 34 | key := &model.SSHPublicKey{ |
| 35 | Title: req.Title, |
| 36 | KeyStr: strings.TrimSpace(req.Key), |
| 37 | UserId: userObj.ID, |
| 38 | } |
| 39 | err, parsed := op.CreateSSHPublicKey(key) |
| 40 | if !parsed { |
| 41 | common.ErrorStrResp(c, "provided key invalid", 400) |
| 42 | return |
| 43 | } else if err != nil { |
| 44 | common.ErrorResp(c, err, 500, true) |
| 45 | return |
| 46 | } |
| 47 | common.SuccessResp(c) |
| 48 | } |
| 49 | |
| 50 | func ListMyPublicKey(c *gin.Context) { |
| 51 | userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User) |
nothing calls this directly
no test coverage detected