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 } else if !has { return nil } if _, err = e.Id(key.ID).Delete(new(PublicKey)); err != nil { return err } // Don't need to rewrite this file if builtin SSH server is enabled. if setting.StartSSHServer { return nil } fpath := filepath.Join(setting.SSHRootPath, "authorized_keys") tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp") if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil { return err } else if err = os.Remove(fpath); err != nil { return err } return os.Rename(tmpPath, fpath) }
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 } else if !has { return nil } if _, err = e.Id(key.ID).Delete(new(PublicKey)); err != nil { return err } fpath := filepath.Join(SSHPath, "authorized_keys") tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp") if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil { return err } else if err = os.Remove(fpath); err != nil { return err } return os.Rename(tmpPath, fpath) }
//获取系统参数表 func GetValueFromSysConfig(txn *xorm.Session, key string) (models.SystemConfig, error) { var val models.SystemConfig val.Ename = key has, err := txn.Get(&val) if !has || !CheckError(err, "取系统参数失败") { log.Error("取系统参数失败:", key) return val, errors.New("failed") } return val, nil }
func deletePublicKey(e *xorm.Session, key *PublicKey) error { has, err := e.Get(key) if err != nil { return err } else if !has { return nil } if _, err = e.Id(key.ID).Delete(key); err != nil { return err } fpath := filepath.Join(SSHPath, "authorized_keys") tmpPath := filepath.Join(SSHPath, "authorized_keys.tmp") if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil { return err } else if err = os.Remove(fpath); err != nil { return err } return os.Rename(tmpPath, fpath) }