1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00
gocsaf/csaf/summary.go
Bernhard E. Reiter cf49c7e414
Fix go.mod and internal dependencies (#371)
* Use a "/v2" in the module path to match the git version tag which
   lead with a 2. Change all mention of the module as dependency
   internally as well.
2023-06-05 10:24:35 +02:00

65 lines
2.2 KiB
Go

// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2021 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2021 Intevation GmbH <https://intevation.de>
package csaf
import (
"time"
"github.com/csaf-poc/csaf_distribution/v2/util"
)
const (
idExpr = `$.document.tracking.id`
titleExpr = `$.document.title`
publisherExpr = `$.document.publisher`
initialReleaseDateExpr = `$.document.tracking.initial_release_date`
currentReleaseDateExpr = `$.document.tracking.current_release_date`
tlpLabelExpr = `$.document.distribution.tlp.label`
summaryExpr = `$.document.notes[? @.category=="summary" || @.type=="summary"].text`
statusExpr = `$.document.tracking.status`
)
// AdvisorySummary is a summary of some essentials of an CSAF advisory.
type AdvisorySummary struct {
ID string
Title string
Publisher *Publisher
InitialReleaseDate time.Time
CurrentReleaseDate time.Time
Summary string
TLPLabel string
Status string
}
// NewAdvisorySummary creates a summary from an advisory doc
// with the help of an expression evaluator expr.
func NewAdvisorySummary(
pe *util.PathEval,
doc any,
) (*AdvisorySummary, error) {
e := &AdvisorySummary{
Publisher: new(Publisher),
}
if err := pe.Match([]util.PathEvalMatcher{
{Expr: idExpr, Action: util.StringMatcher(&e.ID)},
{Expr: titleExpr, Action: util.StringMatcher(&e.Title)},
{Expr: currentReleaseDateExpr, Action: util.TimeMatcher(&e.CurrentReleaseDate, time.RFC3339)},
{Expr: initialReleaseDateExpr, Action: util.TimeMatcher(&e.InitialReleaseDate, time.RFC3339)},
{Expr: summaryExpr, Action: util.StringMatcher(&e.Summary), Optional: true},
{Expr: tlpLabelExpr, Action: util.StringMatcher(&e.TLPLabel), Optional: true},
{Expr: publisherExpr, Action: util.ReMarshalMatcher(e.Publisher)},
{Expr: statusExpr, Action: util.StringMatcher(&e.Status)},
}, doc); err != nil {
return nil, err
}
return e, nil
}