diff --git a/cve-vulner-manager/cve-ddd/app/refactor_hotpatch.go b/cve-vulner-manager/cve-ddd/app/refactor_hotpatch.go index 6bffe5533cc428f5343f955fb8c62d8d81e62428..4997277a2c02a75820f1193666bf713145d6acbf 100644 --- a/cve-vulner-manager/cve-ddd/app/refactor_hotpatch.go +++ b/cve-vulner-manager/cve-ddd/app/refactor_hotpatch.go @@ -14,6 +14,7 @@ import ( "cvevulner/cve-ddd/domain/obs" "cvevulner/cve-ddd/domain/repository" "cvevulner/cve-ddd/domain/service" + "cvevulner/cve-ddd/domain/testresult" "cvevulner/cve-ddd/domain/updateinfo" ) @@ -33,7 +34,7 @@ func NewRefactorHotPatchService( u updateinfo.UpdateInfo, h hotpatch.HotPatch, l *logrus.Entry, - + t testresult.Result, ) *refactorHotPatchService { return &refactorHotPatchService{ repository: r, @@ -42,17 +43,18 @@ func NewRefactorHotPatchService( updateInfo: u, hotPatch: h, log: l, + testResult: t, } } type refactorHotPatchService struct { - repository repository.CveRepository - bulletin bulletin.Bulletin obs obs.OBS - updateInfo updateinfo.UpdateInfo + log *logrus.Entry hotPatch hotpatch.HotPatch - - log *logrus.Entry + bulletin bulletin.Bulletin + testResult testresult.Result + updateInfo updateinfo.UpdateInfo + repository repository.CveRepository } func (h *refactorHotPatchService) GenerateBulletins(uploadDir, date string) error { @@ -73,6 +75,12 @@ func (h *refactorHotPatchService) GenerateBulletins(uploadDir, date string) erro hotDate := "hotpatch_" + date for _, issue := range issues { + isHotPatchExists := h.testResult.IsHotPatchExist(&issue, hotDate) + if !isHotPatchExists { + h.log.Errorf("hot patch source rpm of %s not exist", issue.HotIssueNum) + continue + } + isPublished, err1 := h.hotPatch.IsPublished(issue.CveNum[0], issue.Component, issue.Branch) if err1 != nil { h.log.Errorf("check whether hotpatch %s is published, occurred error: %s", issue.HotIssueNum, err1.Error()) diff --git a/cve-vulner-manager/cve-ddd/domain/hot_patch_issue.go b/cve-vulner-manager/cve-ddd/domain/hot_patch_issue.go index 0016b35ed48618cd61873cce02d9a54a020fc561..4a6f0ddb170497f0ded8f255a60bbc6c11045df3 100644 --- a/cve-vulner-manager/cve-ddd/domain/hot_patch_issue.go +++ b/cve-vulner-manager/cve-ddd/domain/hot_patch_issue.go @@ -1,5 +1,10 @@ package domain +import ( + "path/filepath" + "strings" +) + type HotPatchIssue struct { Type string Branch string @@ -8,3 +13,14 @@ type HotPatchIssue struct { PatchUrl []string HotIssueNum string } + +// SourcePatchName get rpm name of source arch +func (h *HotPatchIssue) SourcePatchName() string { + for _, v := range h.PatchUrl { + if strings.Contains(v, "source/Packages") { + return filepath.Base(v) + } + } + + return "" +} diff --git a/cve-vulner-manager/cve-ddd/domain/testresult/result.go b/cve-vulner-manager/cve-ddd/domain/testresult/result.go index 350673b4e48932b4cbe3ba936de1e39b409ad66e..a39a84e4dbff060680ef20552caff1a02c1efd1c 100644 --- a/cve-vulner-manager/cve-ddd/domain/testresult/result.go +++ b/cve-vulner-manager/cve-ddd/domain/testresult/result.go @@ -7,5 +7,6 @@ import ( type Result interface { Init([]string, string) Filter(domain.Cves) domain.Cves + IsHotPatchExist(*domain.HotPatchIssue, string) bool GenerateProductTree(string, []string) domain.ProductTree } diff --git a/cve-vulner-manager/cve-ddd/infrastructure/testresultimpl/impl.go b/cve-vulner-manager/cve-ddd/infrastructure/testresultimpl/impl.go index 45af6a1411ac037d6c0e3edbf345efa58dd75209..55dc39854ebc705151ad29006593fe5eabaea869 100644 --- a/cve-vulner-manager/cve-ddd/infrastructure/testresultimpl/impl.go +++ b/cve-vulner-manager/cve-ddd/infrastructure/testresultimpl/impl.go @@ -125,6 +125,25 @@ func (impl *testResultImpl) Filter(cves domain.Cves) domain.Cves { return filtered } +func (impl *testResultImpl) IsHotPatchExist(patch *domain.HotPatchIssue, hotDate string) bool { + patchName := patch.SourcePatchName() + if patchName == "" { + return false + } + + url := fmt.Sprintf("%s/repo.openeuler.org/%s/%s/source/Packages/%s", + beego.AppConfig.String("testResult::host"), patch.Branch, hotDate, patchName, + ) + + resp, err := http.Head(url) + if err != nil { + impl.log.Errorf("check hotPatch rpm %s failed: %s", url, err.Error()) + return false + } + + return resp.StatusCode == http.StatusOK +} + func (impl *testResultImpl) GenerateProductTree(component string, affectedVersion []string) domain.ProductTree { tree := make(domain.ProductTree) diff --git a/cve-vulner-manager/routers/new_router.go b/cve-vulner-manager/routers/new_router.go index 928acbbadaf50719aa09fe5139241ca7601bb7b7..202c36a63d574e28c060bcb87d24ed3a25474351 100644 --- a/cve-vulner-manager/routers/new_router.go +++ b/cve-vulner-manager/routers/new_router.go @@ -72,6 +72,7 @@ func initNewRouter() { updateinfoimpl.NewUpdateInfoImpl(logBulletin), hotpatchimpl.NewHotPatchImpl(logHotPatchBulletin), logHotPatchBulletin, + testresultimpl.NewTestResultImpl(logHotPatchBulletin), ) NewCveController := controller.NewCveController(