Skip to content

Commit e612892

Browse files
committed
Normalize function names to CEL conventions
Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]>
1 parent b10a87d commit e612892

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

pkg/elements/document.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/google/cel-go/cel"
1111
"github.com/google/cel-go/common/types"
1212
"github.com/google/cel-go/common/types/ref"
13+
"github.com/google/cel-go/common/types/traits"
1314
"github.com/protobom/protobom/pkg/sbom"
1415
)
1516

@@ -57,3 +58,22 @@ func (*Document) Type() ref.Type {
5758
func (d *Document) Value() any {
5859
return d.Document
5960
}
61+
62+
var _ traits.Indexer = (*Document)(nil)
63+
64+
func (d *Document) Get(index ref.Val) ref.Val {
65+
switch v := index.Value().(type) {
66+
case string:
67+
switch v {
68+
case "nodelist":
69+
return &NodeList{
70+
NodeList: d.NodeList,
71+
}
72+
default:
73+
return types.NewErr("no such key %v", index)
74+
}
75+
76+
default:
77+
return types.NewErr("no such key %v", index)
78+
}
79+
}

pkg/library/api.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func (*Protobom) Functions() []cel.EnvOption {
1717
return []cel.EnvOption{
1818
cel.Function(
19-
"files",
19+
"get_files",
2020
cel.MemberOverload(
2121
"sbom_files_binding", []*types.Type{elements.DocumentType}, elements.NodeListType,
2222
cel.UnaryBinding(functions.Files),
@@ -32,7 +32,7 @@ func (*Protobom) Functions() []cel.EnvOption {
3232
),
3333

3434
cel.Function(
35-
"packages",
35+
"get_packages",
3636
cel.MemberOverload(
3737
"sbom_packages_binding", []*cel.Type{elements.DocumentType}, elements.NodeListType,
3838
cel.UnaryBinding(functions.Packages),
@@ -59,7 +59,7 @@ func (*Protobom) Functions() []cel.EnvOption {
5959
),
6060

6161
cel.Function(
62-
"ToNodeList",
62+
"to_node_list",
6363
cel.MemberOverload(
6464
"document_tonodelist_binding",
6565
[]*cel.Type{elements.DocumentType}, elements.NodeListType,
@@ -80,7 +80,7 @@ func (*Protobom) Functions() []cel.EnvOption {
8080
// NodeByID returns a node looking it up by its identifier
8181
// Overloaded in: Document and NodeList.
8282
cel.Function(
83-
"NodeByID",
83+
"get_node_by_id",
8484
cel.MemberOverload(
8585
"sbom_nodebyid_binding", []*cel.Type{elements.DocumentType, cel.StringType}, elements.NodeType,
8686
cel.BinaryBinding(functions.NodeByID),
@@ -95,7 +95,7 @@ func (*Protobom) Functions() []cel.EnvOption {
9595
// package URL of a certain type.
9696
// Overloaded in: Document and NodeList.
9797
cel.Function(
98-
"NodesByPurlType",
98+
"get_nodes_by_purl_type",
9999
cel.MemberOverload(
100100
"sbom_nodesbypurltype_binding", []*cel.Type{elements.DocumentType, cel.StringType}, elements.NodeListType,
101101
cel.BinaryBinding(functions.NodesByPurlType),
@@ -160,7 +160,7 @@ func (*Protobom) Functions() []cel.EnvOption {
160160
// ToDocument wraps an element and returns a new Document
161161
// Overloaded in: Node NodeList and Document (noop)
162162
cel.Function(
163-
"ToDocument",
163+
"to_document",
164164
cel.MemberOverload(
165165
"document_todocument_binding",
166166
[]*cel.Type{elements.DocumentType}, elements.DocumentType,
@@ -179,7 +179,7 @@ func (*Protobom) Functions() []cel.EnvOption {
179179
),
180180

181181
cel.Function(
182-
"LoadSBOM",
182+
"load_sbom",
183183
cel.MemberOverload(
184184
"protobom_loadsbom_binding",
185185
[]*cel.Type{elements.ProtobomType, cel.StringType}, elements.DocumentType,
@@ -188,7 +188,7 @@ func (*Protobom) Functions() []cel.EnvOption {
188188
),
189189

190190
cel.Function(
191-
"RelateNodeListAtID",
191+
"relate_node_list_at_id",
192192
cel.MemberOverload(
193193
"sbom_relatenodesatid_binding",
194194
[]*cel.Type{elements.DocumentType, elements.NodeListType, cel.StringType, cel.StringType},

0 commit comments

Comments
 (0)