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/serv.go | |
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/serv.go')
-rw-r--r-- | routers/private/serv.go | 23 |
1 files changed, 12 insertions, 11 deletions
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, |