fix: License检查错误抛出到错误信息

This commit is contained in:
TsMask
2025-04-28 17:42:49 +08:00
parent 43b436c830
commit 18bd26c7a8
2 changed files with 18 additions and 10 deletions

View File

@@ -146,9 +146,13 @@ func (s *NeLicenseController) Code(c *gin.Context) {
}
// 更新授权码
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
neLicense.ActivationRequestCode = code
if licensePath != "" {
code, licensePath, err := s.neLicenseService.ReadLicenseInfo(neLicense)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
if code != "" && licensePath != "" {
neLicense.ActivationRequestCode = code
neLicense.LicensePath = licensePath
} else {
neLicense.SerialNum = ""
@@ -255,7 +259,11 @@ func (s *NeLicenseController) State(c *gin.Context) {
neLicense.Status = "1"
neLicense.SerialNum = fmt.Sprint(neState["sn"])
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
code, licensePath, err := s.neLicenseService.ReadLicenseInfo(neLicense)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
neLicense.ActivationRequestCode = code
neLicense.LicensePath = licensePath
} else {

View File

@@ -97,7 +97,7 @@ func (r *NeLicense) SelectByNeTypeAndNeID(neType, neId string) model.NeLicense {
// ReadLicenseInfo 读取授权文件信息
// 返回激活申请码, 激活文件
func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string) {
func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string, error) {
neTypeLower := strings.ToLower(neLicense.NeType)
// 网管本地路径
omcPath := "/usr/local/etc/omc/ne_license"
@@ -111,24 +111,24 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string)
// 网元主机的SSH客户端
sshClient, err := NewNeInfo.NeRunSSHClient(neLicense.NeType, neLicense.NeId)
if err != nil {
return "", ""
return "", "", err
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
return "", ""
return "", "", err
}
defer sftpClient.Close()
// 复制授权申请码到本地
if err = sftpClient.CopyFileRemoteToLocal(nePath+"/Activation_request_code.txt", omcPath+"/Activation_request_code.txt"); err != nil {
return "", ""
return "", "", fmt.Errorf("please check if scp remote copy is allowed")
}
// 读取文件内容
bytes, err := os.ReadFile(omcPath + "/Activation_request_code.txt")
if err != nil {
return "", ""
return "", "", fmt.Errorf("file read failure")
}
// 复制激活文件到本地
@@ -136,7 +136,7 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string)
if err = sftpClient.CopyFileRemoteToLocal(nePath+"/system.ini", omcPath+"/system.ini"); err == nil {
licensePath = omcPath + "/system.ini"
}
return strings.TrimSpace(string(bytes)), licensePath
return strings.TrimSpace(string(bytes)), licensePath, nil
}
// UploadLicense 授权文件上传到网元主机