mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add service document support for aggregator
This commit is contained in:
parent
e37fe68b34
commit
141acc802e
2 changed files with 79 additions and 5 deletions
|
|
@ -185,14 +185,24 @@ func (w *worker) writeROLIE(label string, summaries []summary) error {
|
|||
}
|
||||
}
|
||||
|
||||
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: []csaf.Link{{
|
||||
Rel: "self",
|
||||
HRef: feedURL,
|
||||
}},
|
||||
Link: links,
|
||||
Category: []csaf.ROLIECategory{{
|
||||
Scheme: "urn:ietf:params:rolie:category:information-type",
|
||||
Term: "csaf",
|
||||
|
|
@ -228,6 +238,56 @@ func (w *worker) writeCategories(label string) error {
|
|||
return util.WriteToFile(path, rcd)
|
||||
}
|
||||
|
||||
// writeService writes a service.json document if it is configured.
|
||||
func (w *worker) writeService() error {
|
||||
|
||||
if !w.provider.serviceDocument(w.processor.cfg) {
|
||||
return nil
|
||||
}
|
||||
labels := make([]string, len(w.summaries))
|
||||
var i int
|
||||
for label := range w.summaries {
|
||||
labels[i] = strings.ToLower(label)
|
||||
i++
|
||||
}
|
||||
sort.Strings(labels)
|
||||
|
||||
categories := csaf.ROLIEServiceWorkspaceCollectionCategories{
|
||||
Category: []csaf.ROLIEServiceWorkspaceCollectionCategoriesCategory{{
|
||||
Scheme: "urn:ietf:params:rolie:category:information-type",
|
||||
Term: "csaf",
|
||||
}},
|
||||
}
|
||||
|
||||
var collections []csaf.ROLIEServiceWorkspaceCollection
|
||||
|
||||
for _, ts := range labels {
|
||||
feedName := "csaf-feed-tlp-" + ts + ".json"
|
||||
|
||||
href := w.processor.cfg.Domain + "/.well-known/csaf-aggregator/" +
|
||||
w.provider.Name + "/" + ts + "/" + feedName
|
||||
|
||||
collection := csaf.ROLIEServiceWorkspaceCollection{
|
||||
Title: "CSAF feed (TLP:" + strings.ToUpper(ts) + ")",
|
||||
HRef: href,
|
||||
Categories: categories,
|
||||
}
|
||||
collections = append(collections, collection)
|
||||
}
|
||||
|
||||
rsd := &csaf.ROLIEServiceDocument{
|
||||
Service: csaf.ROLIEService{
|
||||
Workspace: []csaf.ROLIEServiceWorkspace{{
|
||||
Title: "CSAF feeds",
|
||||
Collection: collections,
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
path := filepath.Join(w.dir, "service.json")
|
||||
return util.WriteToFile(path, rsd)
|
||||
}
|
||||
|
||||
func (w *worker) writeIndices() error {
|
||||
|
||||
if len(w.summaries) == 0 || w.dir == "" {
|
||||
|
|
@ -253,5 +313,5 @@ func (w *worker) writeIndices() error {
|
|||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return w.writeService()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue