You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: "Description of what this function does",
28
+
Decl: types.NewFunction(
29
+
types.Args(types.Named("input", types.S).Description("this is the input")),
30
+
types.Named("result", types.S).Description("this is the result"),
31
+
),
32
+
}, myFunctionImpl)
33
+
}
34
+
35
+
funcmyFunctionImpl(bctx topdown.BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
36
+
// Extract arguments
37
+
input, ok:= operands[0].Value.(ast.String)
38
+
if !ok {
39
+
return fmt.Errorf("input must be a string")
40
+
}
41
+
42
+
// Implement logic
43
+
result:=processInput(string(input))
44
+
45
+
// Return result
46
+
returniter(ast.StringTerm(result))
47
+
}
48
+
49
+
// Autoregisters on package load
50
+
funcinit() {
51
+
iferr:=RegisterMyBuiltins(); err != nil {
52
+
panic(fmt.Sprintf("failed to register built-ins: %v", err))
53
+
}
54
+
}
55
+
```
56
+
57
+
2.**Use in Policies** (`*.rego`):
58
+
```rego
59
+
package example
60
+
import rego.v1
61
+
62
+
result := {
63
+
"violations": violations,
64
+
"skipped": false
65
+
}
66
+
67
+
violations contains msg if {
68
+
output := chainloop.my_function(input.value)
69
+
output != "expected"
70
+
msg := "Function returned unexpected value"
71
+
}
72
+
```
73
+
74
+
**Guidelines**:
75
+
- Use `chainloop.*` namespace for all custom built-ins
76
+
- Functions that call third party services should be marked as non-restrictive by adding the `NonRestrictiveBuiltin` category to the builtin definition
0 commit comments