fix: 网元信息读取host信息处理加密密钥

This commit is contained in:
TsMask
2024-08-14 10:16:42 +08:00
parent b0f7e73c2a
commit 6a94a7f39d
2 changed files with 113 additions and 14 deletions

View File

@@ -185,7 +185,17 @@ func (r *NeInfoImpl) bandNeHosts(arr *[]model.NeInfo) {
for i := range *arr {
v := (*arr)[i]
if v.HostIDs != "" {
(*arr)[i].Hosts = NewNeHostImpl.neHostRepository.SelectByIds(strings.Split(v.HostIDs, ","))
hostIds := strings.Split(v.HostIDs, ",")
if len(hostIds) <= 1 {
continue
}
for _, hostId := range hostIds {
neHost := NewNeHostImpl.SelectById(hostId)
if neHost.HostID == "" || neHost.HostID != hostId {
continue
}
(*arr)[i].Hosts = append((*arr)[i].Hosts, neHost)
}
}
}
}
@@ -199,12 +209,11 @@ func (r *NeInfoImpl) SelectById(infoId string, bandHost bool) model.NeInfo {
}
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
if len(neInfos) > 0 {
neInfo := neInfos[0]
// 带主机信息
if neInfo.HostIDs != "" && bandHost {
neInfo.Hosts = NewNeHostImpl.neHostRepository.SelectByIds(strings.Split(neInfo.HostIDs, ","))
if neInfos[0].HostIDs != "" && bandHost {
r.bandNeHosts(&neInfos)
}
return neInfo
return neInfos[0]
}
return model.NeInfo{}
}
@@ -312,12 +321,17 @@ func (r *NeInfoImpl) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
logger.Errorf("NeRunSSHClient NeType:%s NeID:%s hostId not found", neType, neId)
return nil, fmt.Errorf("neinfo hostId not found")
}
neInfo.Hosts = NewNeHostImpl.neHostRepository.SelectByIds(strings.Split(neInfo.HostIDs, ","))
if len(neInfo.Hosts) <= 0 {
logger.Errorf("NeRunSSHClient Hosts %s not found", neInfo.HostIDs)
hostIds := strings.Split(neInfo.HostIDs, ",")
if len(hostIds) <= 1 {
logger.Errorf("NeRunTelnetClient hosts id %s not found", neInfo.HostIDs)
return nil, fmt.Errorf("neinfo host id not found")
}
hostId := hostIds[0] // 网元主机ssh 022
neHost := NewNeHostImpl.SelectById(hostId)
if neHost.HostID == "" || neHost.HostID != hostId {
logger.Errorf("NeRunTelnetClient Hosts %s not found", neInfo.HostIDs)
return nil, fmt.Errorf("neinfo host not found")
}
neHost := neInfo.Hosts[0] // 网元主机ssh 022
if neHost.HostType != "ssh" {
logger.Errorf("NeRunSSHClient Hosts first HostType %s not ssh", neHost.HostType)
return nil, fmt.Errorf("neinfo host type not ssh")
@@ -369,12 +383,17 @@ func (r *NeInfoImpl) NeRunTelnetClient(neType, neId string, num int) (*telnet.Co
logger.Errorf("NeRunTelnetClient NeType:%s NeID:%s hostId not found", neType, neId)
return nil, fmt.Errorf("neinfo hostId not found")
}
neInfo.Hosts = NewNeHostImpl.neHostRepository.SelectByIds(strings.Split(neInfo.HostIDs, ","))
if len(neInfo.Hosts) <= 0 {
hostIds := strings.Split(neInfo.HostIDs, ",")
if len(hostIds) <= 1 {
logger.Errorf("NeRunTelnetClient hosts id %s not found", neInfo.HostIDs)
return nil, fmt.Errorf("neinfo host id not found")
}
hostId := hostIds[num] // 网元主机telnet 14100 25200
neHost := NewNeHostImpl.SelectById(hostId)
if neHost.HostID == "" || neHost.HostID != hostId {
logger.Errorf("NeRunTelnetClient Hosts %s not found", neInfo.HostIDs)
return nil, fmt.Errorf("neinfo host not found")
}
neHost := neInfo.Hosts[num]
// 创建链接Telnet客户端
var connTelnet telnet.ConnTelnet