1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00

Add ROLIE category document check for existence

This commit is contained in:
JanHoefelmeyer 2023-06-15 11:05:37 +02:00
parent 051de5194d
commit d91af558ce
3 changed files with 36 additions and 2 deletions

View file

@ -69,6 +69,7 @@ type processor struct {
badDirListings topicMessages badDirListings topicMessages
badROLIEfeed topicMessages badROLIEfeed topicMessages
badROLIEservice topicMessages badROLIEservice topicMessages
badROLIEcategory topicMessages
expr *util.PathEval expr *util.PathEval
} }
@ -236,6 +237,7 @@ func (p *processor) clean() {
p.badDirListings.reset() p.badDirListings.reset()
p.badROLIEfeed.reset() p.badROLIEfeed.reset()
p.badROLIEservice.reset() p.badROLIEservice.reset()
p.badROLIEcategory.reset()
p.labelChecker = nil p.labelChecker = nil
} }

View file

@ -358,8 +358,18 @@ func (r *rolieServiceReporter) report(p *processor, domain *Domain) {
// documents by certain criteria // documents by certain criteria
// and sets the "message" field value // and sets the "message" field value
// of the "Requirement" struct as a result of that. // of the "Requirement" struct as a result of that.
func (r *rolieCategoryReporter) report(_ *processor, _ *Domain) { func (r *rolieCategoryReporter) report(p *processor, domain *Domain) {
// TODO 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) { func (r *integrityReporter) report(p *processor, domain *Domain) {

View file

@ -11,6 +11,7 @@ package main
import ( import (
"net/http" "net/http"
"net/url" "net/url"
"strings"
"github.com/csaf-poc/csaf_distribution/v2/csaf" "github.com/csaf-poc/csaf_distribution/v2/csaf"
"github.com/csaf-poc/csaf_distribution/v2/util" "github.com/csaf-poc/csaf_distribution/v2/util"
@ -159,6 +160,7 @@ func (p *processor) processROLIEFeeds(feeds [][]csaf.Feed) error {
} }
label := tlpLabel(feed.TLPLabel) label := tlpLabel(feed.TLPLabel)
p.categoryCheck(feedBase, label)
p.labelChecker = &rolieLabelChecker{ p.labelChecker = &rolieLabelChecker{
feedURL: feedURL.String(), feedURL: feedURL.String(),
@ -265,6 +267,26 @@ func containsAllKeys[K comparable, V any](m1, m2 map[K]V) bool {
return true 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 { func (p *processor) serviceCheck(feeds [][]csaf.Feed) error {
// service category document should be next to the pmd // service category document should be next to the pmd
pmdURL, err := url.Parse(p.pmdURL) pmdURL, err := url.Parse(p.pmdURL)