MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / getDiscoverRegoImpl

Function getDiscoverRegoImpl

pkg/policies/engine/builtins/rego.go:64–98  ·  view source on GitHub ↗
(conn *grpc.ClientConn)

Source from the content-addressed store, hash-verified

62}
63
64func getDiscoverRegoImpl(conn *grpc.ClientConn) topdown.BuiltinFunc {
65 discoverSvc := NewDiscoverService(conn)
66
67 return func(bctx topdown.BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
68 if len(operands) < 1 {
69 return errors.New("need at least one operand")
70 }
71
72 var digest, kind ast.String
73 var ok bool
74
75 // Extract digest
76 digest, ok = operands[0].Value.(ast.String)
77 if !ok {
78 return errors.New("digest must be a string")
79 }
80
81 if len(operands) > 1 {
82 // Extract kind
83 kind, ok = operands[1].Value.(ast.String)
84 if !ok {
85 return errors.New("kind must be a string")
86 }
87 }
88
89 // Call the shared service
90 resp, err := discoverSvc.Discover(bctx.Context, string(digest), string(kind))
91 if err != nil {
92 return fmt.Errorf("failed to call discover endpoint: %w", err)
93 }
94
95 // call the iterator with the output value
96 return iter(ast.NewTerm(ast.MustInterfaceToValue(resp.Result)))
97 }
98}
99
100// register is a wrapper around topdown.RegisterBuiltinFunc to handle registration
101func register(builtin *ast.Builtin, impl topdown.BuiltinFunc) error {

Callers 1

RegisterDiscoverBuiltinFunction · 0.85

Calls 2

DiscoverMethod · 0.95
NewDiscoverServiceFunction · 0.85

Tested by

no test coverage detected