Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Addition = func(lhs, rhs ref.Val) ref.Val { return elements.NodeList{ NodeList: &sbom.NodeList{}, } }
var AdditionOp = func(vals ...ref.Val) ref.Val { return elements.NodeList{ NodeList: &sbom.NodeList{}, } }
var Files = func(lhs ref.Val) ref.Val { nodeList, err := getTypedNodes(lhs, sbom.Node_FILE) if err != nil { return types.NewErr(err.Error()) } return nodeList }
Files returns all the Nodes marked as type file from an element. The function supports documents, nodelists, and nodes. If the node is a file, it will return a NodeList with it as the single node or empty if it is a package.
If the passed type is not supported, the return value will be an error.
var LoadSBOM = func(_, pathVal ref.Val) ref.Val { path, ok := pathVal.Value().(string) if !ok { return types.NewErr("argument to element by id has to be a string") } f, err := os.Open(path) if err != nil { return types.NewErr("opening SBOM file: %w", err) } doc, err := loader.ReadSBOM(f) if err != nil { return types.NewErr("loading document: %w", err) } return elements.Document{ Document: doc, } }
var NodeByID = func(lhs, rawID ref.Val) ref.Val { queryID, ok := rawID.Value().(string) if !ok { return types.NewErr("argument to element by id has to be a string") } var node *sbom.Node switch v := lhs.Value().(type) { case *sbom.Document: node = v.NodeList.GetNodeByID(queryID) case *sbom.NodeList: node = v.GetNodeByID(queryID) case *sbom.Node: if v.Id == queryID { node = v } default: return types.NewErr("method unsupported on type %T", lhs.Value()) } if node == nil { return nil } return elements.Node{ Node: node, } }
NodeByID returns a Node matching the specified ID
var NodesByPurlType = func(lhs, rhs ref.Val) ref.Val { purlType, ok := rhs.Value().(string) if !ok { return types.NewErr("argument to GetNodesByPurlType must be a string") } var nl *sbom.NodeList switch v := lhs.Value().(type) { case *sbom.Document: nl = v.NodeList.GetNodesByPurlType(purlType) case *sbom.NodeList: nl = v.GetNodesByPurlType(purlType) default: return types.NewErr("method unsupported on type %T", lhs.Value()) } return elements.NodeList{ NodeList: nl, } }
var Packages = func(lhs ref.Val) ref.Val { nodeList, err := getTypedNodes(lhs, sbom.Node_PACKAGE) if err != nil { return types.NewErr(err.Error()) } return nodeList }
Packages returns a NodeList with any packages in the lhs element. It supports Documents, NodeLists and Nodes. If a node is provided it will return a NodeList with the single node it is a package, otherwise it will be empty.
If lhs is an unsupprted type, Packages will return an error.
var RelateNodeListAtID = func(vals ...ref.Val) ref.Val { if len(vals) != 4 { return types.NewErr("invalid number of arguments for RealteAtNodeListAtID") } id, ok := vals[2].Value().(string) if !ok { return types.NewErr("node id has to be a string") } _, ok = vals[3].Value().(string) if !ok { return types.NewErr("relationship type has has to be a string") } nodelist, ok := vals[1].(elements.NodeList) if !ok { return types.NewErr("could not cast nodelist") } switch v := vals[0].Value().(type) { case *sbom.Document: if err := v.NodeList.RelateNodeListAtID(nodelist.Value().(*sbom.NodeList), id, sbom.Edge_dependsOn); err != nil { return types.NewErr(err.Error()) } return elements.Document{ Document: v, } case *sbom.NodeList: if err := v.RelateNodeListAtID(nodelist.Value().(*sbom.NodeList), id, sbom.Edge_dependsOn); err != nil { return types.NewErr(err.Error()) } return elements.NodeList{ NodeList: v, } default: return types.NewErr("method unsupported on type %T", vals[0].Value()) } }
RelateNodeListAtID relates a nodelist at the specified ID
var ToDocument = func(lhs ref.Val) ref.Val { var nodelist *elements.NodeList switch v := lhs.Value().(type) { case *sbom.NodeList: nodelist = &elements.NodeList{NodeList: v} case *elements.NodeList: nodelist = v case *elements.Node: nodelist = v.ToNodeList() case *sbom.Node: nodelist = elements.Node{Node: v}.ToNodeList() default: return types.NewErr("unable to convert element to document") } reconnectOrphanNodes(nodelist) doc := elements.Document{ Document: &sbom.Document{ Metadata: &sbom.Metadata{ Id: "", Version: "1", Name: "bomshell generated document", Date: timestamppb.Now(), Tools: []*sbom.Tool{ { Name: "bomshell", Version: version.GetVersionInfo().GitVersion, Vendor: "Chainguard Labs", }, }, Authors: []*sbom.Person{}, Comment: "This document was generated by bomshell from a protobom nodelist", }, NodeList: nodelist.NodeList, }, } return doc }
ToDocument converts an element into a fill document. This is useful when bomshell needs to convert its results to a document to output them as an SBOM
var ToNodeList = func(lhs ref.Val) ref.Val { switch v := lhs.Value().(type) { case *sbom.Document: return elements.NodeList{ NodeList: v.NodeList, } case *elements.Document: return elements.NodeList{ NodeList: v.Document.NodeList, } case *sbom.NodeList: return elements.NodeList{ NodeList: v, } case *elements.NodeList: return v case *elements.Node: nl := v.ToNodeList() return *nl case *sbom.Node: nl := elements.Node{ Node: v, }.ToNodeList() return *nl default: return types.NewErr("type does not support conversion to NodeList" + fmt.Sprintf("%T", v)) } }
ToNodeList takes a node and returns a new NodeList with that nodelist with the node as the only member.
Functions ¶
This section is empty.
Types ¶
This section is empty.