mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Empty rolie (#357)
* Create ROLIE feed if summaries are empty * Formatting, Remove sorting of 0 elements * Handle minimum entry length error as warning in checker * Use empty array instead of creating an empty array to reference * Change schema to allow for empty entry arrays * Use https://raw.githubusercontent.com/oasis-tcs/csaf/81b2663697958bc5f85d14372712a40028fb8338/csaf_2.0/json_schema/ROLIE_feed_json_schema.json as schema for ROLIE feeds * Change label name from empty to undefined * Change default of create_service_document for csaf_provider to true * Config * Count entries in csaf-checker, warn if there are none. * Add Comments to csaf/rolie.go's CountEntries function * Delete index.txt and changes.csv in aggregator if there are no entries. * Create an empty ROLIE feed document when setting up folders during create * nit: set update time stamp in structure init. * Instantiate label checker only once. * Ignore domain not having roles. * provider: Create empty entry section in ROLIE feed. * Stop check for domain if PMD check fails * Add missing continue statement * Report missing ROLIE feed entries in ROLIE feed, not Provider Metadata * Do not ommit empty entries in ROLIE feeds. * Fixed error handling problem introduced by faulty merge. Removed unused errStop handling while there. --------- Co-authored-by: JanHoefelmeyer <hoefelmeyer.jan@gmail.com> Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de> Co-authored-by: JanHoefelmeyer <Jan Höfelmeyer jhoefelmeyer@intevation.de>
This commit is contained in:
parent
540d02d367
commit
b61912410a
8 changed files with 194 additions and 43 deletions
|
|
@ -91,6 +91,22 @@ func (w *worker) writeInterims(label string, summaries []summary) error {
|
|||
|
||||
func (w *worker) writeCSV(label string, summaries []summary) error {
|
||||
|
||||
fname := filepath.Join(w.dir, label, changesCSV)
|
||||
|
||||
// If we don't have any entries remove existing file.
|
||||
if len(summaries) == 0 {
|
||||
// Does it really exist?
|
||||
if err := os.RemoveAll(fname); err != nil {
|
||||
return fmt.Errorf("unable to remove %q: %w", fname, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
f, err := os.Create(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Do not sort in-place.
|
||||
ss := make([]summary, len(summaries))
|
||||
copy(ss, summaries)
|
||||
|
|
@ -100,11 +116,6 @@ func (w *worker) writeCSV(label string, summaries []summary) error {
|
|||
ss[j].summary.CurrentReleaseDate)
|
||||
})
|
||||
|
||||
fname := filepath.Join(w.dir, label, changesCSV)
|
||||
f, err := os.Create(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out := util.NewFullyQuotedCSWWriter(f)
|
||||
|
||||
record := make([]string, 2)
|
||||
|
|
@ -137,6 +148,16 @@ func (w *worker) writeCSV(label string, summaries []summary) error {
|
|||
func (w *worker) writeIndex(label string, summaries []summary) error {
|
||||
|
||||
fname := filepath.Join(w.dir, label, indexTXT)
|
||||
|
||||
// If we don't have any entries remove existing file.
|
||||
if len(summaries) == 0 {
|
||||
// Does it really exist?
|
||||
if err := os.RemoveAll(fname); err != nil {
|
||||
return fmt.Errorf("unable to remove %q: %w", fname, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
f, err := os.Create(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -157,6 +178,46 @@ func (w *worker) writeIndex(label string, summaries []summary) error {
|
|||
return err2
|
||||
}
|
||||
|
||||
func (w *worker) writeROLIENoSummaries(label string) error {
|
||||
|
||||
labelFolder := strings.ToLower(label)
|
||||
|
||||
fname := "csaf-feed-tlp-" + labelFolder + ".json"
|
||||
|
||||
feedURL := w.processor.cfg.Domain + "/.well-known/csaf-aggregator/" +
|
||||
w.provider.Name + "/" + labelFolder + "/" + fname
|
||||
|
||||
links := []csaf.Link{{
|
||||
Rel: "self",
|
||||
HRef: feedURL,
|
||||
}}
|
||||
|
||||
if w.provider.serviceDocument(w.processor.cfg) {
|
||||
links = append(links, csaf.Link{
|
||||
Rel: "service",
|
||||
HRef: w.processor.cfg.Domain + "/.well-known/csaf-aggregator/" +
|
||||
w.provider.Name + "/service.json",
|
||||
})
|
||||
}
|
||||
|
||||
rolie := &csaf.ROLIEFeed{
|
||||
Feed: csaf.FeedData{
|
||||
ID: "csaf-feed-tlp-" + strings.ToLower(label),
|
||||
Title: "CSAF feed (TLP:" + strings.ToUpper(label) + ")",
|
||||
Link: links,
|
||||
Category: []csaf.ROLIECategory{{
|
||||
Scheme: "urn:ietf:params:rolie:category:information-type",
|
||||
Term: "csaf",
|
||||
}},
|
||||
Updated: csaf.TimeStamp(time.Now().UTC()),
|
||||
Entry: []*csaf.Entry{},
|
||||
},
|
||||
}
|
||||
|
||||
path := filepath.Join(w.dir, labelFolder, fname)
|
||||
return util.WriteToFile(path, rolie)
|
||||
}
|
||||
|
||||
func (w *worker) writeROLIE(label string, summaries []summary) error {
|
||||
|
||||
labelFolder := strings.ToLower(label)
|
||||
|
|
@ -311,6 +372,7 @@ func (w *worker) writeService() error {
|
|||
func (w *worker) writeIndices() error {
|
||||
|
||||
if len(w.summaries) == 0 || w.dir == "" {
|
||||
w.writeROLIENoSummaries("undefined")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue