diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-10 16:14:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 16:14:24 +0800 |
commit | 3ca5dc7e32b372d14ff80d96f14b8f6a805862f1 (patch) | |
tree | 50d193ed0dacf2888d57b193a9b0d36065aff205 /routers/private | |
parent | 0a9fcf63a49799ad3b0f146c54879161bac61e10 (diff) | |
download | gitea-3ca5dc7e32b372d14ff80d96f14b8f6a805862f1.tar.gz gitea-3ca5dc7e32b372d14ff80d96f14b8f6a805862f1.zip |
Move keys to models/asymkey (#17917)
* Move keys to models/keys
* Rename models/keys -> models/asymkey
* change the missed package name
* Fix package alias
* Fix test
* Fix docs
* Fix test
* Fix test
* merge
Diffstat (limited to 'routers/private')
-rw-r--r-- | routers/private/hook_verification.go | 4 | ||||
-rw-r--r-- | routers/private/key.go | 12 | ||||
-rw-r--r-- | routers/private/serv.go | 23 |
3 files changed, 20 insertions, 19 deletions
diff --git a/routers/private/hook_verification.go b/routers/private/hook_verification.go index 8c7492ea68..1b44550cff 100644 --- a/routers/private/hook_verification.go +++ b/routers/private/hook_verification.go @@ -12,7 +12,7 @@ import ( "io" "os" - "code.gitea.io/gitea/models" + asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" ) @@ -97,7 +97,7 @@ func readAndVerifyCommit(sha string, repo *git.Repository, env []string) error { if err != nil { return err } - verification := models.ParseCommitWithSignature(commit) + verification := asymkey_model.ParseCommitWithSignature(commit) if !verification.Verified { cancel() return &errUnverifiedCommit{ diff --git a/routers/private/key.go b/routers/private/key.go index 4f518e41f0..30fde73c8a 100644 --- a/routers/private/key.go +++ b/routers/private/key.go @@ -8,7 +8,7 @@ package private import ( "net/http" - "code.gitea.io/gitea/models" + asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/timeutil" @@ -18,16 +18,16 @@ import ( func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { keyID := ctx.ParamsInt64(":id") repoID := ctx.ParamsInt64(":repoid") - if err := models.UpdatePublicKeyUpdated(keyID); err != nil { + if err := asymkey_model.UpdatePublicKeyUpdated(keyID); err != nil { ctx.JSON(http.StatusInternalServerError, private.Response{ Err: err.Error(), }) return } - deployKey, err := models.GetDeployKeyByRepo(keyID, repoID) + deployKey, err := asymkey_model.GetDeployKeyByRepo(keyID, repoID) if err != nil { - if models.IsErrDeployKeyNotExist(err) { + if asymkey_model.IsErrDeployKeyNotExist(err) { ctx.PlainText(http.StatusOK, []byte("success")) return } @@ -37,7 +37,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { return } deployKey.UpdatedUnix = timeutil.TimeStampNow() - if err = models.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil { + if err = asymkey_model.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil { ctx.JSON(http.StatusInternalServerError, private.Response{ Err: err.Error(), }) @@ -52,7 +52,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { func AuthorizedPublicKeyByContent(ctx *context.PrivateContext) { content := ctx.FormString("content") - publicKey, err := models.SearchPublicKeyByContent(content) + publicKey, err := asymkey_model.SearchPublicKeyByContent(content) if err != nil { ctx.JSON(http.StatusInternalServerError, private.Response{ Err: err.Error(), diff --git a/routers/private/serv.go b/routers/private/serv.go index f28d5a7450..e5ebc5aa92 100644 --- a/routers/private/serv.go +++ b/routers/private/serv.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/models" + asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" @@ -34,9 +35,9 @@ func ServNoCommand(ctx *context.PrivateContext) { } results := private.KeyAndOwner{} - key, err := models.GetPublicKeyByID(keyID) + key, err := asymkey_model.GetPublicKeyByID(keyID) if err != nil { - if models.IsErrKeyNotExist(err) { + if asymkey_model.IsErrKeyNotExist(err) { ctx.JSON(http.StatusUnauthorized, private.Response{ Err: fmt.Sprintf("Cannot find key: %d", keyID), }) @@ -50,7 +51,7 @@ func ServNoCommand(ctx *context.PrivateContext) { } results.Key = key - if key.Type == models.KeyTypeUser || key.Type == models.KeyTypePrincipal { + if key.Type == asymkey_model.KeyTypeUser || key.Type == asymkey_model.KeyTypePrincipal { user, err := user_model.GetUserByID(key.OwnerID) if err != nil { if user_model.IsErrUserNotExist(err) { @@ -184,9 +185,9 @@ func ServCommand(ctx *context.PrivateContext) { } // Get the Public Key represented by the keyID - key, err := models.GetPublicKeyByID(keyID) + key, err := asymkey_model.GetPublicKeyByID(keyID) if err != nil { - if models.IsErrKeyNotExist(err) { + if asymkey_model.IsErrKeyNotExist(err) { ctx.JSON(http.StatusNotFound, private.ErrServCommand{ Results: results, Err: fmt.Sprintf("Cannot find key: %d", keyID), @@ -205,7 +206,7 @@ func ServCommand(ctx *context.PrivateContext) { results.UserID = key.OwnerID // If repo doesn't exist, deploy key doesn't make sense - if !repoExist && key.Type == models.KeyTypeDeploy { + if !repoExist && key.Type == asymkey_model.KeyTypeDeploy { ctx.JSON(http.StatusNotFound, private.ErrServCommand{ Results: results, Err: fmt.Sprintf("Cannot find repository %s/%s", results.OwnerName, results.RepoName), @@ -216,15 +217,15 @@ func ServCommand(ctx *context.PrivateContext) { // Deploy Keys have ownerID set to 0 therefore we can't use the owner // So now we need to check if the key is a deploy key // We'll keep hold of the deploy key here for permissions checking - var deployKey *models.DeployKey + var deployKey *asymkey_model.DeployKey var user *user_model.User - if key.Type == models.KeyTypeDeploy { + if key.Type == asymkey_model.KeyTypeDeploy { results.IsDeployKey = true var err error - deployKey, err = models.GetDeployKeyByRepo(key.ID, repo.ID) + deployKey, err = asymkey_model.GetDeployKeyByRepo(key.ID, repo.ID) if err != nil { - if models.IsErrDeployKeyNotExist(err) { + if asymkey_model.IsErrDeployKeyNotExist(err) { ctx.JSON(http.StatusNotFound, private.ErrServCommand{ Results: results, Err: fmt.Sprintf("Public (Deploy) Key: %d:%s is not authorized to %s %s/%s.", key.ID, key.Name, modeString, results.OwnerName, results.RepoName), @@ -297,7 +298,7 @@ func ServCommand(ctx *context.PrivateContext) { owner.Visibility.IsPrivate() || (user != nil && user.IsRestricted) || // user will be nil if the key is a deploykey setting.Service.RequireSignInView) { - if key.Type == models.KeyTypeDeploy { + if key.Type == asymkey_model.KeyTypeDeploy { if deployKey.Mode < mode { ctx.JSON(http.StatusUnauthorized, private.ErrServCommand{ Results: results, |