1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Add another layer aound the ROLIE feed documents.

This commit is contained in:
Sascha L. Teichmann 2022-02-23 21:10:19 +01:00
parent 9e13831a6f
commit 4fc6bc5509
3 changed files with 20 additions and 13 deletions

View file

@ -490,7 +490,7 @@ func (p *processor) processROLIEFeed(feed string) error {
// Extract the CSAF files from feed. // Extract the CSAF files from feed.
var files []string var files []string
for _, f := range rfeed.Entry { for _, f := range rfeed.Feed.Entry {
for i := range f.Link { for i := range f.Link {
files = append(files, f.Link[i].HRef) files = append(files, f.Link[i].HRef)
} }

View file

@ -226,16 +226,18 @@ func (c *controller) upload(r *http.Request) (interface{}, error) {
// Create new if does not exists. // Create new if does not exists.
if rolie == nil { if rolie == nil {
rolie = &csaf.ROLIEFeed{ rolie = &csaf.ROLIEFeed{
Feed: csaf.FeedData{
ID: "csaf-feed-tlp-" + ts, ID: "csaf-feed-tlp-" + ts,
Title: "CSAF feed (TLP:" + string(tlpLabel) + ")", Title: "CSAF feed (TLP:" + string(tlpLabel) + ")",
Link: []csaf.Link{{ Link: []csaf.Link{{
Rel: "rel", Rel: "rel",
HRef: string(feedURL), HRef: string(feedURL),
}}, }},
},
} }
} }
rolie.Updated = csaf.TimeStamp(time.Now()) rolie.Feed.Updated = csaf.TimeStamp(time.Now())
year := strconv.Itoa(ex.initialReleaseDate.Year()) year := strconv.Itoa(ex.initialReleaseDate.Year())
@ -245,7 +247,7 @@ func (c *controller) upload(r *http.Request) (interface{}, error) {
e := rolie.EntryByID(ex.id) e := rolie.EntryByID(ex.id)
if e == nil { if e == nil {
e = &csaf.Entry{ID: ex.id} e = &csaf.Entry{ID: ex.id}
rolie.Entry = append(rolie.Entry, e) rolie.Feed.Entry = append(rolie.Feed.Entry, e)
} }
e.Titel = ex.title e.Titel = ex.title

View file

@ -58,8 +58,8 @@ type Entry struct {
Format Format `json:"format"` Format Format `json:"format"`
} }
// ROLIEFeed is a ROLIE feed. // FeedData is the contetn of the ROLIE feed.
type ROLIEFeed struct { type FeedData struct {
ID string `json:"id"` ID string `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Link []Link `json:"link,omitempty"` Link []Link `json:"link,omitempty"`
@ -68,6 +68,11 @@ type ROLIEFeed struct {
Entry []*Entry `json:"entry,omitempty"` 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. // LoadROLIEFeed loads a ROLIE feed from a reader.
func LoadROLIEFeed(r io.Reader) (*ROLIEFeed, error) { func LoadROLIEFeed(r io.Reader) (*ROLIEFeed, error) {
dec := json.NewDecoder(r) 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. // EntryByID looks up an entry by its ID.
// Returns nil if no such entry was found. // Returns nil if no such entry was found.
func (rf *ROLIEFeed) EntryByID(id string) *Entry { func (rf *ROLIEFeed) EntryByID(id string) *Entry {
for _, entry := range rf.Entry { for _, entry := range rf.Feed.Entry {
if entry.ID == id { if entry.ID == id {
return entry return entry
} }
@ -101,7 +106,7 @@ func (rf *ROLIEFeed) EntryByID(id string) *Entry {
// SortEntriesByUpdated sorts all the entries in the feed // SortEntriesByUpdated sorts all the entries in the feed
// by their update times. // by their update times.
func (rf *ROLIEFeed) SortEntriesByUpdated() { func (rf *ROLIEFeed) SortEntriesByUpdated() {
entries := rf.Entry entries := rf.Feed.Entry
sort.Slice(entries, func(i, j int) bool { sort.Slice(entries, func(i, j int) bool {
return time.Time(entries[j].Updated).Before(time.Time(entries[i].Updated)) return time.Time(entries[j].Updated).Before(time.Time(entries[i].Updated))
}) })