diff options
author | zeripath <art27@cantab.net> | 2018-11-01 03:40:49 +0000 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-10-31 23:40:49 -0400 |
commit | 00533d38702767bc25703968daaa87b30980d2c9 (patch) | |
tree | 06391609f84a25702c6cbd4498003e81b47adca3 /models/ssh_key.go | |
parent | 584844eada226f062d46da53e9ba6470ecd58eaa (diff) | |
download | gitea-00533d38702767bc25703968daaa87b30980d2c9.tar.gz gitea-00533d38702767bc25703968daaa87b30980d2c9.zip |
Keys API changes (#4960)
* Add private information to the deploy keys api
This commit adds more information to the deploy keys to allow for back
reference in to the main keys list. It also adds information about the
repository that the key is referring to.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add private information to the user keys API
This adjusts the keys API to give out private information to user keys if
the current user is the owner or an admin.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add ability to search keys by fingerprint
This commit adds the functionality to search ssh-keys by fingerprint of
the ssh-key. Deploy keys per repository can also be searched. There is
no current clear API point to allow search of all deploy keys by
fingerprint or keyID.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add integration test
Diffstat (limited to 'models/ssh_key.go')
-rw-r--r-- | models/ssh_key.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go index 2592209b4d..0368ffad33 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/modules/util" "github.com/Unknwon/com" + "github.com/go-xorm/builder" "github.com/go-xorm/xorm" "golang.org/x/crypto/ssh" ) @@ -465,6 +466,19 @@ func SearchPublicKeyByContent(content string) (*PublicKey, error) { return key, nil } +// SearchPublicKey returns a list of public keys matching the provided arguments. +func SearchPublicKey(uid int64, fingerprint string) ([]*PublicKey, error) { + keys := make([]*PublicKey, 0, 5) + cond := builder.NewCond() + if uid != 0 { + cond = cond.And(builder.Eq{"owner_id": uid}) + } + if fingerprint != "" { + cond = cond.And(builder.Eq{"fingerprint": fingerprint}) + } + return keys, x.Where(cond).Find(&keys) +} + // ListPublicKeys returns a list of public keys belongs to given user. func ListPublicKeys(uid int64) ([]*PublicKey, error) { keys := make([]*PublicKey, 0, 5) @@ -833,3 +847,19 @@ func ListDeployKeys(repoID int64) ([]*DeployKey, error) { Where("repo_id = ?", repoID). Find(&keys) } + +// SearchDeployKeys returns a list of deploy keys matching the provided arguments. +func SearchDeployKeys(repoID int64, keyID int64, fingerprint string) ([]*DeployKey, error) { + keys := make([]*DeployKey, 0, 5) + cond := builder.NewCond() + if repoID != 0 { + cond = cond.And(builder.Eq{"repo_id": repoID}) + } + if keyID != 0 { + cond = cond.And(builder.Eq{"key_id": keyID}) + } + if fingerprint != "" { + cond = cond.And(builder.Eq{"fingerprint": fingerprint}) + } + return keys, x.Where(cond).Find(&keys) +} |