MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / AddMyPublicKey

Function AddMyPublicKey

server/handles/sshkey.go:19–48  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

17}
18
19func 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
50func ListMyPublicKey(c *gin.Context) {
51 userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User)

Callers

nothing calls this directly

Calls 5

ErrorStrRespFunction · 0.92
CreateSSHPublicKeyFunction · 0.92
ErrorRespFunction · 0.92
SuccessRespFunction · 0.92
IsGuestMethod · 0.80

Tested by

no test coverage detected