summaryrefslogtreecommitdiffstats
path: root/models/publickey.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/publickey.go')
-rw-r--r--models/publickey.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/models/publickey.go b/models/publickey.go
index f9880c74cd..1246cffc58 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -209,6 +209,18 @@ func AddPublicKey(key *PublicKey) (err error) {
return nil
}
+// GetPublicKeyById returns public key by given ID.
+func GetPublicKeyById(keyId int64) (*PublicKey, error) {
+ key := new(PublicKey)
+ has, err := x.Id(keyId).Get(key)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrKeyNotExist
+ }
+ return key, nil
+}
+
// ListPublicKey returns a list of all public keys that user has.
func ListPublicKey(uid int64) ([]*PublicKey, error) {
keys := make([]*PublicKey, 0, 5)
@@ -277,6 +289,12 @@ func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error {
return nil
}
+// UpdatePublicKey updates given public key.
+func UpdatePublicKey(key *PublicKey) error {
+ _, err := x.Id(key.Id).AllCols().Update(key)
+ return err
+}
+
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
func DeletePublicKey(key *PublicKey) error {
has, err := x.Get(key)