diff --git a/conf/app.conf b/conf/app.conf index 016e2d3b0ba8048703aaa81e22e58823107575a9..218c75991c762caa96cc3d3415b1f9bd52552493 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -75,7 +75,7 @@ exceptcve = 0 3 19 * * * gensaflag = 2 gensa = 0 3 19 * * * issuestatisticflag = 2 -issuestatistic = 0 43 14 * * * +issuestatistic = 0 53 15 * * * cvecredflag = 2 cvecredit = 0 53 14 * * * urgenttaskflag = 2 diff --git a/conf/product_app.conf b/conf/product_app.conf index a3310636fbd20efdebac1808a128d9e2f18d01da..6ebdb554ab21a13175080d6f6961bc8be33fd58a 100644 --- a/conf/product_app.conf +++ b/conf/product_app.conf @@ -76,7 +76,7 @@ exceptcve = 0 0 4 * * * gensaflag = 1 gensa = 0 1 0 * * * issuestatisticflag = 1 -issuestatistic = 0 30 8 * * 1,3 +issuestatistic = 0 35 8 * * * cvecredflag = 1 cvecredit = 0 0 5 * * * urgenttaskflag = 1 diff --git a/cve-py/issue_statistics/to_email.xlsx b/cve-py/issue_statistics/to_email.xlsx index 1e3a906e8a8abf378d91f441fdb12b5cc348e0fd..9d5ced369808b0b11e80745974ad2b0704fd1326 100644 Binary files a/cve-py/issue_statistics/to_email.xlsx and b/cve-py/issue_statistics/to_email.xlsx differ diff --git a/task/genexcel.go b/task/genexcel.go index fdca3ff96b5e1e932e49c6af4006f6dd04cad185..48b92c2ac22816cacc2162426a6b42d52b59c021 100644 --- a/task/genexcel.go +++ b/task/genexcel.go @@ -3,39 +3,14 @@ package task import ( "cvevulner/common" "cvevulner/taskhandler" - "errors" - "github.com/astaxie/beego/config" "github.com/astaxie/beego/logs" ) //GenExcelData generate excel data func GenExcelData() error{ defer common.Catchs() - logs.Info("执行issue生成excel task start") - // 查询需要处理的cve, 1:新增;2:修改 - BConfig, err := config.NewConfig("ini", "conf/app.conf") - if err != nil{ - logs.Error("config init error:", err) - return err - } - forceRewrite, err := BConfig.Bool("excel::forcerewrite") - if err != nil{ - logs.Error("config excel::forcerewrite error: invalid value is ", forceRewrite) - return errors.New("value is nil") - } - snPrefix := BConfig.String("excel::snprefix") - if snPrefix == "" { - logs.Error("config excel::snprefix error: invalid value is ", snPrefix) - return errors.New("value is nil") - } - snSuffix, err := BConfig.Int64("excel::snsuffix") - if snSuffix == 0 || err != nil { - logs.Error("config excel::snsuffix error: invalid value is ", snSuffix) - return errors.New("value is nil") - } - //excelName := "openEuler." + common.GetCurDate() + ".xlsx" - //errx := taskhandler.GenerateCveExcel(excelName, snPrefix, snSuffix, forceRewrite) + logs.Info("Execute the task of checking whether cve has already released sa...") errx := taskhandler.GenerateExcelTask() - logs.Info("执行issue生成excel task end") + logs.Info("The task of executing to check whether cve has been released sa is over...") return errx } \ No newline at end of file diff --git a/task/grabissue.go b/task/grabissue.go index 6980137984fd591a41b26d0891936b283370b564..49b46c46e7660b5c2c85f50c23f50ee2c2ee00a1 100644 --- a/task/grabissue.go +++ b/task/grabissue.go @@ -12,8 +12,7 @@ import ( //GetIssueData get the issue data func GetIssueData() error{ defer common.Catchs() - logs.Info("获取已经创建的issue数据源 task start") - // 查询需要处理的cve, 1:新增;2:修改 + logs.Info("The task of getting the data source of the created issue starts...") BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil{ logs.Error("config init error:", err) @@ -26,10 +25,10 @@ func GetIssueData() error{ } giteeToken := os.Getenv("GITEE_TOKEN") if giteeToken == "" { - logs.Error("获取token失败, 无法获取issue任务") - return errors.New("获取token失败, 无法获取issue任务") + logs.Error("Failed to obtain token, unable to obtain issue task") + return errors.New("Failed to obtain token, unable to obtain issue task") } errx := taskhandler.GrabIssueByOrg(giteeToken, owner) - logs.Info("获取已经创建的issue数据源 task end") + logs.Info("The task of obtaining the data source of the created issue ends...") return errx } \ No newline at end of file diff --git a/task/issuetask.go b/task/issuetask.go index 21ab8bb3d39a6909cba2f2b4e22499e60fe91200..873e8ed111a37ab0344f414347ae68a8f7f1f257 100644 --- a/task/issuetask.go +++ b/task/issuetask.go @@ -17,38 +17,40 @@ import ( "time" ) +var mutex sync.Mutex + //GetGiteeToken Get Code Cloud API TOKEN func GetGiteeToken() error { defer common.Catchs() // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("GetGiteeToken, config init error:", err) return err } clientID := BConfig.String("gitee::client_id") if clientID == "" { - logs.Error("config gitee::clientID error: invalid value is ", clientID) + logs.Error("GetGiteeToken, config gitee::clientID ,error: invalid value") return errors.New("value is nil") } clientSecret := beego.AppConfig.String("gitee::client_secret") if clientSecret == "" { - logs.Error("config gitee::clientSecret error: invalid value is ", clientSecret) + logs.Error("GetGiteeToken, config gitee::clientSecret, error: invalid value") return errors.New("value is nil") } Email := BConfig.String("gitee::email") if Email == "" { - logs.Error("config gitee::email error: value is nil") + logs.Error("GetGiteeToken, config gitee::email, error: value is nil") return errors.New("value is nil") } password := BConfig.String("gitee::password") if password == "" { - logs.Error("config gitee::password error: value is nil") + logs.Error("GetGiteeToken, config gitee::password, error: value is nil") return errors.New("value is nil") } Scope := BConfig.String("gitee::scope") if Scope == "" { - logs.Error("config gitee::scope error: value is nil") + logs.Error("GetGiteeToken, config gitee::scope, error: value is nil") return errors.New("value is nil") } logs.Info(clientID, clientSecret, password) @@ -82,7 +84,7 @@ func ErrorCveStatistics(errDesc string, issueValue models.VulnCenter, status int if issueValue.OrganizationID != 2 { sc, err := models.QueryIssueScore(issueValue.CveId) if err != nil || sc.Id == 0 { - logs.Error("获取Score 失败, err: ", err, "cveId: ", issueValue.CveId) + logs.Error("ErrorCveStatistics, Failed to get Score, err: ", err, ", cveId: ", issueValue.CveId) return } icr := models.IssueCreateRecord{ErrorDescription: errDesc} @@ -91,17 +93,15 @@ func ErrorCveStatistics(errDesc string, issueValue models.VulnCenter, status int if issReErr == nil && issueRecordId > 0 { logs.Info("Issue record data created successfully, id:", issueRecordId) } else { - logs.Error("Failed to create issue record data, err: ", issReErr) + logs.Error("ErrorCveStatistics, Failed to create issue record data, err: ", issReErr) } } } -var mutex sync.Mutex - func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears int) error { accessToken := os.Getenv("GITEE_TOKEN") if accessToken == "" || len(accessToken) < 1 { - logs.Error("issue token Get failed, current time: ", common.GetCurTime()) + logs.Error("addUnlimitedIssue, issue token Get failed, current time: ", common.GetCurTime()) return errors.New("Failed to get token in environment variable") } owner := beego.AppConfig.String("gitee::owner") @@ -114,15 +114,15 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears ss := rand.Int31n(10) time.Sleep(time.Second * time.Duration(ss)) } else { - logs.Info("No cve data can be used, current time: ", common.GetCurTime(), ", err: ", err) + logs.Info("addUnlimitedIssue, No cve data can be used, current time: ", common.GetCurTime(), ", err: ", err) return err } for index, issueValue := range cveData { - logs.Info("Currently processing:", index, ",cve data, cveNum: ", issueValue.CveNum) + logs.Info("addUnlimitedIssue, Currently processing:", index, ",cve data, cveNum: ", issueValue.CveNum) // add mutex lockErr := models.LockUpdateIssueStatus(issueValue.CveId, issueValue.CveNum, 15) if !lockErr { - logs.Error("The current cve is processing, continue to process the next data, "+ + logs.Error("addUnlimitedIssue, The current cve is processing, continue to process the next data, "+ "err: ", lockErr, ",data: ", issueValue) continue } @@ -130,7 +130,8 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears seError := models.GetIssueSpecErrByColName(&se, "CveNum", "Owner", "PackName", "Status") if seError == nil && se.Id > 0 { models.UpdateIssueStatus(issueValue, 5) - logs.Info("The current issue does not need to be processed, it has been processed, cveData: ", issueValue) + logs.Info("addUnlimitedIssue, The current issue does not need to be processed, "+ + "it has been processed, cveData: ", issueValue) ErrorCveStatistics("CVE已经归档无需处理", issueValue, 1) continue } @@ -140,7 +141,8 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears if strings.ToLower(goi.State) == "closed" || strings.ToLower(goi.State) == "rejected" || goi.State == "已完成" || goi.State == "已拒绝" || goi.IssueState == "已挂起" { models.UpdateIssueStatus(issueValue, 2) - logs.Info("The cve data has already been submitted to the issue, no need to submit repeatedly, cveData: ", issueValue) + logs.Info("addUnlimitedIssue, The cve data has already been submitted to the issue, "+ + "no need to submit repeatedly, cveData: ", issueValue) ErrorCveStatistics("CVE已创建过issue, 且已归档", issueValue, 1) continue } @@ -157,7 +159,7 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears } if cveYears <= years { models.UpdateIssueStatus(issueValue, 4) - logs.Info("cve: ", issueValue.CveNum, ",Need to be greater than: ", + logs.Info("addUnlimitedIssue, cve: ", issueValue.CveNum, ",Need to be greater than: ", years, ",Otherwise, there is no need to submit an issue on git, cveData: ", issueValue) if issueValue.OrganizationID != 2 { ErrorCveStatistics("CVE年限受限", issueValue, 2) @@ -170,7 +172,7 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears issueExist := taskhandler.GetCveSecurityNotice(issueValue.CveNum) if issueExist { models.UpdateIssueStatus(issueValue, 2) - logs.Info("The cve data has been displayed on the official website, "+ + logs.Info("addUnlimitedIssue, The cve data has been displayed on the official website, "+ "no need to submit an issue on git, cveData: ", issueValue) ErrorCveStatistics("CVE已经在官网展示, 已修复", issueValue, 1) continue @@ -182,7 +184,8 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears err := ProcIssue(issueValue, accessToken, owner, gaussOwner, gitGaussToken) mutex.Unlock() if err != nil { - logs.Error("Failed to create issue, cvenum: ", issueValue.CveNum, "err,err: ", err) + logs.Error("addUnlimitedIssue, Failed to create issue, cvenum: ", + issueValue.CveNum, "err,err: ", err) errDesc := fmt.Sprintf("%v", err) ErrorCveStatistics(errDesc, issueValue, 2) continue @@ -193,7 +196,8 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears err := ProcUpdateIssue(issueValue, accessToken, owner) mutex.Unlock() if err != nil { - logs.Error("Failed to update issue, cvenum: ", issueValue.CveNum, "err,err: ", err) + logs.Error("addUnlimitedIssue, Failed to update issue, cvenum: ", + issueValue.CveNum, "err,err: ", err) errDesc := fmt.Sprintf("%v", err) ErrorCveStatistics(errDesc, issueValue, 2) continue @@ -210,7 +214,8 @@ func addUnlimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears int) error { accessToken := os.Getenv("GITEE_TOKEN") if accessToken == "" || len(accessToken) < 1 { - logs.Error("issue token 获取失败, 当前时间: ", common.GetCurTime()) + logs.Error("addLimitedIssue, Issue token acquisition failed, "+ + "current time: ", common.GetCurTime()) return errors.New("Failed to get token in environment variable") } owner := beego.AppConfig.String("gitee::owner") @@ -220,7 +225,7 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i if issueErr == nil && len(issueWhiteData) > 0 { for _, issues := range issueWhiteData { if issues.Status == 2 { - logs.Error("Removed from whitelist, repo: ", issues.PackageName) + logs.Error("addLimitedIssue, Removed from whitelist, repo: ", issues.PackageName) continue } for ; ; { @@ -230,15 +235,17 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i ss := rand.Int31n(10) time.Sleep(time.Second * time.Duration(ss)) } else { - logs.Info("无cve数据可以使用, 当前时间: ", common.GetCurTime(), ", err: ", err) + logs.Info("addLimitedIssue, No cve data can be used, "+ + "current time: ", common.GetCurTime(), ", err: ", err) break } for index, issueValue := range cveData { - logs.Info("当前正在处理第:", index, "条cve数据, cveNum: ", issueValue.CveNum) + logs.Info("addLimitedIssue, Currently processing section: ", index, + ", Cve data, cveNum: ", issueValue.CveNum) // add mutex lockErr := models.LockUpdateIssueStatus(issueValue.CveId, issueValue.CveNum, 15) if !lockErr { - logs.Error("The current cve is processing, continue to"+ + logs.Error("addLimitedIssue, The current cve is processing, continue to"+ " process the next data, err: ", lockErr, ",data: ", issueValue) continue } @@ -247,7 +254,7 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i seError := models.GetIssueSpecErrByColName(&se, "CveNum", "Owner", "PackName", "Status") if seError == nil && se.Id > 0 { models.UpdateIssueStatus(issueValue, 5) - logs.Info("The current issue does not need to be processed,"+ + logs.Info("addLimitedIssue, The current issue does not need to be processed,"+ " it has been processed, cveData: ", issueValue) ErrorCveStatistics("CVE已经归档无需处理", issueValue, 1) continue @@ -258,7 +265,8 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i if strings.ToLower(goi.State) == "closed" || strings.ToLower(goi.State) == "rejected" || goi.State == "已完成" || goi.State == "已拒绝" || goi.IssueState == "已挂起" { models.UpdateIssueStatus(issueValue, 2) - logs.Info("cve数据已经已经提交过issue,不需要重复提交, cveData: ", issueValue) + logs.Info("addLimitedIssue, The cve data has already been submitted to the issue, "+ + "no need to submit repeatedly, cveData: ", issueValue) ErrorCveStatistics("CVE已创建过issue, 且已归档", issueValue, 1) continue } @@ -275,8 +283,8 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i } if cveYears <= years { models.UpdateIssueStatus(issueValue, 4) - logs.Info("cve: ", issueValue.CveNum, ",需要大于: ", - years, ",否则不需要在git上提交issue, cveData: ", issueValue) + logs.Info("addLimitedIssue, cve: ", issueValue.CveNum, ",Need to be greater than: ", + years, ", Otherwise there is no need to submit an issue on git, cveData: ", issueValue) if issueValue.OrganizationID != 2 { ErrorCveStatistics("CVE年限受限", issueValue, 2) } @@ -288,7 +296,8 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i issueExist := taskhandler.GetCveSecurityNotice(issueValue.CveNum) if issueExist { models.UpdateIssueStatus(issueValue, 2) - logs.Info("cve数据已经在官网上展示过,不需要在git上提交issue, cveData: ", issueValue) + logs.Info("addLimitedIssue, The cve data has been displayed on the official website, "+ + "no need to submit an issue on git, cveData: ", issueValue) ErrorCveStatistics("CVE已经在官网展示, 已修复", issueValue, 1) continue } @@ -298,7 +307,8 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i err := ProcIssue(issueValue, accessToken, owner, gaussOwner, gitGaussToken) mutex.Unlock() if err != nil { - logs.Error("创建issue失败, cvenum: ", issueValue.CveNum, "err,err: ", err) + logs.Error("addLimitedIssue, Failed to create issue, cvenum: ", + issueValue.CveNum, ",err: ", err) errDesc := fmt.Sprintf("%v", err) ErrorCveStatistics(errDesc, issueValue, 2) continue @@ -308,7 +318,8 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i err := ProcUpdateIssue(issueValue, accessToken, owner) mutex.Unlock() if err != nil { - logs.Error("修改issue失败, cvenum: ", issueValue.CveNum, "err,err: ", err) + logs.Error("addLimitedIssue, Failed to modify the issue, cvenum: ", + issueValue.CveNum, "err,err: ", err) errDesc := fmt.Sprintf("%v", err) ErrorCveStatistics(errDesc, issueValue, 2) continue @@ -331,53 +342,53 @@ func addLimitedIssue(beforeTime string, prcnum int, years, toolYears, manYears i //CreateIssue Create issue func CreateIssue() error { defer common.Catchs() - logs.Info("执行创建issue task start") + logs.Info("The issue task of creating cve begins. . .") // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("CreateIssue, config init, error:", err) return err } days, ok := BConfig.Int("crontab::days") if ok != nil { - logs.Error("config crontab::days error:", ok) + logs.Error("CreateIssue, config crontab::days, error:", ok) return ok } years, ok := BConfig.Int("cve::cve_number") if ok != nil { - logs.Error("config cve::years error:", ok) + logs.Error("CreateIssue, config cve::years, error:", ok) return ok } manYears, ok := BConfig.Int("cve::cve_number_m") if ok != nil { - logs.Error("config cve::manYears error:", ok) + logs.Error("CreateIssue, config cve::manYears, error:", ok) return ok } toolYears, ok := BConfig.Int("cve::cve_number_t") if ok != nil { - logs.Error("config cve::toolYears error:", ok) + logs.Error("CreateIssue, config cve::toolYears, error:", ok) return ok } prcnum, ok := BConfig.Int("crontab::prcnum") if ok != nil { - logs.Error("config crontab::prcnum error:", ok) + logs.Error("CreateIssue, config crontab::prcnum, error:", ok) return ok } issueWhitelist, ok := BConfig.Int("cve::issue_whitelist") if ok != nil { - logs.Error("config cve::issue_whitelist error: ", ok) + logs.Error("CreateIssue, config cve::issue_whitelist, error: ", ok) return ok } beforeTime := common.GetBeforeTime(days) if issueWhitelist == 1 { limitErr := addLimitedIssue(beforeTime, prcnum, years, toolYears, manYears) - logs.Info("addLimitedIssue, err: ", limitErr) - logs.Info("执行创建issue task end") + logs.Info("CreateIssue, addLimitedIssue, err: ", limitErr) + logs.Info("The execution of the issue task of creating cve ends. . .") return limitErr } else { unlimitErr := addUnlimitedIssue(beforeTime, prcnum, years, toolYears, manYears) - logs.Info("addUnlimitedIssue, err: ", unlimitErr) - logs.Info("执行创建issue task end") + logs.Info("CreateIssue, addUnlimitedIssue, err: ", unlimitErr) + logs.Info("The execution of the issue task of creating cve ends. . .") return unlimitErr } } @@ -388,10 +399,12 @@ func ProcUpdateIssue(issueValue models.VulnCenter, accessToken, owner string) er // Query and modify score sr, err := models.QueryIssueScoreRecord(issueValue.CveId, 0) if err != nil { - logs.Error("Failed to query score records, cveId: ", issueValue.CveId, "err: ", err) + logs.Error("ProcUpdateIssue, Failed to query score records, cveId: ", + issueValue.CveId, ", err: ", err) sc, err := models.QueryIssueScore(issueValue.CveId) if err != nil { - logs.Error("获取Score 失败, err: ", err, "cveId: ", issueValue.CveId) + logs.Error("ProcUpdateIssue, Failed to get Score, err: ", + err, ", cveId: ", issueValue.CveId) return errors.New("NVD评分缺失") } sr.NVDScore = sc.NVDScore @@ -417,8 +430,9 @@ func ProcUpdateIssue(issueValue models.VulnCenter, accessToken, owner string) er it.Assignee = assignee //return err } else { - logs.Error("获取仓库: owner:", owner, "path:", path, "分析人失败", "assErr:", assErr, - ", cveid: ", issueValue.CveId, ",创建无maintainer的issue") + logs.Error("ProcUpdateIssue, Get the repo: owner:", owner, + ", path:", path, ", Analyst failed, ", "assErr:", assErr, + ", cveid: ", issueValue.CveId, ", Create an issue without a maintainer") } } else { it.Assignee = repoMainTainer @@ -427,7 +441,7 @@ func ProcUpdateIssue(issueValue models.VulnCenter, accessToken, owner string) er // Judgment of necessary fields if it.NVDScore <= 0 || len(issueValue.Description) < 2 || len(issueValue.CveNum) < 2 || len(issueValue.PackName) < 2 || len(issueValue.CveVersion) < 1 { - logs.Error("Field is empty: NVDScore: ", it.NVDScore, ",Description: ", + logs.Error("ProcUpdateIssue, Field is empty: NVDScore: ", it.NVDScore, ",Description: ", issueValue.Description, ",CveNum:", issueValue.CveNum, ",PackName: ", issueValue.PackName, ",CveVersion: ", issueValue.CveVersion) // Update issue status @@ -437,7 +451,8 @@ func ProcUpdateIssue(issueValue models.VulnCenter, accessToken, owner string) er _, err := taskhandler.UpdateIssueToGit(accessToken, owner, path, issueValue, it) if err != nil && err.Error() != "Recreate issue" { - logs.Error("更新issue 模板失败, cveId: ", issueValue.CveId, "err: ", err) + logs.Error("ProcUpdateIssue, Failed to update issue template, "+ + "cveId: ", issueValue.CveId, "err: ", err) // Update issue status models.UpdateIssueStatus(issueValue, 3) return err @@ -448,11 +463,13 @@ func ProcUpdateIssue(issueValue models.VulnCenter, accessToken, owner string) er models.UpdateIssueScore(issueValue, 2) templetID, err := models.CreateIssueTemplate(&it) if err != nil { - logs.Error("修改issue模板失败, cveId: ", issueValue.CveId, "err: ", err) + logs.Error("ProcUpdateIssue, Failed to modify issue template, "+ + "cveId: ", issueValue.CveId, ",err: ", err) //return err } models.UpdateIssueScoreRe(issueValue, 1) - logs.Info("更新issue模板成功,cveId: ", issueValue.CveId, "templetID: ", templetID) + logs.Info("ProcUpdateIssue, Successfully updated the issue template, "+ + "cveId: ", issueValue.CveId, ", templetID: ", templetID) } return nil } @@ -466,25 +483,25 @@ func ProcIssue(issueValue models.VulnCenter, if issueValue.OrganizationID != 2 { sn, err := models.QueryIssueSecurity(issueValue.CveId, issueValue.CveNum) if err == nil && len(sn.CveNum) > 0 { - logs.Info("查询安全信息:sn: ", sn) + logs.Info("ProcIssue, QueryIssueSecurity, Query safety information: ", sn) // Get issue handler repoMainTainer, ok := models.QueryRepoMaintainer(issueValue.PackName) if !ok || repoMainTainer == "" || len(repoMainTainer) < 1 { assignee, err = taskhandler.GetCollaboratorInfo(accessToken, owner, path) if assignee == "" { - logs.Error("获取仓库: owner:", owner, "path:", path, "分析人失败", "err:", err, - "cveid: ", issueValue.CveId, ",创建无maintainer的issue") + logs.Error("ProcIssue, Get the repo: owner:", owner, ",path:", path, ",Analyst failed", + ", cveid: ", issueValue.CveId, ",Create an issue without a maintainer", ", err:", err) } } else { assignee = repoMainTainer } } else { - logs.Error("获取security 失败, err: ", err, "cveId: ", issueValue.CveId) + logs.Error("ProcIssue, Failed to obtain security", ", cveId: ", issueValue.CveId, ", err: ", err) return errors.New("CVE描述缺失") } sc, err := models.QueryIssueScore(issueValue.CveId) if err != nil { - logs.Error("获取Score 失败, err: ", err, "cveId: ", issueValue.CveId) + logs.Error("ProcIssue, Failed to get Score, err: ", err, ", cveId: ", issueValue.CveId) return errors.New("NVD评分缺失") } branchList := []string{} @@ -492,7 +509,8 @@ func ProcIssue(issueValue models.VulnCenter, // Get branch information branchList, errBrands = taskhandler.GetBranchesInfo(accessToken, owner, path) if branchList == nil || len(branchList) == 0 { - logs.Error("获取分支信息失败,CveNum: ", issueValue.CveNum, "path: ", path, ", err: ", errBrands) + logs.Error("ProcIssue, Failed to obtain branch information,CveNum: ", issueValue.CveNum, + ", path: ", path, ", err: ", errBrands) } if len(branchList) > 0 { brandArry = []string{} @@ -518,7 +536,7 @@ func ProcIssue(issueValue models.VulnCenter, } // Judgment of necessary fields if legalFlag { - logs.Error("Field is empty: NVDScore: ", sc.NVDScore, ",Description: ", + logs.Error("ProcIssue, Field is empty: NVDScore: ", sc.NVDScore, ",Description: ", issueValue.Description, ",CveNum:", issueValue.CveNum, ",PackName: ", issueValue.PackName, ",CveVersion: ", issueValue.CveVersion) // Update issue status @@ -527,7 +545,7 @@ func ProcIssue(issueValue models.VulnCenter, } resp, err := taskhandler.CreateIssueToGit(accessToken, owner, path, assignee, issueValue, sc, brandArry) if err != nil && err.Error() != "Recreate issue" { - logs.Error("创建issue失败, err: ", err, "resp: ", resp, "cveId: ", issueValue.CveId) + logs.Error("ProcIssue, Failed to create issue, err: ", err, ",resp: ", resp, ",cveId: ", issueValue.CveId) // Update issue status models.UpdateIssueStatus(issueValue, 3) return err @@ -535,13 +553,13 @@ func ProcIssue(issueValue models.VulnCenter, } else { sc, err := models.QueryIssueScore(issueValue.CveId) if err != nil { - logs.Error("获取Score 失败, err: ", err, "cveId: ", issueValue.CveId) + logs.Error("ProcIssue, Failed to get Score, err: ", err, ", cveId: ", issueValue.CveId) return err } // Judgment of necessary fields if sc.NVDScore <= 0 || len(issueValue.Description) < 2 || len(issueValue.CveNum) < 2 || len(issueValue.PackName) < 2 || len(issueValue.CveVersion) < 1 { - logs.Error("Field is empty: NVDScore: ", sc.NVDScore, ",Description: ", + logs.Error("ProcIssue, Field is empty: NVDScore: ", sc.NVDScore, ",Description: ", issueValue.Description, ",CveNum:", issueValue.CveNum, ",PackName: ", issueValue.PackName, ",CveVersion: ", issueValue.CveVersion) // Update issue status @@ -551,7 +569,8 @@ func ProcIssue(issueValue models.VulnCenter, path = "security" resp, err := taskhandler.CreateIssueToGit(gitGaussToken, gaussOwner, path, assignee, issueValue, sc, brandArry) if err != nil && err.Error() != "Recreate issue" { - logs.Error("创建issue失败, err: ", err, "resp: ", resp, "cveId: ", issueValue.CveId) + logs.Error("ProcIssue, Failed to create issue, err: ", err, + ",resp: ", resp, ",cveId: ", issueValue.CveId) // Update issue status models.UpdateIssueStatus(issueValue, 3) return err diff --git a/task/oricvecheck.go b/task/oricvecheck.go index 8d236ed40bd2271dcdc7858f1037ef93ed5df109..65896ffe1e6fdc5f4f13616ce7aaf8e7439ee268 100644 --- a/task/oricvecheck.go +++ b/task/oricvecheck.go @@ -13,29 +13,29 @@ import ( //CheckOriCve Check the CVE of the original data func CheckOriCve() error { defer common.Catchs() - logs.Info("校验原始cve数据 task start") + logs.Info("The task of verifying the original cve data starts...") // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("CheckOriCve, config init, error:", err) return err } // The amount of data processed at a time prcNum, err := BConfig.Int("crontab::prcnum") if err != nil { - logs.Error("config crontab::prcnum error: invalid value is ", prcNum) + logs.Error("CheckOriCve, config crontab::prcnum, error: invalid value") return errors.New("value is nil") } // Get the data source of the table _, err = taskhandler.CheckCveOriginData(prcNum) - logs.Info("校验原始cve数据 task end") + logs.Info("End of verifying original cve data task...") return err } // Unlock database table data func UnLockTable() error { defer common.Catchs() - logs.Info("执行解锁表 task start") + logs.Info("Execute unlock table task start...") // unlock center models.UnLockUpdateIssueStatus(15, 0, common.GetCurTime()) // unlock origin cve @@ -44,34 +44,34 @@ func UnLockTable() error { models.UnLockUpdateOriginStatus(15, 0, common.GetCurTime()) // unlock excel models.UnLockUpdateOriginExcelStatus(15, 0, common.GetCurTime()) - logs.Info("执行解锁表 task end") + logs.Info("Execute unlock table End of task...") return nil } // Cve handles abnormal data reprocessing func ProcAbnCve() error { defer common.Catchs() - logs.Info("纠正cve数据 task start") + logs.Info("Correct the cve data and start the task...") // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("ProcAbnCve, config init, error:", err) return err } // The amount of data processed at a time prcNum, err := BConfig.Int("crontab::prcnum") if err != nil { - logs.Error("config crontab::prcnum error: invalid value is ", prcNum) + logs.Error("ProcAbnCve, config crontab::prcnum, error: invalid value") return errors.New("value is nil") } days, err := BConfig.Int("crontab::days") if err != nil { - logs.Error("config crontab::days error: invalid value is ", days) + logs.Error("ProcAbnCve, config crontab::days, error: invalid value") return errors.New("value is nil") } cveStatuStr := BConfig.String("cve::abn_cve_status") if cveStatuStr == "" { - logs.Error("config cve::abn_cve_status error: invalid value is ", cveStatuStr) + logs.Error("ProcAbnCve, config cve::abn_cve_status error: invalid value") return errors.New("value is nil") } st := strings.Split(cveStatuStr, ",") @@ -81,28 +81,28 @@ func ProcAbnCve() error { cveSt := strings.Join(st, ",") // Get the data source of the table _, err = taskhandler.UpdateAbnCveStatus(prcNum, days, cveSt) - logs.Info("纠正cve数据 task end") + logs.Info("Correct cve data End of task...") return err } // Generate a certain number of SA numbers each time func ProcSaNumber() error { defer common.Catchs() - logs.Info("Generate SA number task start") + logs.Info("Generate SA number task start...") // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("ProcSaNumber, config init, error:", err) return err } // The amount of data processed at a time saReAmount, err := BConfig.Int64("cve::sa_re_amount") if err != nil { - logs.Error("config cve::sa_re_amount error: invalid value is ", saReAmount) + logs.Error("ProcSaNumber, config cve::sa_re_amount, error: invalid value") return errors.New("value is nil") } // Get the data source of the table _, err = taskhandler.AddSaNumber(saReAmount) - logs.Info("Generate SA number task end") + logs.Info("Generate SA number task end...") return err } diff --git a/task/printlog.go b/task/printlog.go index 5f1afe6154069073d8423ce6739e7b8c55765173..e754a82a1bd449c6a4869ea70c54035a3a494d8b 100644 --- a/task/printlog.go +++ b/task/printlog.go @@ -12,12 +12,12 @@ import ( func DeletLogs() error { BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("DeletLogs, config init, error:", err) return err } logDir := BConfig.String("log::log_dir") if logDir == "" { - logs.Error("config excel::log_dir error: invalid value is ", logDir) + logs.Error("DeletLogs, config excel::log_dir, error: invalid value") return errors.New("value is nil") } fileInfoList, err := ioutil.ReadDir(logDir) @@ -30,7 +30,7 @@ func DeletLogs() error { if fileInfoList[i].Name() != "cve.log" { err := os.Remove(logDir + "/" + fileInfoList[i].Name()) if err != nil { - logs.Error("删除文件失败: ", fileInfoList[i].Name()) + logs.Error("Failed to delete file: ", fileInfoList[i].Name()) } } } @@ -39,12 +39,12 @@ func DeletLogs() error { // ProcLogData Processing log func ProcLogData() error { - logs.Info("创建日志任务 task start") + logs.Info("Create log task starts") // delete logs err := DeletLogs() if err != nil { logs.Error(err) } - logs.Info("创建日志任务 task end") + logs.Info("End of log creation task") return err } diff --git a/task/urgent.go b/task/urgent.go index c50e634b2d3bb7a757b8a6a81a7051c06f197bc8..8270e235423a849a02c3c95d7d2bac053bb47b45 100644 --- a/task/urgent.go +++ b/task/urgent.go @@ -15,32 +15,32 @@ func SynchronizeExcelData() error { // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init, error: ", err) + logs.Error("SynchronizeExcelData, config init, error: ", err) return err } // The amount of data processed at a time prcNum, err := BConfig.Int("crontab::prcnum") if err != nil { - logs.Error("crontab::prcnum, error: ", err) + logs.Error("SynchronizeExcelData, crontab::prcnum, error: ", err) return errors.New("value is nil") } // How many days have been processed to date data days, ok := BConfig.Int("crontab::days") if ok != nil { - logs.Error("crontab::days, err:", err) + logs.Error("SynchronizeExcelData, crontab::days, err:", err) return ok } // openeuler Number start value cveRef := BConfig.String("cve::cveref") openeulerNum, ok := BConfig.Int("cve::openeulernum") if ok != nil { - logs.Error("cve::openeulernum, err:", err) + logs.Error("SynchronizeExcelData, cve::openeulernum, err:", err) return ok } // Processing excel raw data okx, err := taskhandler.GetCveOriginExcelData(prcNum, days, openeulerNum, cveRef) if !okx { - logs.Error("ProcCveOriginData, GetCveOriginExcelData, err: ", err) + logs.Error("SynchronizeExcelData, GetCveOriginExcelData, err: ", err) return err } return nil diff --git a/task/yaml.go b/task/yaml.go index cd37b16126a901f88dabf1fb00197722ed12790e..2c1ad1538260a1f0134948acd30aa3ba0cfe27dc 100644 --- a/task/yaml.go +++ b/task/yaml.go @@ -11,16 +11,16 @@ import ( // GetYamlData Get yaml data source func GetYamlData() error { defer common.Catchs() - logs.Info("获取yaml数据源 task start") + logs.Info("Get the yaml data source task started") // Query the cve to be processed, 1: add; 2: modify BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("GetYamlData, config init, error:", err) return err } apiUrl := BConfig.String("yaml::apiurl") if apiUrl == "" { - logs.Error("config yaml::apiurl error: invalid value is ", apiUrl) + logs.Error("GetYamlData, config yaml::apiurl, error: invalid value") return errors.New("value is nil") } // Get the data source of the table @@ -29,6 +29,6 @@ func GetYamlData() error { if err == nil { _, err = taskhandler.GetYamlByGit(apiUrl) } - logs.Info("获取yaml数据源 task end") + logs.Info("End of the task of obtaining yaml data source") return err } diff --git a/taskhandler/assist.go b/taskhandler/assist.go index 2be2cbc59ddaebeacefe20ffffc4aba5739b97c5..986523274e66099e2303f453dc00ca99cd2ea3de 100644 --- a/taskhandler/assist.go +++ b/taskhandler/assist.go @@ -21,7 +21,8 @@ func GetOautToken(gt GiteeToken) { req.Data["scope"] = gt.Scope resp, err := util.PostURLEncoded(req) if err != nil { - logs.Error("获取 token 失败,url: ", url, "请求参数:", gt, "err:", err) + logs.Error("Failed to obtain token,url: ", url, + ",Request parameter: ", gt, ", err:", err) return } var respDict map[string]interface{} @@ -31,7 +32,7 @@ func GetOautToken(gt GiteeToken) { return } if _, ok := respDict["access_token"]; !ok { - logs.Error("获取token失败, err: ", ok, "url: ", url) + logs.Error("Failed to obtain token, err: ", ok, ", url: ", url) return } GitToken := respDict["access_token"].(string) @@ -68,7 +69,7 @@ func GetCollaboratorInfo(accessToken string, owner string, path string) (string, } } } else { - logs.Error("获取仓库责任人失败, owner:", owner, "path:", path, "err: ", err) + logs.Error("Failed to obtain repo owner, owner:", owner, ",path:", path, ",err: ", err) return "", err } } @@ -96,7 +97,8 @@ func GetBranchesInfo(accessToken string, owner string, path string) ([]string, e } } } else { - logs.Error("获取分支名称失败, err: ", err, "owner: ", owner, "path: ", path) + logs.Error("Failed to get branch name, " + + "err: ", err, ",owner: ", owner, ",path: ", path) return branchNameList, err } } diff --git a/taskhandler/comment.go b/taskhandler/comment.go index 597e2d5764c33a6aafd5a7618a0757856cf91167..d61b9ece05d306367c07a0f72799f792c215173a 100644 --- a/taskhandler/comment.go +++ b/taskhandler/comment.go @@ -14,7 +14,7 @@ func AddCommentToIssue(msg, issueNum, owner, repo, access string) { if err != nil { logs.Error(err) } - logs.Info("添加评论返回:", res) + logs.Info("Add comment back:", res) } //SendPrivateLetters Send a private message to a gitee user @@ -25,5 +25,5 @@ func SendPrivateLetters(access, content, useName string) { if err != nil { logs.Error(err) } - logs.Info("发送私信:", res) + logs.Info("Send private message:", res) } diff --git a/taskhandler/createissue.go b/taskhandler/createissue.go index 5d0305a98ff3130d4b16a6ffec14c3e8252669f2..f2809f03165037ed31fba3a69d661d4769e80c14 100644 --- a/taskhandler/createissue.go +++ b/taskhandler/createissue.go @@ -17,18 +17,13 @@ import ( var updateLock sync.Mutex -func CreateIssueData(issueTemp *models.IssueTemplate, cve models.VulnCenter, sc models.Score, resp map[string]interface{}, +func CreateIssueData(issueTemp *models.IssueTemplate, cve models.VulnCenter, + sc models.Score, resp map[string]interface{}, path, assignee, issueType, labels, owner string) { issueTemp.CveId = cve.CveId issueTemp.CveNum = cve.CveNum issueTemp.OwnedComponent = path issueTemp.OwnedVersion = cve.CveVersion - //err := models.GetIssueTemplateByColName(issueTemp, "cve_id", "cve_num", "owned_component") - //if err != nil || issueTemp.TemplateId == 0{ - // logs.Info(err) - // issueTemp.MtAuditFlag = 0 - // issueTemp.SaAuditFlag = 0 - //} if issueTemp.TemplateId == 0 { issueTemp.MtAuditFlag = 1 issueTemp.SaAuditFlag = 0 @@ -85,7 +80,7 @@ func CreateIssueData(issueTemp *models.IssueTemplate, cve models.VulnCenter, sc issueTemp.Milestone = "" issueTemp.Program = "" issueTemp.SecurityHole = 0 - logs.Info("组装issue,模板数据存入db: ", issueTemp) + logs.Info("CreateIssueData, Assemble issue, store template data in db: ", issueTemp) } func GetIssueNum(accessToken, owner, path, issueNum string) error { @@ -103,7 +98,7 @@ func GetIssueNum(accessToken, owner, path, issueNum string) error { return nil } } else { - logs.Error("http 请求失败, url: ", url) + logs.Error("GetIssueNum, http request failed, url: ", url) return err } } @@ -168,31 +163,35 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, requestBody := CreateIssueBody(accessToken, owner, path, it.Assignee, cve, sc, OpenEulerScore, score, labels, it, 1, it.IssueType, "", brandArray) if requestBody != "" && len(requestBody) > 1 { - logs.Info("Template data before issue creation: ", requestBody) + logs.Info("CreateIssueToGit, Template data before issue creation: ", requestBody) updateLock.Lock() resp, err := util.HTTPPatch(url, requestBody) updateLock.Unlock() if err != nil { - logs.Error("Update issue failed, cveNum: ", cve.CveNum, "err: ", err, ",url: ", url) + logs.Error("CreateIssueToGit, Update issue failed, cveNum: ", + cve.CveNum, ",err: ", err, ",url: ", url) return "", errors.New("调用gitee更新issue接口失败") } if _, ok := resp["id"]; !ok { - logs.Error("Update issue failed, err: ", ok, "url: ", url) + logs.Error("CreateIssueToGit, Update issue failed, err: ", ok, ", url: ", url) return "", errors.New("调用gitee更新issue接口失败") } - logs.Info("Update issue successfully, cveNum: ", cve.CveNum, "issueNum: ", resp["number"].(string)) + logs.Info("CreateIssueToGit, Update issue successfully, "+ + "cveNum: ", cve.CveNum, "issueNum: ", resp["number"].(string)) // Structure data //var issueTemp models.IssueTemplate CreateIssueData(&it, cve, sc, resp, path, it.Assignee, issueType, labels, owner) // Store issue data issTempID, err := models.CreateIssueTemplate(&it) if err != nil { - logs.Error("Failed to update data of issue template, cveNum: ", cve.CveNum, ",err: ", err) + logs.Error("CreateIssueToGit, Failed to update data of issue template,"+ + " cveNum: ", cve.CveNum, ",err: ", err) //return "", nil } - logs.Info("Successfully updated the data of the issue template, issTempID: ", issTempID, ",cveNum: ", cve.CveNum) + logs.Info("CreateIssueToGit, Successfully updated the data of the issue template, "+ + "issTempID: ", issTempID, ",cveNum: ", cve.CveNum) } else { - logs.Info("No need to update the issue template and issue status, its: ", it) + logs.Info("CreateIssueToGit, No need to update the issue template and issue status, its: ", it) } // Update issue status models.UpdateIssueStatus(cve, 2) @@ -214,18 +213,20 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, score := strconv.FormatFloat(sc.NVDScore, 'f', 1, 64) requestBody := CreateIssueBody(accessToken, owner, path, assignee, cve, sc, "", score, labels, it, 2, issueType, "", brandArray) - logs.Info("isssue_body: ", requestBody) + logs.Info("CreateIssueToGit, isssue_body: ", requestBody) if requestBody != "" && len(requestBody) > 1 { updateLock.Lock() resp, err := util.HTTPPost(url, requestBody) updateLock.Unlock() if err != nil { - logs.Error("url: ", url, "Failed to create issue, cveNum: ", cve.CveNum, ", err: ", err, ",url:", url) + logs.Error("CreateIssueToGit, url: ", url, ", Failed to create issue, "+ + "cveNum: ", cve.CveNum, ", err: ", err, ",url:", url) models.DeleteIssueTemplate(issTempID) return "", errors.New("调用gitee的创建issue接口失败") } if _, ok := resp["id"]; !ok { - logs.Error("Failed to create issue, err: ", ok, "url: ", url) + logs.Error("CreateIssueToGit, Failed to create issue, "+ + "err: ", ok, ", url: ", url) models.DeleteIssueTemplate(issTempID) return "", errors.New("调用gitee的创建issue接口失败") } @@ -246,11 +247,12 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, // Store issue data issTempIDx, idxErr := models.UpdateIssueTemplateAll(&issueTemp) if idxErr != nil { - logs.Error("Failed to create data for issue template, cveNum: ", cve, ",err: ", err) + logs.Error("CreateIssueToGit, Failed to create data for issue template, "+ + "cveNum: ", cve, ",err: ", err) //models.DeleteIssueTemplate(issTempID) return "", errors.New("内部错误, 模板存储失败") } - logs.Info("The data of the issue template was successfully "+ + logs.Info("CreateIssueToGit, The data of the issue template was successfully, "+ "created, issTempID: ", issTempIDx, "cveNum: ", cve.CveNum) // Create issue comment affectedVersion := "" @@ -265,7 +267,7 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, affectedVersion = affectedVersion + "\n" } errx := CreateIssueComment(accessToken, owner, path, assignee, cve, resp, affectedVersion) - logs.Info("Issue comment creation result, err: ", errx) + logs.Info("CreateIssueToGit, Issue comment creation result, err: ", errx) // Send gitee private message content := fmt.Sprintf("%v 仓库有新的CVE和安全问题的ISSUE被 cve-manager 创建,CVE编号: %v, 请及时处理.", path, cve.CveNum) SendPrivateLetters(accessToken, content, assignee) @@ -273,10 +275,10 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, issueID := int64(resp["id"].(float64)) err = CreateDepositHooks(accessToken, owner, path, cve, issueNum, issueID) if err != nil { - logs.Error("Failed to create hooks, cveNum: ", cve.CveNum, "err: ", err) + logs.Error("CreateIssueToGit, Failed to create hooks, cveNum: ", cve.CveNum, "err: ", err) return "", errors.New("创建webhook失败") } - logs.Info("Create hooks successfully, cveNum: ", cve.CveNum) + logs.Info("CreateIssueToGit, Create hooks successfully, cveNum: ", cve.CveNum) // Update issue status models.UpdateIssueStatus(cve, 2) // Update score status @@ -287,7 +289,8 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, models.DeleteIssueTemplate(issTempID) } } else { - logs.Error("Repeat issue, cve: ", cve, ", templateErr: ", templateErr) + logs.Error("CreateIssueToGit, Repeat issue, cve: ", cve, + ", templateErr: ", templateErr) return "", nil } } @@ -308,16 +311,19 @@ func CreateIssueToGit(accessToken, owner, path, assignee string, CreateSecNoticeData(&sec, cve, path, branchs, sc.NVDScore) secID, noticeErr := models.UpdateSecNotice(&sec) if noticeErr != nil { - logs.Error("Failed to update security information,CveNum: ", cve.CveNum, "path: ", path, "err: ", noticeErr) + logs.Error("CreateIssueToGit, Failed to update security information,"+ + "CveNum: ", cve.CveNum, "path: ", path, "err: ", noticeErr) return "", nil } - logs.Info("Update security information successfully, secID: ", secID, "cveNum: ", cve.CveNum) + logs.Info("CreateIssueToGit, Update security information successfully, "+ + "secID: ", secID, "cveNum: ", cve.CveNum) return "", nil } func UpdateIssueToGit(accessToken string, owner string, path string, cve models.VulnCenter, its models.IssueTemplate) (string, error) { - logs.Info("更新模板请求参数: cve: ", cve, ",its: ", its, ", owner: ", owner, ",path: ", path) + logs.Info("UpdateIssueToGit, Update template request parameters: cve: ", cve, + ",its: ", its, ", owner: ", owner, ",path: ", path) gaussOwner := beego.AppConfig.String("opengauss::gauss_owner") gitGaussToken := beego.AppConfig.String("opengauss::git_gauss_token") if cve.OrganizationID == 2 { @@ -360,21 +366,21 @@ func UpdateIssueToGit(accessToken string, owner string, path string, var sc models.Score sc, scok := models.QueryScoreByCveId(cve.CveId) if !scok { - logs.Error("评分不存在, cve: ", cve) + logs.Error("UpdateIssueToGit, Score does not exist, cve: ", cve) } requestBody := CreateIssueBody(accessToken, owner, path, its.Assignee, cve, sc, OpenEulerScore, score, labels, its, 3, its.IssueType, pkgLink, brandArray) - logs.Info("isssue_body: ", requestBody) + logs.Info("UpdateIssueToGit, isssue_body: ", requestBody) if requestBody != "" && len(requestBody) > 1 { updateLock.Lock() resp, err := util.HTTPPatch(url, requestBody) updateLock.Unlock() if err != nil { - logs.Error("更新issue失败, cveNum: ", cve.CveNum, "err: ", err) + logs.Error("UpdateIssueToGit, Update issue failed, cveNum: ", cve.CveNum, "err: ", err) return "", errors.New("调用gitee更新issue的接口失败") } if _, ok := resp["id"]; !ok { - logs.Error("创建issue 失败, err: ", ok, "url: ", url) + logs.Error("UpdateIssueToGit, Failed to create issue, err: ", ok, "url: ", url) return "", errors.New("调用gitee更新issue的接口失败") } // Store security bulletin related information @@ -382,10 +388,12 @@ func UpdateIssueToGit(accessToken string, owner string, path string, CreateSecNoticeData(&sec, cve, path, its.AffectedVersion, its.OpenEulerScore) secId, err := models.UpdateSecNotice(&sec) if err != nil { - logs.Error("更新安全信息失败,CveNum: ", cve.CveNum, ",path: ", path, ",err: ", err) + logs.Error("UpdateIssueToGit, Failed to update security information, "+ + "CveNum: ", cve.CveNum, ",path: ", path, ",err: ", err) return "", errors.New("内部错误, 数据错误") } else { - logs.Info("更新安全信息成功, secId: ", secId, ",cveNum: ", cve.CveNum) + logs.Info("UpdateIssueToGit, Update security information successfully, "+ + "secId: ", secId, ",cveNum: ", cve.CveNum) } } } @@ -432,7 +440,8 @@ func CreateIssueHookData(issHook *models.IssueHooks, resp map[string]interface{} return issHook } -func PatchWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, hookId string, issueId, cveId int64) error { +func PatchWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, + hookId string, issueId, cveId int64) error { if accessToken != "" && owner != "" && path != "" { url := "https://gitee.com/api/v5/repos/" + owner + "/" + path + "/hooks/" + hookId push_events := "true" @@ -450,14 +459,14 @@ func PatchWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, hookId stri "note_events": "%s", "merge_requests_events": "%s" }`, accessToken, hookurl, pwd, push_events, tag_push_events, issues_events, note_events, merge_requests_events) - logs.Info("hook_body: ", requestBody) + logs.Info("PatchWebHooks, hook_body: ", requestBody) resp, err := util.HTTPPatch(url, requestBody) if err != nil { - logs.Error("更新钩子失败, url: ", url, ", err: ", err) + logs.Error("PatchWebHooks, Failed to update webhook, url: ", url, ", err: ", err) return err } if _, ok := resp["id"]; !ok { - logs.Error("更新仓库 hook失败, err: ", ok, "url: ", url) + logs.Error("PatchWebHooks, Failed to update webhook, err: ", ok, ", url: ", url) return errors.New("更新仓库 hook失败") } if resp["password"].(string) == pwd { @@ -466,10 +475,10 @@ func PatchWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, hookId stri path, owner, issueNum, issueId, cveId) hookId, err := models.CreateDepositHooks(&issHook) if err != nil { - logs.Error("更新仓库 hook数据失败, repo: ", path, ", err: ", err) + logs.Error("PatchWebHooks, Failed to update webhook, repo: ", path, ", err: ", err) return nil } else { - logs.Info("更新仓库 hook数据成功, hookId: ", hookId, "repo: ", path) + logs.Info("PatchWebHooks, Update webhook successfully, hookId: ", hookId, "repo: ", path) } } return nil @@ -498,11 +507,11 @@ func PostWebHooks(accessToken, owner, path, hookurl, pwd, issueNum string, issue logs.Info("hook_body: ", requestBody) resp, err := util.HTTPPost(url, requestBody) if err != nil { - logs.Error("创建钩子失败, url: ", url, ", cveId:", cveId, ",err: ", err) + logs.Error("PatchWebHooks, Failed to create webhook, url: ", url, ", cveId:", cveId, ",err: ", err) return err } if _, ok := resp["id"]; !ok { - logs.Error("创建仓库hook失败, err: ", ok, "url: ", url) + logs.Error("PatchWebHooks, Failed to create webhook, err: ", ok, "url: ", url) return errors.New("创建仓库hook失败") } if resp["password"].(string) == pwd { @@ -512,10 +521,10 @@ func PostWebHooks(accessToken, owner, path, hookurl, pwd, issueNum string, issue // Store issue data hookId, err := models.CreateDepositHooks(&issHook) if err != nil { - logs.Error("创建仓库hook失败, path: ", path, "err: ", err) + logs.Error("PatchWebHooks, Failed to create webhook, path: ", path, ", err: ", err) return err } else { - logs.Info("创建仓库 hook数据成功, hookId: ", hookId, "path: ", path) + logs.Info("PatchWebHooks, Create webhook successfully, hookId: ", hookId, ", path: ", path) } } return nil @@ -533,7 +542,7 @@ func CreateDepositHooks(accessToken string, owner string, path string, ih.Repo = path BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("CreateDepositHooks, config init, error:", err) return err } pwd := BConfig.String("hook::hookpwd") @@ -547,26 +556,26 @@ func CreateDepositHooks(accessToken string, owner string, path string, hookId := strconv.FormatInt(wh.HookId, 10) patchErr := PatchWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, hookId, issueId, cve.CveId) if patchErr == nil { - logs.Info("owner: ", owner, ",repo: ", path, ",webhook updated successfully") + logs.Info("CreateDepositHooks, owner: ", owner, ",repo: ", path, ",webhook updated successfully") } else { - logs.Error("owner: ", owner, ",repo: ", path, ",patchErr: ", patchErr) + logs.Error("CreateDepositHooks, owner: ", owner, ",repo: ", path, ",patchErr: ", patchErr) } } } if !hookExist { postErr := PostWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, issueId, cve.CveId) if postErr == nil { - logs.Info("owner: ", owner, ",repo: ", path, ",webhook created successfully") + logs.Info("CreateDepositHooks, owner: ", owner, ",repo: ", path, ",webhook created successfully") } else { - logs.Error("owner: ", owner, ",repo: ", path, ",postErr: ", postErr) + logs.Error("CreateDepositHooks, owner: ", owner, ",repo: ", path, ",postErr: ", postErr) } } } else { postErr := PostWebHooks(accessToken, owner, path, hookurl, pwd, issueNum, issueId, cve.CveId) if postErr == nil { - logs.Info("owner: ", owner, ",repo: ", path, ",webhook created successfully") + logs.Info("CreateDepositHooks, owner: ", owner, ",repo: ", path, ",webhook created successfully") } else { - logs.Error("owner: ", owner, ",repo: ", path, ", postErr: ", postErr) + logs.Error("CreateDepositHooks, owner: ", owner, ",repo: ", path, ", postErr: ", postErr) } } return nil @@ -579,7 +588,7 @@ func CreateIssueComment(accessToken, owner, path, assignee string, url := "https://gitee.com/api/v5/repos/" + owner + "/" + path + "/issues/" + issueNum + "/comments" BConfig, err := config.NewConfig("ini", "conf/app.conf") if err != nil { - logs.Error("config init error:", err) + logs.Error("CreateIssueComment, config init, error:", err) return err } commentCmd := BConfig.String("reflink::comment_cmd") @@ -591,14 +600,15 @@ func CreateIssueComment(accessToken, owner, path, assignee string, "access_token": "%s", "body": "%s" }`, accessToken, commentBody) - logs.Info("create issue comment body: ", requestBody) + logs.Info("CreateIssueComment, create issue comment body: ", requestBody) resp, err := util.HTTPPost(url, requestBody) if err != nil { - logs.Error("创建issue评论失败, url: ", url, "cveId", cve.CveId, ",issueNum: ", issueNum, ",err: ", err) + logs.Error("CreateIssueComment, Failed to create issue comment, url: ", url, + ", cveId", cve.CveId, ",issueNum: ", issueNum, ",err: ", err) return err } if _, ok := resp["id"]; !ok { - logs.Error("创建issue评论失败, err: ", ok, "url: ", url) + logs.Error("CreateIssueComment, Failed to create issue comment, err: ", ok, ", url: ", url) return errors.New("创建issue评论失败") } commentID := int64(resp["id"].(float64)) @@ -662,19 +672,20 @@ func CreateIssueLabel(accessToken string, owner string, path string, body["access_token"] = accessToken body["body"] = fmt.Sprintf(`[%s,%s]`, beego.AppConfig.String("labelUnFix"), beego.AppConfig.String("labelUnFix")) requestBody, _ := json.Marshal(body) - logs.Info("create issue label: ", string(requestBody)) + logs.Info("CreateIssueLabel, create issue label: ", string(requestBody)) resp, err := util.HTTPPost1(url, string(requestBody)) if err != nil { - logs.Error("cve标签创建失败, url: ", url, "requestBody: ", requestBody, "err: ", err) + logs.Error("CreateIssueLabel, cve tag creation failed, url: ", + url, ", requestBody: ", requestBody, ", err: ", err) return err } for _, value := range resp { if _, ok := value["id"]; !ok { - logs.Error("创建issue 标签失败, err: ", ok, "url: ", url) + logs.Error("CreateIssueLabel, Failed to create issue tag, err: ", ok, ", url: ", url) return errors.New("创建issue标签失败") } } - logs.Info("issue 标签创建成功, resp: ", resp) + logs.Info("CreateIssueLabel, The issue tag was created successfully, resp: ", resp) } return nil }