Add check if public key name has been used

This commit is contained in:
Unknown 2014-03-16 06:25:16 -04:00
parent ca956d5cec
commit fb960db6af
2 changed files with 16 additions and 0 deletions

View file

@ -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")