(conn *grpc.ClientConn)
| 62 | } |
| 63 | |
| 64 | func 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 |
| 101 | func register(builtin *ast.Builtin, impl topdown.BuiltinFunc) error { |
no test coverage detected