mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-01 03:24:14 +08:00
fix: Modify the logic for adding hosts (#7976)
This commit is contained in:
parent
4087a7af3c
commit
ff32281257
@ -231,6 +231,14 @@ func (u *HostService) SearchForTree(search dto.SearchForTree) ([]dto.HostTree, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *HostService) Create(req dto.HostOperate) (*dto.HostInfo, error) {
|
func (u *HostService) Create(req dto.HostOperate) (*dto.HostInfo, error) {
|
||||||
|
if req.Name == "local" {
|
||||||
|
return nil, buserr.New("ErrRecordExist")
|
||||||
|
}
|
||||||
|
hostItem, _ := hostRepo.Get(hostRepo.WithByAddr(req.Addr), hostRepo.WithByUser(req.User), hostRepo.WithByPort(req.Port))
|
||||||
|
if hostItem.ID != 0 {
|
||||||
|
return nil, buserr.New("ErrRecordExist")
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if len(req.Password) != 0 && req.AuthMode == "password" {
|
if len(req.Password) != 0 && req.AuthMode == "password" {
|
||||||
req.Password, err = u.EncryptHost(req.Password)
|
req.Password, err = u.EncryptHost(req.Password)
|
||||||
@ -265,37 +273,6 @@ func (u *HostService) Create(req dto.HostOperate) (*dto.HostInfo, error) {
|
|||||||
host.GroupID = group.ID
|
host.GroupID = group.ID
|
||||||
req.GroupID = group.ID
|
req.GroupID = group.ID
|
||||||
}
|
}
|
||||||
var sameHostID uint
|
|
||||||
if req.Name == "local" {
|
|
||||||
hostSame, _ := hostRepo.Get(repo.WithByName("local"))
|
|
||||||
sameHostID = hostSame.ID
|
|
||||||
} else {
|
|
||||||
hostSame, _ := hostRepo.Get(hostRepo.WithByAddr(req.Addr), hostRepo.WithByUser(req.User), hostRepo.WithByPort(req.Port))
|
|
||||||
sameHostID = hostSame.ID
|
|
||||||
}
|
|
||||||
if sameHostID != 0 {
|
|
||||||
host.ID = sameHostID
|
|
||||||
upMap := make(map[string]interface{})
|
|
||||||
upMap["name"] = req.Name
|
|
||||||
upMap["group_id"] = req.GroupID
|
|
||||||
upMap["addr"] = req.Addr
|
|
||||||
upMap["port"] = req.Port
|
|
||||||
upMap["user"] = req.User
|
|
||||||
upMap["auth_mode"] = req.AuthMode
|
|
||||||
upMap["password"] = req.Password
|
|
||||||
upMap["private_key"] = req.PrivateKey
|
|
||||||
upMap["pass_phrase"] = req.PassPhrase
|
|
||||||
upMap["remember_password"] = req.RememberPassword
|
|
||||||
upMap["description"] = req.Description
|
|
||||||
if err := hostRepo.Update(sameHostID, upMap); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var hostinfo dto.HostInfo
|
|
||||||
if err := copier.Copy(&hostinfo, &host); err != nil {
|
|
||||||
return nil, buserr.WithDetail("ErrStructTransform", err.Error(), nil)
|
|
||||||
}
|
|
||||||
return &hostinfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := hostRepo.Create(&host); err != nil {
|
if err := hostRepo.Create(&host); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user