#1535 Removing deploy key does not remove key

tokarchuk/v1.17
Unknwon 9 years ago
parent 90f5b8edaf
commit 260301bf2e
  1. 22
      models/publickey.go
  2. 2
      models/user.go

@ -298,9 +298,13 @@ func saveAuthorizedKeyFile(keys ...*PublicKey) error {
return nil
}
// checkKeyContent onlys checks if key content has been used as public key,
// it is OK to use same key as deploy key for multiple repositories/users.
func checkKeyContent(content string) error {
// Same key can only be added once.
has, err := x.Where("content=?", content).Get(new(PublicKey))
has, err := x.Get(&PublicKey{
Content: content,
Type: KEY_TYPE_USER,
})
if err != nil {
return err
} else if has {
@ -440,10 +444,11 @@ func UpdatePublicKey(key *PublicKey) error {
return err
}
func deletePublicKey(e *xorm.Session, key *PublicKey) error {
func deletePublicKey(e *xorm.Session, keyID int64) error {
sshOpLocker.Lock()
defer sshOpLocker.Unlock()
key := &PublicKey{ID: keyID}
has, err := e.Get(key)
if err != nil {
return err
@ -451,7 +456,7 @@ func deletePublicKey(e *xorm.Session, key *PublicKey) error {
return nil
}
if _, err = e.Id(key.ID).Delete(key); err != nil {
if _, err = e.Id(key.ID).Delete(new(PublicKey)); err != nil {
return err
}
@ -467,8 +472,7 @@ func deletePublicKey(e *xorm.Session, key *PublicKey) error {
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
func DeletePublicKey(id int64) (err error) {
key := &PublicKey{ID: id}
has, err := x.Id(key.ID).Get(key)
has, err := x.Id(id).Get(new(PublicKey))
if err != nil {
return err
} else if !has {
@ -481,7 +485,7 @@ func DeletePublicKey(id int64) (err error) {
return err
}
if err = deletePublicKey(sess, key); err != nil {
if err = deletePublicKey(sess, id); err != nil {
return err
}
@ -658,7 +662,7 @@ func DeleteDeployKey(id int64) error {
return err
}
if _, err = sess.Id(key.ID).Delete(key); err != nil {
if _, err = sess.Id(key.ID).Delete(new(DeployKey)); err != nil {
return fmt.Errorf("delete deploy key[%d]: %v", key.ID, err)
}
@ -667,7 +671,7 @@ func DeleteDeployKey(id int64) error {
if err != nil {
return err
} else if !has {
if err = deletePublicKey(sess, &PublicKey{ID: key.KeyID}); err != nil {
if err = deletePublicKey(sess, key.KeyID); err != nil {
return err
}
}

@ -592,7 +592,7 @@ func DeleteUser(u *User) error {
return fmt.Errorf("get all public keys: %v", err)
}
for _, key := range keys {
if err = deletePublicKey(sess, key); err != nil {
if err = deletePublicKey(sess, key.ID); err != nil {
return fmt.Errorf("deletePublicKey: %v", err)
}
}

Loading…
Cancel
Save