Skip to content

Commit

Permalink
🐛 Fix audit initialization
Browse files Browse the repository at this point in the history
Fixes #1721

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Sep 25, 2023
1 parent da98e29 commit 74ca184
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
66 changes: 66 additions & 0 deletions providers/os/resources/audit.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 21 additions & 6 deletions providers/os/resources/os.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74ca184

Please sign in to comment.