mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Demand Go 1.19 in go.mod. Replaced interface{} with any
This commit is contained in:
parent
1189d538b3
commit
c4b70d20cd
15 changed files with 74 additions and 74 deletions
|
|
@ -78,7 +78,7 @@ func (w *worker) checkInterims(
|
||||||
data.Reset()
|
data.Reset()
|
||||||
hasher := io.MultiWriter(s256, &data)
|
hasher := io.MultiWriter(s256, &data)
|
||||||
|
|
||||||
var doc interface{}
|
var doc any
|
||||||
if err := func() error {
|
if err := func() error {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
tee := io.TeeReader(res.Body, hasher)
|
tee := io.TeeReader(res.Body, hasher)
|
||||||
|
|
|
||||||
|
|
@ -430,7 +430,7 @@ func (w *worker) sign(data []byte) (string, error) {
|
||||||
sig.Data, constants.PGPSignatureHeader, "", "")
|
sig.Data, constants.PGPSignatureHeader, "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worker) extractCategories(label string, advisory interface{}) error {
|
func (w *worker) extractCategories(label string, advisory any) error {
|
||||||
|
|
||||||
// use provider or global categories
|
// use provider or global categories
|
||||||
var categories []string
|
var categories []string
|
||||||
|
|
@ -499,7 +499,7 @@ func (w *worker) mirrorFiles(tlpLabel csaf.TLPLabel, files []csaf.AdvisoryFile)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var advisory interface{}
|
var advisory any
|
||||||
|
|
||||||
s256 := sha256.New()
|
s256 := sha256.New()
|
||||||
s512 := sha512.New()
|
s512 := sha512.New()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ type worker struct {
|
||||||
|
|
||||||
client util.Client // client per provider
|
client util.Client // client per provider
|
||||||
provider *provider // current provider
|
provider *provider // current provider
|
||||||
metadataProvider interface{} // current metadata provider
|
metadataProvider any // current metadata provider
|
||||||
loc string // URL of current provider-metadata.json
|
loc string // URL of current provider-metadata.json
|
||||||
dir string // Directory to store data to.
|
dir string // Directory to store data to.
|
||||||
summaries map[string][]summary // the summaries of the advisories.
|
summaries map[string][]summary // the summaries of the advisories.
|
||||||
|
|
@ -80,7 +80,7 @@ func (w *worker) createDir() (string, error) {
|
||||||
func (w *worker) locateProviderMetadata(domain string) error {
|
func (w *worker) locateProviderMetadata(domain string) error {
|
||||||
|
|
||||||
lpmd := csaf.LoadProviderMetadataForDomain(
|
lpmd := csaf.LoadProviderMetadataForDomain(
|
||||||
w.client, domain, func(format string, args ...interface{}) {
|
w.client, domain, func(format string, args ...any) {
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
|
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ type processor struct {
|
||||||
alreadyChecked map[string]whereType
|
alreadyChecked map[string]whereType
|
||||||
pmdURL string
|
pmdURL string
|
||||||
pmd256 []byte
|
pmd256 []byte
|
||||||
pmd interface{}
|
pmd any
|
||||||
keys []*crypto.KeyRing
|
keys []*crypto.KeyRing
|
||||||
|
|
||||||
badIntegrities topicMessages
|
badIntegrities topicMessages
|
||||||
|
|
@ -112,22 +112,22 @@ func (wt whereType) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add adds a message to this topic.
|
// add adds a message to this topic.
|
||||||
func (m *topicMessages) add(typ MessageType, format string, args ...interface{}) {
|
func (m *topicMessages) add(typ MessageType, format string, args ...any) {
|
||||||
*m = append(*m, Message{Type: typ, Text: fmt.Sprintf(format, args...)})
|
*m = append(*m, Message{Type: typ, Text: fmt.Sprintf(format, args...)})
|
||||||
}
|
}
|
||||||
|
|
||||||
// error adds an error message to this topic.
|
// error adds an error message to this topic.
|
||||||
func (m *topicMessages) error(format string, args ...interface{}) {
|
func (m *topicMessages) error(format string, args ...any) {
|
||||||
m.add(ErrorType, format, args...)
|
m.add(ErrorType, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// warn adds a warning message to this topic.
|
// warn adds a warning message to this topic.
|
||||||
func (m *topicMessages) warn(format string, args ...interface{}) {
|
func (m *topicMessages) warn(format string, args ...any) {
|
||||||
m.add(WarnType, format, args...)
|
m.add(WarnType, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// info adds an info message to this topic.
|
// info adds an info message to this topic.
|
||||||
func (m *topicMessages) info(format string, args ...interface{}) {
|
func (m *topicMessages) info(format string, args ...any) {
|
||||||
m.add(InfoType, format, args...)
|
m.add(InfoType, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,7 +378,7 @@ func (p *processor) integrity(
|
||||||
files []csaf.AdvisoryFile,
|
files []csaf.AdvisoryFile,
|
||||||
base string,
|
base string,
|
||||||
mask whereType,
|
mask whereType,
|
||||||
lg func(MessageType, string, ...interface{}),
|
lg func(MessageType, string, ...any),
|
||||||
) error {
|
) error {
|
||||||
b, err := url.Parse(base)
|
b, err := url.Parse(base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -440,7 +440,7 @@ func (p *processor) integrity(
|
||||||
data.Reset()
|
data.Reset()
|
||||||
hasher := io.MultiWriter(s256, s512, &data)
|
hasher := io.MultiWriter(s256, s512, &data)
|
||||||
|
|
||||||
var doc interface{}
|
var doc any
|
||||||
|
|
||||||
if err := func() error {
|
if err := func() error {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
@ -592,7 +592,7 @@ func (p *processor) processROLIEFeed(feed string) error {
|
||||||
return errContinue
|
return errContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
rfeed, rolieDoc, err := func() (*csaf.ROLIEFeed, interface{}, error) {
|
rfeed, rolieDoc, err := func() (*csaf.ROLIEFeed, any, error) {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
all, err := io.ReadAll(res.Body)
|
all, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -602,7 +602,7 @@ func (p *processor) processROLIEFeed(feed string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("%s: %v", feed, err)
|
return nil, nil, fmt.Errorf("%s: %v", feed, err)
|
||||||
}
|
}
|
||||||
var rolieDoc interface{}
|
var rolieDoc any
|
||||||
err = json.NewDecoder(bytes.NewReader(all)).Decode(&rolieDoc)
|
err = json.NewDecoder(bytes.NewReader(all)).Decode(&rolieDoc)
|
||||||
return rfeed, rolieDoc, err
|
return rfeed, rolieDoc, err
|
||||||
|
|
||||||
|
|
@ -899,7 +899,7 @@ func (p *processor) checkCSAFs(domain string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fs, hasRolie := rolie.([]interface{})
|
fs, hasRolie := rolie.([]any)
|
||||||
hasRolie = hasRolie && len(fs) > 0
|
hasRolie = hasRolie && len(fs) > 0
|
||||||
|
|
||||||
if hasRolie {
|
if hasRolie {
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func (d *downloader) httpClient() util.Client {
|
||||||
func (d *downloader) download(domain string) error {
|
func (d *downloader) download(domain string) error {
|
||||||
|
|
||||||
lpmd := csaf.LoadProviderMetadataForDomain(
|
lpmd := csaf.LoadProviderMetadataForDomain(
|
||||||
d.httpClient(), domain, func(format string, args ...interface{}) {
|
d.httpClient(), domain, func(format string, args ...any) {
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
|
"Looking for provider-metadata.json of '"+domain+"': "+format+"\n", args...)
|
||||||
})
|
})
|
||||||
|
|
@ -122,7 +122,7 @@ func (d *downloader) download(domain string) error {
|
||||||
|
|
||||||
func (d *downloader) loadOpenPGPKeys(
|
func (d *downloader) loadOpenPGPKeys(
|
||||||
client util.Client,
|
client util.Client,
|
||||||
doc interface{},
|
doc any,
|
||||||
base *url.URL,
|
base *url.URL,
|
||||||
) error {
|
) error {
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@ func (d *downloader) downloadFiles(label csaf.TLPLabel, files []csaf.AdvisoryFil
|
||||||
// Download the advisory and hash it.
|
// Download the advisory and hash it.
|
||||||
hasher := io.MultiWriter(writers...)
|
hasher := io.MultiWriter(writers...)
|
||||||
|
|
||||||
var doc interface{}
|
var doc any
|
||||||
|
|
||||||
if err := func() error {
|
if err := func() error {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (c *controller) tlpParam(r *http.Request) (tlp, error) {
|
||||||
|
|
||||||
// create calls the "ensureFolders" functions to create the directories and files.
|
// create calls the "ensureFolders" functions to create the directories and files.
|
||||||
// It returns a struct by success, otherwise an error.
|
// It returns a struct by success, otherwise an error.
|
||||||
func (c *controller) create(*http.Request) (interface{}, error) {
|
func (c *controller) create(*http.Request) (any, error) {
|
||||||
if err := ensureFolders(c.cfg); err != nil {
|
if err := ensureFolders(c.cfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -144,14 +144,14 @@ func (c *controller) create(*http.Request) (interface{}, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) upload(r *http.Request) (interface{}, error) {
|
func (c *controller) upload(r *http.Request) (any, error) {
|
||||||
|
|
||||||
newCSAF, data, err := c.loadCSAF(r)
|
newCSAF, data, err := c.loadCSAF(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var content interface{}
|
var content any
|
||||||
if err := json.Unmarshal(data, &content); err != nil {
|
if err := json.Unmarshal(data, &content); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ func (c *controller) auth(
|
||||||
// render sets the headers for the response. It applies the given template "tmpl" to
|
// render sets the headers for the response. It applies the given template "tmpl" to
|
||||||
// the given object "arg" and writes the output to http.ResponseWriter.
|
// the given object "arg" and writes the output to http.ResponseWriter.
|
||||||
// It logs a warning in case of error.
|
// It logs a warning in case of error.
|
||||||
func (c *controller) render(rw http.ResponseWriter, tmpl string, arg interface{}) {
|
func (c *controller) render(rw http.ResponseWriter, tmpl string, arg any) {
|
||||||
rw.Header().Set("Content-type", "text/html; charset=utf-8")
|
rw.Header().Set("Content-type", "text/html; charset=utf-8")
|
||||||
rw.Header().Set("X-Content-Type-Options", "nosniff")
|
rw.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
if err := c.tmpl.ExecuteTemplate(rw, tmpl, arg); err != nil {
|
if err := c.tmpl.ExecuteTemplate(rw, tmpl, arg); err != nil {
|
||||||
|
|
@ -142,13 +142,13 @@ func (c *controller) render(rw http.ResponseWriter, tmpl string, arg interface{}
|
||||||
// failed constructs the error messages by calling "asMultiError" and calls "render"
|
// failed constructs the error messages by calling "asMultiError" and calls "render"
|
||||||
// function to render the passed template and error object.
|
// function to render the passed template and error object.
|
||||||
func (c *controller) failed(rw http.ResponseWriter, tmpl string, err error) {
|
func (c *controller) failed(rw http.ResponseWriter, tmpl string, err error) {
|
||||||
result := map[string]interface{}{"Error": asMultiError(err)}
|
result := map[string]any{"Error": asMultiError(err)}
|
||||||
c.render(rw, tmpl, result)
|
c.render(rw, tmpl, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// index calls the "render" function and passes the "index.html" and c.cfg to it.
|
// index calls the "render" function and passes the "index.html" and c.cfg to it.
|
||||||
func (c *controller) index(rw http.ResponseWriter, r *http.Request) {
|
func (c *controller) index(rw http.ResponseWriter, r *http.Request) {
|
||||||
c.render(rw, "index.html", map[string]interface{}{
|
c.render(rw, "index.html", map[string]any{
|
||||||
"Config": c.cfg,
|
"Config": c.cfg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +158,7 @@ func (c *controller) index(rw http.ResponseWriter, r *http.Request) {
|
||||||
// in case of no error occurred, otherwise calls the "failed" function and passes the given
|
// in case of no error occurred, otherwise calls the "failed" function and passes the given
|
||||||
// template and the error from "fn".
|
// template and the error from "fn".
|
||||||
func (c *controller) web(
|
func (c *controller) web(
|
||||||
fn func(*http.Request) (interface{}, error),
|
fn func(*http.Request) (any, error),
|
||||||
tmpl string,
|
tmpl string,
|
||||||
) func(http.ResponseWriter, *http.Request) {
|
) func(http.ResponseWriter, *http.Request) {
|
||||||
|
|
||||||
|
|
@ -173,7 +173,7 @@ func (c *controller) web(
|
||||||
|
|
||||||
// writeJSON sets the header for the response and writes the JSON encoding of the given "content".
|
// writeJSON sets the header for the response and writes the JSON encoding of the given "content".
|
||||||
// It logs out an error message in case of an error.
|
// It logs out an error message in case of an error.
|
||||||
func writeJSON(rw http.ResponseWriter, content interface{}, code int) {
|
func writeJSON(rw http.ResponseWriter, content any, code int) {
|
||||||
rw.Header().Set("Content-type", "application/json; charset=utf-8")
|
rw.Header().Set("Content-type", "application/json; charset=utf-8")
|
||||||
rw.Header().Set("X-Content-Type-Options", "nosniff")
|
rw.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
rw.WriteHeader(code)
|
rw.WriteHeader(code)
|
||||||
|
|
@ -182,7 +182,7 @@ func writeJSON(rw http.ResponseWriter, content interface{}, code int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorToContent(err error) interface{} {
|
func errorToContent(err error) any {
|
||||||
return &struct {
|
return &struct {
|
||||||
Errors multiError `json:"errors"`
|
Errors multiError `json:"errors"`
|
||||||
}{
|
}{
|
||||||
|
|
@ -191,7 +191,7 @@ func errorToContent(err error) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func api(
|
func api(
|
||||||
fn func(*http.Request) (interface{}, error),
|
fn func(*http.Request) (any, error),
|
||||||
) func(http.ResponseWriter, *http.Request) {
|
) func(http.ResponseWriter, *http.Request) {
|
||||||
|
|
||||||
return func(rw http.ResponseWriter, r *http.Request) {
|
return func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ func (p *processor) uploadRequest(filename string) (*http.Request, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.opts.NoSchemaCheck {
|
if !p.opts.NoSchemaCheck {
|
||||||
var doc interface{}
|
var doc any
|
||||||
if err := json.NewDecoder(bytes.NewReader(data)).Decode(&doc); err != nil {
|
if err := json.NewDecoder(bytes.NewReader(data)).Decode(&doc); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,9 @@ func (haf HashedAdvisoryFile) SignURL() string { return haf.name(3, ".asc") }
|
||||||
type AdvisoryFileProcessor struct {
|
type AdvisoryFileProcessor struct {
|
||||||
client util.Client
|
client util.Client
|
||||||
expr *util.PathEval
|
expr *util.PathEval
|
||||||
doc interface{}
|
doc any
|
||||||
base *url.URL
|
base *url.URL
|
||||||
log func(format string, args ...interface{})
|
log func(format string, args ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAdvisoryFileProcessor constructs an filename extractor
|
// NewAdvisoryFileProcessor constructs an filename extractor
|
||||||
|
|
@ -83,9 +83,9 @@ type AdvisoryFileProcessor struct {
|
||||||
func NewAdvisoryFileProcessor(
|
func NewAdvisoryFileProcessor(
|
||||||
client util.Client,
|
client util.Client,
|
||||||
expr *util.PathEval,
|
expr *util.PathEval,
|
||||||
doc interface{},
|
doc any,
|
||||||
base *url.URL,
|
base *url.URL,
|
||||||
log func(format string, args ...interface{}),
|
log func(format string, args ...any),
|
||||||
) *AdvisoryFileProcessor {
|
) *AdvisoryFileProcessor {
|
||||||
return &AdvisoryFileProcessor{
|
return &AdvisoryFileProcessor{
|
||||||
client: client,
|
client: client,
|
||||||
|
|
@ -113,7 +113,7 @@ func (afp *AdvisoryFileProcessor) Process(
|
||||||
) error {
|
) error {
|
||||||
lg := afp.log
|
lg := afp.log
|
||||||
if lg == nil {
|
if lg == nil {
|
||||||
lg = func(format string, args ...interface{}) {
|
lg = func(format string, args ...any) {
|
||||||
log.Printf("AdvisoryFileProcessor.Process: "+format, args...)
|
log.Printf("AdvisoryFileProcessor.Process: "+format, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ func (afp *AdvisoryFileProcessor) Process(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fs, hasRolie := rolie.([]interface{})
|
fs, hasRolie := rolie.([]any)
|
||||||
hasRolie = hasRolie && len(fs) > 0
|
hasRolie = hasRolie && len(fs) > 0
|
||||||
|
|
||||||
if hasRolie {
|
if hasRolie {
|
||||||
|
|
@ -190,7 +190,7 @@ func (afp *AdvisoryFileProcessor) Process(
|
||||||
// prefixed by baseURL/.
|
// prefixed by baseURL/.
|
||||||
func (afp *AdvisoryFileProcessor) loadIndex(
|
func (afp *AdvisoryFileProcessor) loadIndex(
|
||||||
baseURL string,
|
baseURL string,
|
||||||
lg func(string, ...interface{}),
|
lg func(string, ...any),
|
||||||
) ([]AdvisoryFile, error) {
|
) ([]AdvisoryFile, error) {
|
||||||
|
|
||||||
base, err := url.Parse(baseURL)
|
base, err := url.Parse(baseURL)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ type test struct {
|
||||||
// outDocument is the document send to the remote validation service.
|
// outDocument is the document send to the remote validation service.
|
||||||
type outDocument struct {
|
type outDocument struct {
|
||||||
Tests []test `json:"tests"`
|
Tests []test `json:"tests"`
|
||||||
Document interface{} `json:"document"`
|
Document any `json:"document"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// inDocument is the document recieved from the remote validation service.
|
// inDocument is the document recieved from the remote validation service.
|
||||||
|
|
@ -70,7 +70,7 @@ type cache interface {
|
||||||
|
|
||||||
// RemoteValidator validates an advisory document remotely.
|
// RemoteValidator validates an advisory document remotely.
|
||||||
type RemoteValidator interface {
|
type RemoteValidator interface {
|
||||||
Validate(doc interface{}) (bool, error)
|
Validate(doc any) (bool, error)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ type syncedRemoteValidator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate implements the validation part of the RemoteValidator interface.
|
// Validate implements the validation part of the RemoteValidator interface.
|
||||||
func (srv *syncedRemoteValidator) Validate(doc interface{}) (bool, error) {
|
func (srv *syncedRemoteValidator) Validate(doc any) (bool, error) {
|
||||||
srv.Lock()
|
srv.Lock()
|
||||||
defer srv.Unlock()
|
defer srv.Unlock()
|
||||||
return srv.RemoteValidator.Validate(doc)
|
return srv.RemoteValidator.Validate(doc)
|
||||||
|
|
@ -204,7 +204,7 @@ func (v *remoteValidator) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// key calculates the key for an advisory document and presets.
|
// key calculates the key for an advisory document and presets.
|
||||||
func (v *remoteValidator) key(doc interface{}) ([]byte, error) {
|
func (v *remoteValidator) key(doc any) ([]byte, error) {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
if err := json.NewEncoder(h).Encode(doc); err != nil {
|
if err := json.NewEncoder(h).Encode(doc); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -218,7 +218,7 @@ func (v *remoteValidator) key(doc interface{}) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate executes a remote validation of an advisory.
|
// Validate executes a remote validation of an advisory.
|
||||||
func (v *remoteValidator) Validate(doc interface{}) (bool, error) {
|
func (v *remoteValidator) Validate(doc any) (bool, error) {
|
||||||
|
|
||||||
var key []byte
|
var key []byte
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type AdvisorySummary struct {
|
||||||
// with the help of an expression evaluator expr.
|
// with the help of an expression evaluator expr.
|
||||||
func NewAdvisorySummary(
|
func NewAdvisorySummary(
|
||||||
pe *util.PathEval,
|
pe *util.PathEval,
|
||||||
doc interface{},
|
doc any,
|
||||||
) (*AdvisorySummary, error) {
|
) (*AdvisorySummary, error) {
|
||||||
|
|
||||||
e := &AdvisorySummary{
|
e := &AdvisorySummary{
|
||||||
|
|
|
||||||
16
csaf/util.go
16
csaf/util.go
|
|
@ -27,7 +27,7 @@ type LoadedProviderMetadata struct {
|
||||||
// URL is location where the document was found.
|
// URL is location where the document was found.
|
||||||
URL string
|
URL string
|
||||||
// Document is the de-serialized JSON document.
|
// Document is the de-serialized JSON document.
|
||||||
Document interface{}
|
Document any
|
||||||
// Hash is a SHA256 sum over the document.
|
// Hash is a SHA256 sum over the document.
|
||||||
Hash []byte
|
Hash []byte
|
||||||
// Messages are the error message happened while loading.
|
// Messages are the error message happened while loading.
|
||||||
|
|
@ -41,14 +41,14 @@ func (lpm *LoadedProviderMetadata) Valid() bool {
|
||||||
|
|
||||||
// defaultLogging generates a logging function if given is nil.
|
// defaultLogging generates a logging function if given is nil.
|
||||||
func defaultLogging(
|
func defaultLogging(
|
||||||
logging func(format string, args ...interface{}),
|
logging func(format string, args ...any),
|
||||||
prefix, suffix string,
|
prefix, suffix string,
|
||||||
) func(format string, args ...interface{}) {
|
) func(format string, args ...any) {
|
||||||
|
|
||||||
if logging != nil {
|
if logging != nil {
|
||||||
return logging
|
return logging
|
||||||
}
|
}
|
||||||
return func(format string, args ...interface{}) {
|
return func(format string, args ...any) {
|
||||||
log.Printf(prefix+format+suffix, args...)
|
log.Printf(prefix+format+suffix, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ func LoadProviderMetadataFromURL(
|
||||||
client util.Client,
|
client util.Client,
|
||||||
url string,
|
url string,
|
||||||
already map[string]*LoadedProviderMetadata,
|
already map[string]*LoadedProviderMetadata,
|
||||||
logging func(format string, args ...interface{}),
|
logging func(format string, args ...any),
|
||||||
) *LoadedProviderMetadata {
|
) *LoadedProviderMetadata {
|
||||||
|
|
||||||
logging = defaultLogging(logging, "LoadProviderMetadataFromURL: ", "\n")
|
logging = defaultLogging(logging, "LoadProviderMetadataFromURL: ", "\n")
|
||||||
|
|
@ -85,7 +85,7 @@ func LoadProviderMetadataFromURL(
|
||||||
|
|
||||||
tee := io.TeeReader(res.Body, hash)
|
tee := io.TeeReader(res.Body, hash)
|
||||||
|
|
||||||
var doc interface{}
|
var doc any
|
||||||
|
|
||||||
err = json.NewDecoder(tee).Decode(&doc)
|
err = json.NewDecoder(tee).Decode(&doc)
|
||||||
// Before checking the err lets check if we had the same
|
// Before checking the err lets check if we had the same
|
||||||
|
|
@ -143,7 +143,7 @@ func LoadProviderMetadatasFromSecurity(
|
||||||
client util.Client,
|
client util.Client,
|
||||||
path string,
|
path string,
|
||||||
already map[string]*LoadedProviderMetadata,
|
already map[string]*LoadedProviderMetadata,
|
||||||
logging func(format string, args ...interface{}),
|
logging func(format string, args ...any),
|
||||||
) []*LoadedProviderMetadata {
|
) []*LoadedProviderMetadata {
|
||||||
|
|
||||||
logging = defaultLogging(logging, "LoadProviderMetadataFromSecurity: ", "\n")
|
logging = defaultLogging(logging, "LoadProviderMetadataFromSecurity: ", "\n")
|
||||||
|
|
@ -191,7 +191,7 @@ func LoadProviderMetadatasFromSecurity(
|
||||||
func LoadProviderMetadataForDomain(
|
func LoadProviderMetadataForDomain(
|
||||||
client util.Client,
|
client util.Client,
|
||||||
domain string,
|
domain string,
|
||||||
logging func(format string, args ...interface{}),
|
logging func(format string, args ...any),
|
||||||
) *LoadedProviderMetadata {
|
) *LoadedProviderMetadata {
|
||||||
|
|
||||||
logging = defaultLogging(logging, "LoadProviderMetadataForDomain: ", "\n")
|
logging = defaultLogging(logging, "LoadProviderMetadataForDomain: ", "\n")
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (cs *compiledSchema) compiler(sds []schemaData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *compiledSchema) validate(doc interface{}) ([]string, error) {
|
func (cs *compiledSchema) validate(doc any) ([]string, error) {
|
||||||
cs.once.Do(cs.compile)
|
cs.once.Do(cs.compile)
|
||||||
|
|
||||||
if cs.err != nil {
|
if cs.err != nil {
|
||||||
|
|
@ -153,24 +153,24 @@ func (cs *compiledSchema) validate(doc interface{}) ([]string, error) {
|
||||||
|
|
||||||
// ValidateCSAF validates the document doc against the JSON schema
|
// ValidateCSAF validates the document doc against the JSON schema
|
||||||
// of CSAF.
|
// of CSAF.
|
||||||
func ValidateCSAF(doc interface{}) ([]string, error) {
|
func ValidateCSAF(doc any) ([]string, error) {
|
||||||
return compiledCSAFSchema.validate(doc)
|
return compiledCSAFSchema.validate(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateProviderMetadata validates the document doc against the JSON schema
|
// ValidateProviderMetadata validates the document doc against the JSON schema
|
||||||
// of provider metadata.
|
// of provider metadata.
|
||||||
func ValidateProviderMetadata(doc interface{}) ([]string, error) {
|
func ValidateProviderMetadata(doc any) ([]string, error) {
|
||||||
return compiledProviderSchema.validate(doc)
|
return compiledProviderSchema.validate(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateAggregator validates the document doc against the JSON schema
|
// ValidateAggregator validates the document doc against the JSON schema
|
||||||
// of aggregator.
|
// of aggregator.
|
||||||
func ValidateAggregator(doc interface{}) ([]string, error) {
|
func ValidateAggregator(doc any) ([]string, error) {
|
||||||
return compiledAggregatorSchema.validate(doc)
|
return compiledAggregatorSchema.validate(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateROLIE validates the ROLIE feed against the JSON schema
|
// ValidateROLIE validates the ROLIE feed against the JSON schema
|
||||||
// of ROLIE
|
// of ROLIE
|
||||||
func ValidateROLIE(doc interface{}) ([]string, error) {
|
func ValidateROLIE(doc any) ([]string, error) {
|
||||||
return compiledRolieSchema.validate(doc)
|
return compiledRolieSchema.validate(doc)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/csaf-poc/csaf_distribution
|
module github.com/csaf-poc/csaf_distribution
|
||||||
|
|
||||||
go 1.17
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.1.0
|
github.com/BurntSushi/toml v1.1.0
|
||||||
|
|
|
||||||
34
util/json.go
34
util/json.go
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReMarshalJSON transforms data from src to dst via JSON marshalling.
|
// ReMarshalJSON transforms data from src to dst via JSON marshalling.
|
||||||
func ReMarshalJSON(dst, src interface{}) error {
|
func ReMarshalJSON(dst, src any) error {
|
||||||
intermediate, err := json.Marshal(src)
|
intermediate, err := json.Marshal(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -44,7 +44,7 @@ func NewPathEval() *PathEval {
|
||||||
|
|
||||||
// Eval evalutes expression expr on document doc.
|
// Eval evalutes expression expr on document doc.
|
||||||
// Returns the result of the expression.
|
// Returns the result of the expression.
|
||||||
func (pe *PathEval) Eval(expr string, doc interface{}) (interface{}, error) {
|
func (pe *PathEval) Eval(expr string, doc any) (any, error) {
|
||||||
if doc == nil {
|
if doc == nil {
|
||||||
return nil, errors.New("no document to extract data from")
|
return nil, errors.New("no document to extract data from")
|
||||||
}
|
}
|
||||||
|
|
@ -65,21 +65,21 @@ type PathEvalMatcher struct {
|
||||||
// Expr is the expression to evaluate
|
// Expr is the expression to evaluate
|
||||||
Expr string
|
Expr string
|
||||||
// Action is executed with the result of the match.
|
// Action is executed with the result of the match.
|
||||||
Action func(interface{}) error
|
Action func(any) error
|
||||||
// Optional expresses if the expression is optional.
|
// Optional expresses if the expression is optional.
|
||||||
Optional bool
|
Optional bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReMarshalMatcher is an action to re-marshal the result to another type.
|
// ReMarshalMatcher is an action to re-marshal the result to another type.
|
||||||
func ReMarshalMatcher(dst interface{}) func(interface{}) error {
|
func ReMarshalMatcher(dst any) func(any) error {
|
||||||
return func(src interface{}) error {
|
return func(src any) error {
|
||||||
return ReMarshalJSON(dst, src)
|
return ReMarshalJSON(dst, src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoolMatcher stores the matched result in a bool.
|
// BoolMatcher stores the matched result in a bool.
|
||||||
func BoolMatcher(dst *bool) func(interface{}) error {
|
func BoolMatcher(dst *bool) func(any) error {
|
||||||
return func(x interface{}) error {
|
return func(x any) error {
|
||||||
b, ok := x.(bool)
|
b, ok := x.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("not a bool")
|
return errors.New("not a bool")
|
||||||
|
|
@ -90,8 +90,8 @@ func BoolMatcher(dst *bool) func(interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringMatcher stores the matched result in a string.
|
// StringMatcher stores the matched result in a string.
|
||||||
func StringMatcher(dst *string) func(interface{}) error {
|
func StringMatcher(dst *string) func(any) error {
|
||||||
return func(x interface{}) error {
|
return func(x any) error {
|
||||||
s, ok := x.(string)
|
s, ok := x.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("not a string")
|
return errors.New("not a string")
|
||||||
|
|
@ -102,8 +102,8 @@ func StringMatcher(dst *string) func(interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeMatcher stores a time with a given format.
|
// TimeMatcher stores a time with a given format.
|
||||||
func TimeMatcher(dst *time.Time, format string) func(interface{}) error {
|
func TimeMatcher(dst *time.Time, format string) func(any) error {
|
||||||
return func(x interface{}) error {
|
return func(x any) error {
|
||||||
s, ok := x.(string)
|
s, ok := x.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("not a string")
|
return errors.New("not a string")
|
||||||
|
|
@ -120,9 +120,9 @@ func TimeMatcher(dst *time.Time, format string) func(interface{}) error {
|
||||||
// Extract extracts a value from a given document with a given expression/action.
|
// Extract extracts a value from a given document with a given expression/action.
|
||||||
func (pe *PathEval) Extract(
|
func (pe *PathEval) Extract(
|
||||||
expr string,
|
expr string,
|
||||||
action func(interface{}) error,
|
action func(any) error,
|
||||||
optional bool,
|
optional bool,
|
||||||
doc interface{},
|
doc any,
|
||||||
) error {
|
) error {
|
||||||
optErr := func(err error) error {
|
optErr := func(err error) error {
|
||||||
if err == nil || optional {
|
if err == nil || optional {
|
||||||
|
|
@ -138,7 +138,7 @@ func (pe *PathEval) Extract(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match matches a list of PathEvalMatcher pairs against a document.
|
// Match matches a list of PathEvalMatcher pairs against a document.
|
||||||
func (pe *PathEval) Match(matcher []PathEvalMatcher, doc interface{}) error {
|
func (pe *PathEval) Match(matcher []PathEvalMatcher, doc any) error {
|
||||||
for _, m := range matcher {
|
for _, m := range matcher {
|
||||||
if err := pe.Extract(m.Expr, m.Action, m.Optional, doc); err != nil {
|
if err := pe.Extract(m.Expr, m.Action, m.Optional, doc); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -153,7 +153,7 @@ func (pe *PathEval) Match(matcher []PathEvalMatcher, doc interface{}) error {
|
||||||
func (pe *PathEval) Strings(
|
func (pe *PathEval) Strings(
|
||||||
exprs []string,
|
exprs []string,
|
||||||
optional bool,
|
optional bool,
|
||||||
doc interface{},
|
doc any,
|
||||||
) ([]string, error) {
|
) ([]string, error) {
|
||||||
results := make([]string, 0, len(exprs))
|
results := make([]string, 0, len(exprs))
|
||||||
var result string
|
var result string
|
||||||
|
|
@ -169,8 +169,8 @@ func (pe *PathEval) Strings(
|
||||||
|
|
||||||
// AsStrings transforms an []interface{string, string,... }
|
// AsStrings transforms an []interface{string, string,... }
|
||||||
// to a []string.
|
// to a []string.
|
||||||
func AsStrings(x interface{}) ([]string, bool) {
|
func AsStrings(x any) ([]string, bool) {
|
||||||
strs, ok := x.([]interface{})
|
strs, ok := x.([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue