diff --git a/providers/os/resources/audit.go b/providers/os/resources/audit.go new file mode 100644 index 0000000000..2e5b922bea --- /dev/null +++ b/providers/os/resources/audit.go @@ -0,0 +1,66 @@ +package resources + +import ( + "fmt" + "strconv" + + "go.mondoo.com/cnquery/llx" + "go.mondoo.com/cnquery/providers-sdk/v1/plugin" +) + +func (c *mqlAuditCvss) id() (string, error) { + if c.Score.Error != nil { + return "", c.Score.Error + } + score := c.Score.Data + + if c.Vector.Error != nil { + return "", c.Vector.Error + } + vector := c.Vector.Data + return "cvss/" + strconv.FormatFloat(score, 'f', 2, 64) + "/vector/" + vector, nil +} + +func (c *mqlAuditAdvisory) id() (string, error) { + return c.Mrn.Data, c.Mrn.Error +} + +func (c *mqlAuditCve) id() (string, error) { + return c.Mrn.Data, c.Mrn.Error +} + +func initAuditAdvisory(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { + if len(args) == 7 { + return args, nil, nil + } + + if _, ok := args["mrn"]; !ok { + return args, nil, fmt.Errorf("Initialized \"audit.advisory\" resource without a \"mrn\". This field is required.") + } + + return args, nil, nil +} + +func initAuditCve(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { + if len(args) == 8 { + return args, nil, nil + } + + if _, ok := args["mrn"]; !ok { + return args, nil, fmt.Errorf("Initialized \"audit.cve\" resource without a \"mrn\". This field is required.") + } + + return args, nil, nil +} + +func initAuditCvss(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { + if len(args) == 2 { + return args, nil, nil + } + + if _, ok := args["score"]; !ok { + return args, nil, fmt.Errorf("Initialized \"audit.cvss\" resource without a \"score\". This field is required.") + } + + return args, nil, nil +} diff --git a/providers/os/resources/os.lr.go b/providers/os/resources/os.lr.go index 4168f644ad..3edc38a0eb 100644 --- a/providers/os/resources/os.lr.go +++ b/providers/os/resources/os.lr.go @@ -43,15 +43,15 @@ func init() { Create: createPlatformCves, }, "audit.cvss": { - // to override args, implement: initAuditCvss(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Init: initAuditCvss, Create: createAuditCvss, }, "audit.advisory": { - // to override args, implement: initAuditAdvisory(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Init: initAuditAdvisory, Create: createAuditAdvisory, }, "audit.cve": { - // to override args, implement: initAuditCve(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Init: initAuditCve, Create: createAuditCve, }, "machine": { @@ -4605,7 +4605,12 @@ func createAuditCvss(runtime *plugin.Runtime, args map[string]*llx.RawData) (plu return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("audit.cvss", res.__id) @@ -4659,7 +4664,12 @@ func createAuditAdvisory(runtime *plugin.Runtime, args map[string]*llx.RawData) return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("audit.advisory", res.__id) @@ -4734,7 +4744,12 @@ func createAuditCve(runtime *plugin.Runtime, args map[string]*llx.RawData) (plug return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("audit.cve", res.__id)