mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
write category documents in create.
This commit is contained in:
parent
df21b2575d
commit
72a7240fd0
2 changed files with 31 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -65,6 +66,15 @@ func createWellknown(_ *config, wellknown string) error {
|
|||
// No creation for the "csaf" option will be done.
|
||||
// It creates also symbolic links to feed folders.
|
||||
func createFeedFolders(c *config, wellknown string) error {
|
||||
|
||||
// If we have static configured categories we need to create
|
||||
// the category documents.
|
||||
var catDoc *csaf.ROLIECategoryDocument
|
||||
|
||||
if categories := c.StaticCategories(); len(categories) > 0 {
|
||||
catDoc = csaf.NewROLIECategoryDocument(categories...)
|
||||
}
|
||||
|
||||
for _, t := range c.TLPs {
|
||||
if t == tlpCSAF {
|
||||
continue
|
||||
|
|
@ -83,6 +93,13 @@ func createFeedFolders(c *config, wellknown string) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
// Store the category document.
|
||||
if catDoc != nil {
|
||||
catPath := path.Join(tlpLink, "category.json")
|
||||
if err := util.WriteToFile(catPath, catDoc); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,20 @@ type ROLIECategoryDocument struct {
|
|||
Categories ROLIECategories `json:"categories"`
|
||||
}
|
||||
|
||||
// NewROLIECategoryDocument creates a new ROLIE category document from a list
|
||||
// of categories.
|
||||
func NewROLIECategoryDocument(categories ...string) *ROLIECategoryDocument {
|
||||
cats := make([]ROLIECategory, len(categories))
|
||||
for i, cat := range categories {
|
||||
cats[i] = ROLIECategory{Term: cat}
|
||||
}
|
||||
return &ROLIECategoryDocument{
|
||||
Categories: ROLIECategories{
|
||||
Category: cats,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// LoadROLIECategoryDocument loads a ROLIE category document from a reader.
|
||||
func LoadROLIECategoryDocument(r io.Reader) (*ROLIECategoryDocument, error) {
|
||||
var rcd ROLIECategoryDocument
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue