diff options
Diffstat (limited to 'routers/api/v1/user/gpg_key.go')
-rw-r--r-- | routers/api/v1/user/gpg_key.go | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index 9066268bba..b0f9f1feb3 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -8,7 +8,7 @@ import ( "fmt" "net/http" - "code.gitea.io/gitea/models" + asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -18,7 +18,7 @@ import ( ) func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) { - keys, err := models.ListGPGKeys(uid, listOptions) + keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, listOptions) if err != nil { ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err) return @@ -29,7 +29,7 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) apiKeys[i] = convert.ToGPGKey(keys[i]) } - total, err := models.CountUserGPGKeys(uid) + total, err := asymkey_model.CountUserGPGKeys(uid) if err != nil { ctx.InternalServerError(err) return @@ -114,9 +114,9 @@ func GetGPGKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id")) + key, err := asymkey_model.GetGPGKeyByID(ctx.ParamsInt64(":id")) if err != nil { - if models.IsErrGPGKeyNotExist(err) { + if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "GetGPGKeyByID", err) @@ -128,12 +128,12 @@ func GetGPGKey(ctx *context.APIContext) { // CreateUserGPGKey creates new GPG key to given user by ID. func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) { - token := models.VerificationToken(ctx.User, 1) - lastToken := models.VerificationToken(ctx.User, 0) + token := asymkey_model.VerificationToken(ctx.User, 1) + lastToken := asymkey_model.VerificationToken(ctx.User, 0) - keys, err := models.AddGPGKey(uid, form.ArmoredKey, token, form.Signature) - if err != nil && models.IsErrGPGInvalidTokenSignature(err) { - keys, err = models.AddGPGKey(uid, form.ArmoredKey, lastToken, form.Signature) + keys, err := asymkey_model.AddGPGKey(uid, form.ArmoredKey, token, form.Signature) + if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) { + keys, err = asymkey_model.AddGPGKey(uid, form.ArmoredKey, lastToken, form.Signature) } if err != nil { HandleAddGPGKeyError(ctx, err, token) @@ -156,7 +156,7 @@ func GetVerificationToken(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - token := models.VerificationToken(ctx.User, 1) + token := asymkey_model.VerificationToken(ctx.User, 1) ctx.PlainText(http.StatusOK, []byte(token)) } @@ -178,25 +178,25 @@ func VerifyUserGPGKey(ctx *context.APIContext) { // "$ref": "#/responses/validationError" form := web.GetForm(ctx).(*api.VerifyGPGKeyOption) - token := models.VerificationToken(ctx.User, 1) - lastToken := models.VerificationToken(ctx.User, 0) + token := asymkey_model.VerificationToken(ctx.User, 1) + lastToken := asymkey_model.VerificationToken(ctx.User, 0) - _, err := models.VerifyGPGKey(ctx.User.ID, form.KeyID, token, form.Signature) - if err != nil && models.IsErrGPGInvalidTokenSignature(err) { - _, err = models.VerifyGPGKey(ctx.User.ID, form.KeyID, lastToken, form.Signature) + _, err := asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, token, form.Signature) + if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) { + _, err = asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, lastToken, form.Signature) } if err != nil { - if models.IsErrGPGInvalidTokenSignature(err) { + if asymkey_model.IsErrGPGInvalidTokenSignature(err) { ctx.Error(http.StatusUnprocessableEntity, "GPGInvalidSignature", fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) return } ctx.Error(http.StatusInternalServerError, "VerifyUserGPGKey", err) } - key, err := models.GetGPGKeysByKeyID(form.KeyID) + key, err := asymkey_model.GetGPGKeysByKeyID(form.KeyID) if err != nil { - if models.IsErrGPGKeyNotExist(err) { + if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "GetGPGKeysByKeyID", err) @@ -255,8 +255,8 @@ func DeleteGPGKey(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if err := models.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { - if models.IsErrGPGKeyAccessDenied(err) { + if err := asymkey_model.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { + if asymkey_model.IsErrGPGKeyAccessDenied(err) { ctx.Error(http.StatusForbidden, "", "You do not have access to this key") } else { ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err) @@ -270,15 +270,15 @@ func DeleteGPGKey(ctx *context.APIContext) { // HandleAddGPGKeyError handle add GPGKey error func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) { switch { - case models.IsErrGPGKeyAccessDenied(err): + case asymkey_model.IsErrGPGKeyAccessDenied(err): ctx.Error(http.StatusUnprocessableEntity, "GPGKeyAccessDenied", "You do not have access to this GPG key") - case models.IsErrGPGKeyIDAlreadyUsed(err): + case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err): ctx.Error(http.StatusUnprocessableEntity, "GPGKeyIDAlreadyUsed", "A key with the same id already exists") - case models.IsErrGPGKeyParsing(err): + case asymkey_model.IsErrGPGKeyParsing(err): ctx.Error(http.StatusUnprocessableEntity, "GPGKeyParsing", err) - case models.IsErrGPGNoEmailFound(err): + case asymkey_model.IsErrGPGNoEmailFound(err): ctx.Error(http.StatusNotFound, "GPGNoEmailFound", fmt.Sprintf("None of the emails attached to the GPG key could be found. It may still be added if you provide a valid signature for the token: %s", token)) - case models.IsErrGPGInvalidTokenSignature(err): + case asymkey_model.IsErrGPGInvalidTokenSignature(err): ctx.Error(http.StatusUnprocessableEntity, "GPGInvalidSignature", fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) default: ctx.Error(http.StatusInternalServerError, "AddGPGKey", err) |