MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / genKeyPair

Function genKeyPair

cmd/cql-proxy/api/keypair.go:29–68  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

27)
28
29func genKeyPair(c *gin.Context) {
30 r := struct {
31 Password string `json:"password" form:"password"`
32 }{}
33
34 if err := c.ShouldBind(&r); err != nil {
35 abortWithError(c, http.StatusBadRequest, err)
36 return
37 }
38
39 // save key to persistence
40 developer := getDeveloperID(c)
41
42 p, err := model.AddNewPrivateKey(model.GetDB(c), developer)
43 if err != nil {
44 _ = c.Error(err)
45 abortWithError(c, http.StatusInternalServerError, ErrGenerateKeyPairFailed)
46 return
47 }
48
49 // set as main account
50 err = model.SetIfNoMainAccount(model.GetDB(c), developer, p.Account)
51 if err != nil {
52 _ = c.Error(err)
53 abortWithError(c, http.StatusInternalServerError, ErrSetMainAccountFailed)
54 return
55 }
56
57 keyBytes, err := kms.EncodePrivateKey(p.Key, []byte(r.Password))
58 if err != nil {
59 _ = c.Error(err)
60 abortWithError(c, http.StatusInternalServerError, ErrEncodePrivateKeyFailed)
61 return
62 }
63
64 responseWithData(c, http.StatusOK, gin.H{
65 "account": p.Account,
66 "key": string(keyBytes),
67 })
68}
69
70func uploadKeyPair(c *gin.Context) {
71 r := struct {

Callers

nothing calls this directly

Calls 8

AddNewPrivateKeyFunction · 0.92
GetDBFunction · 0.92
SetIfNoMainAccountFunction · 0.92
EncodePrivateKeyFunction · 0.92
abortWithErrorFunction · 0.85
getDeveloperIDFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected