diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index 1728e9c..edf92b7 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -69,6 +69,7 @@ type processor struct { badDirListings topicMessages badROLIEfeed topicMessages badROLIEservice topicMessages + badROLIEcategory topicMessages expr *util.PathEval } @@ -236,6 +237,7 @@ func (p *processor) clean() { p.badDirListings.reset() p.badROLIEfeed.reset() p.badROLIEservice.reset() + p.badROLIEcategory.reset() p.labelChecker = nil } diff --git a/cmd/csaf_checker/reporters.go b/cmd/csaf_checker/reporters.go index 85b1acd..c9d9ed9 100644 --- a/cmd/csaf_checker/reporters.go +++ b/cmd/csaf_checker/reporters.go @@ -358,8 +358,18 @@ func (r *rolieServiceReporter) report(p *processor, domain *Domain) { // documents by certain criteria // and sets the "message" field value // of the "Requirement" struct as a result of that. -func (r *rolieCategoryReporter) report(_ *processor, _ *Domain) { - // TODO +func (r *rolieCategoryReporter) report(p *processor, domain *Domain) { + req := r.requirement(domain) + if !p.badROLIEcategory.used() { + req.message(InfoType, "No checks on the existence of ROLIE category documents performed.") + return + } + if len(p.badROLIEcategory) == 0 { + req.message(InfoType, "All checked ROLIE category documents exist.") + return + } + req.Messages = p.badROLIEcategory + } func (r *integrityReporter) report(p *processor, domain *Domain) { diff --git a/cmd/csaf_checker/roliecheck.go b/cmd/csaf_checker/roliecheck.go index 41e257b..30ac49d 100644 --- a/cmd/csaf_checker/roliecheck.go +++ b/cmd/csaf_checker/roliecheck.go @@ -11,6 +11,7 @@ package main import ( "net/http" "net/url" + "strings" "github.com/csaf-poc/csaf_distribution/v2/csaf" "github.com/csaf-poc/csaf_distribution/v2/util" @@ -159,6 +160,7 @@ func (p *processor) processROLIEFeeds(feeds [][]csaf.Feed) error { } label := tlpLabel(feed.TLPLabel) + p.categoryCheck(feedBase, label) p.labelChecker = &rolieLabelChecker{ feedURL: feedURL.String(), @@ -265,6 +267,26 @@ func containsAllKeys[K comparable, V any](m1, m2 map[K]V) bool { return true } +func (p *processor) categoryCheck(folderURL string, label csaf.TLPLabel) error { + labelname := strings.ToLower(string(label)) + urlrc := folderURL + "category-" + labelname + ".json" + + p.badROLIEcategory.use() + client := p.httpClient() + res, err := client.Get(urlrc) + if err != nil { + p.badROLIEcategory.error("Cannot fetch rolie category document %s: %v", urlrc, err) + return errContinue + } + if res.StatusCode != http.StatusOK { + p.badROLIEcategory.warn("Fetching %s failed. Status code %d (%s)", + urlrc, res.StatusCode, res.Status) + return errContinue + } + + return nil +} + func (p *processor) serviceCheck(feeds [][]csaf.Feed) error { // service category document should be next to the pmd pmdURL, err := url.Parse(p.pmdURL)