Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor update ssh key use time #1466

Merged
merged 1 commit into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,7 @@ func runServ(c *cli.Context) error {

// Update user key activity.
if keyID > 0 {
key, err := models.GetPublicKeyByID(keyID)
if err != nil {
fail("Internal error", "GetPublicKeyById: %v", err)
}

key.Updated = time.Now()
if err = models.UpdatePublicKey(key); err != nil {
if err = models.UpdatePublicKeyUpdated(keyID); err != nil {
fail("Internal error", "UpdatePublicKey: %v", err)
}
}
Expand Down
14 changes: 14 additions & 0 deletions models/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,20 @@ func UpdatePublicKey(key *PublicKey) error {
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.
func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
if len(keyIDs) == 0 {
Expand Down