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

write category documents in create.

This commit is contained in:
Sascha L. Teichmann 2022-06-30 05:04:00 +02:00
parent df21b2575d
commit 72a7240fd0
2 changed files with 31 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"unicode" "unicode"
@ -65,6 +66,15 @@ func createWellknown(_ *config, wellknown string) error {
// No creation for the "csaf" option will be done. // No creation for the "csaf" option will be done.
// It creates also symbolic links to feed folders. // It creates also symbolic links to feed folders.
func createFeedFolders(c *config, wellknown string) error { 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 { for _, t := range c.TLPs {
if t == tlpCSAF { if t == tlpCSAF {
continue continue
@ -83,6 +93,13 @@ func createFeedFolders(c *config, wellknown string) error {
return err 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 return nil
} }

View file

@ -79,6 +79,20 @@ type ROLIECategoryDocument struct {
Categories ROLIECategories `json:"categories"` 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. // LoadROLIECategoryDocument loads a ROLIE category document from a reader.
func LoadROLIECategoryDocument(r io.Reader) (*ROLIECategoryDocument, error) { func LoadROLIECategoryDocument(r io.Reader) (*ROLIECategoryDocument, error) {
var rcd ROLIECategoryDocument var rcd ROLIECategoryDocument