refactor update ssh key use time (#1466)
This commit is contained in:
parent
d9db188274
commit
5c0bee9b20
|
@ -316,13 +316,7 @@ func runServ(c *cli.Context) error {
|
||||||
|
|
||||||
// Update user key activity.
|
// Update user key activity.
|
||||||
if keyID > 0 {
|
if keyID > 0 {
|
||||||
key, err := models.GetPublicKeyByID(keyID)
|
if err = models.UpdatePublicKeyUpdated(keyID); err != nil {
|
||||||
if err != nil {
|
|
||||||
fail("Internal error", "GetPublicKeyById: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
key.Updated = time.Now()
|
|
||||||
if err = models.UpdatePublicKey(key); err != nil {
|
|
||||||
fail("Internal error", "UpdatePublicKey: %v", err)
|
fail("Internal error", "UpdatePublicKey: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,6 +500,20 @@ func UpdatePublicKey(key *PublicKey) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePublicKeyUpdated updates public key use time.
|
||||||
|
func UpdatePublicKeyUpdated(id int64) error {
|
||||||
|
cnt, err := x.ID(id).Cols("updated").Update(&PublicKey{
|
||||||
|
Updated: time.Now(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cnt != 1 {
|
||||||
|
return ErrKeyNotExist{id}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// deletePublicKeys does the actual key deletion but does not update authorized_keys file.
|
// deletePublicKeys does the actual key deletion but does not update authorized_keys file.
|
||||||
func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
|
func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
|
||||||
if len(keyIDs) == 0 {
|
if len(keyIDs) == 0 {
|
||||||
|
|
Loading…
Reference in New Issue