mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add check if public key name has been used
This commit is contained in:
@@ -67,11 +67,23 @@ type PublicKey struct {
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrKeyAlreadyExist = errors.New("Public key already exist")
|
||||
)
|
||||
|
||||
func GenAuthorizedKey(keyId int64, key string) string {
|
||||
return fmt.Sprintf(tmplPublicKey, appPath, keyId, key)
|
||||
}
|
||||
|
||||
func AddPublicKey(key *PublicKey) (err error) {
|
||||
// Check if public key name has been used.
|
||||
has, err := orm.Get(key)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
return ErrKeyAlreadyExist
|
||||
}
|
||||
|
||||
// Calculate fingerprint.
|
||||
tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
|
||||
"id_rsa.pub")
|
||||
|
Reference in New Issue
Block a user