From 4fc6bc55091968522aa765fbe98aef375db7adef Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Wed, 23 Feb 2022 21:10:19 +0100 Subject: [PATCH 1/2] Add another layer aound the ROLIE feed documents. --- cmd/csaf_checker/processor.go | 2 +- cmd/csaf_provider/actions.go | 18 ++++++++++-------- csaf/rolie.go | 13 +++++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index 49e4d62..e7b54d8 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -490,7 +490,7 @@ func (p *processor) processROLIEFeed(feed string) error { // Extract the CSAF files from feed. var files []string - for _, f := range rfeed.Entry { + for _, f := range rfeed.Feed.Entry { for i := range f.Link { files = append(files, f.Link[i].HRef) } diff --git a/cmd/csaf_provider/actions.go b/cmd/csaf_provider/actions.go index 1e4df7d..7cbe9cb 100644 --- a/cmd/csaf_provider/actions.go +++ b/cmd/csaf_provider/actions.go @@ -226,16 +226,18 @@ func (c *controller) upload(r *http.Request) (interface{}, error) { // Create new if does not exists. if rolie == nil { rolie = &csaf.ROLIEFeed{ - ID: "csaf-feed-tlp-" + ts, - Title: "CSAF feed (TLP:" + string(tlpLabel) + ")", - Link: []csaf.Link{{ - Rel: "rel", - HRef: string(feedURL), - }}, + Feed: csaf.FeedData{ + ID: "csaf-feed-tlp-" + ts, + Title: "CSAF feed (TLP:" + string(tlpLabel) + ")", + Link: []csaf.Link{{ + Rel: "rel", + HRef: string(feedURL), + }}, + }, } } - rolie.Updated = csaf.TimeStamp(time.Now()) + rolie.Feed.Updated = csaf.TimeStamp(time.Now()) year := strconv.Itoa(ex.initialReleaseDate.Year()) @@ -245,7 +247,7 @@ func (c *controller) upload(r *http.Request) (interface{}, error) { e := rolie.EntryByID(ex.id) if e == nil { e = &csaf.Entry{ID: ex.id} - rolie.Entry = append(rolie.Entry, e) + rolie.Feed.Entry = append(rolie.Feed.Entry, e) } e.Titel = ex.title diff --git a/csaf/rolie.go b/csaf/rolie.go index 12e6beb..4e22e2c 100644 --- a/csaf/rolie.go +++ b/csaf/rolie.go @@ -58,8 +58,8 @@ type Entry struct { Format Format `json:"format"` } -// ROLIEFeed is a ROLIE feed. -type ROLIEFeed struct { +// FeedData is the contetn of the ROLIE feed. +type FeedData struct { ID string `json:"id"` Title string `json:"title"` Link []Link `json:"link,omitempty"` @@ -68,6 +68,11 @@ type ROLIEFeed struct { Entry []*Entry `json:"entry,omitempty"` } +// ROLIEFeed is a ROLIE feed. +type ROLIEFeed struct { + Feed FeedData `json:"feed"` +} + // LoadROLIEFeed loads a ROLIE feed from a reader. func LoadROLIEFeed(r io.Reader) (*ROLIEFeed, error) { dec := json.NewDecoder(r) @@ -90,7 +95,7 @@ func (rf *ROLIEFeed) WriteTo(w io.Writer) (int64, error) { // EntryByID looks up an entry by its ID. // Returns nil if no such entry was found. func (rf *ROLIEFeed) EntryByID(id string) *Entry { - for _, entry := range rf.Entry { + for _, entry := range rf.Feed.Entry { if entry.ID == id { return entry } @@ -101,7 +106,7 @@ func (rf *ROLIEFeed) EntryByID(id string) *Entry { // SortEntriesByUpdated sorts all the entries in the feed // by their update times. func (rf *ROLIEFeed) SortEntriesByUpdated() { - entries := rf.Entry + entries := rf.Feed.Entry sort.Slice(entries, func(i, j int) bool { return time.Time(entries[j].Updated).Before(time.Time(entries[i].Updated)) }) From 670f4cbf609e2deee79c9de5ceaf72a8d757f567 Mon Sep 17 00:00:00 2001 From: Fadi Abbud Date: Thu, 24 Feb 2022 09:06:16 +0100 Subject: [PATCH 2/2] Fix Typo --- csaf/rolie.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csaf/rolie.go b/csaf/rolie.go index 4e22e2c..4c4a5af 100644 --- a/csaf/rolie.go +++ b/csaf/rolie.go @@ -58,7 +58,7 @@ type Entry struct { Format Format `json:"format"` } -// FeedData is the contetn of the ROLIE feed. +// FeedData is the content of the ROLIE feed. type FeedData struct { ID string `json:"id"` Title string `json:"title"`