(c *gin.Context)
| 110 | } |
| 111 | |
| 112 | func deleteKeyPair(c *gin.Context) { |
| 113 | r := struct { |
| 114 | Account utils.AccountAddress `json:"account" form:"account" uri:"account" binding:"required,len=64"` |
| 115 | Force bool `json:"force" form:"force"` |
| 116 | }{} |
| 117 | |
| 118 | // ignore validation, check in later ShouldBind |
| 119 | _ = c.ShouldBindUri(&r) |
| 120 | |
| 121 | if err := c.ShouldBind(&r); err != nil { |
| 122 | abortWithError(c, http.StatusBadRequest, err) |
| 123 | return |
| 124 | } |
| 125 | |
| 126 | // check and delete private key |
| 127 | developer := getDeveloperID(c) |
| 128 | db := model.GetDB(c) |
| 129 | |
| 130 | account, err := model.GetAccount(db, developer, r.Account) |
| 131 | if err != nil { |
| 132 | _ = c.Error(err) |
| 133 | abortWithError(c, http.StatusBadRequest, ErrGetAccountFailed) |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | // check account for projects |
| 138 | var projects []*model.Project |
| 139 | projects, err = model.GetUserProjects(db, developer, account.ID) |
| 140 | if err != nil { |
| 141 | _ = c.Error(err) |
| 142 | abortWithError(c, http.StatusBadRequest, ErrGetProjectsFailed) |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | if len(projects) > 0 { |
| 147 | if r.Force { |
| 148 | err = model.DeleteProjects(db, projects...) |
| 149 | if err != nil { |
| 150 | _ = c.Error(err) |
| 151 | abortWithError(c, http.StatusInternalServerError, ErrDeleteProjectsFailed) |
| 152 | return |
| 153 | } |
| 154 | } else { |
| 155 | err = ErrKeyPairHasRelatedProjects |
| 156 | abortWithError(c, http.StatusBadRequest, err) |
| 157 | return |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | p, err := model.DeletePrivateKey(db, developer, r.Account) |
| 162 | if err != nil { |
| 163 | _ = c.Error(err) |
| 164 | abortWithError(c, http.StatusInternalServerError, ErrDeletePrivateKeyFailed) |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | err = model.FixDeletedMainAccount(db, developer, p.ID) |
| 169 | if err != nil { |
nothing calls this directly
no test coverage detected