-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we allow users to disable specific functions in Checker? #899
Comments
Current, we define ourself Library to replace the StdLib. type filterLibrary struct {
functions map[string]bool
}
func (filterLibrary) LibraryName() string {
return "cel.j2gg0s.filter"
}
func (lib filterLibrary) CompileOptions() []cel.EnvOption {
opts := []cel.EnvOption{}
for _, fn := range stdlib.Functions() {
if !lib.functions[fn.Name()] {
continue
}
fn := fn
opts = append(opts, cel.Function(fn.Name(),
func(*decls.FunctionDecl) (*decls.FunctionDecl, error) {
return fn, nil
}))
}
for _, typ := range stdlib.Types() {
typ := typ
opts = append(opts, cel.Variable(typ.Name(), typ.Type()))
}
opts = append(opts, cel.Macros(cel.StandardMacros...))
return opts
}
func (filterLibrary) ProgramOptions() []cel.ProgramOption {
return []cel.ProgramOption{}
} |
The ideal state would be to offer some options for subsetting on the Since the standard library is a fixed set of functions and types, how people approach subsetting can sometimes be inclusive or exclusive, e.g. only these functions / overloads, everything except these functions / overloads. Perhaps something like this: type StdLibSubsetConfig struct {
IncludeFunctions []string
ExcludeFunctions []string
IncludeOverloads []string
ExcludeOverloads[]string
IncludeMacros []string
ExcludeMacros []string
}
func StdLibSubset(config *StdLibSubsetConfig) StdLibOption {
...
} I'm tempted to package multiple configuration settings together rather than have separate options given how they can interact, but I'm open to suggestions. The alternative might look like this: func StdLibIncludeFunctions(names ...string) StdLibOption {
...
}
func StdLibExcludeFunctions(names ...string) StdLibOption {
...
} |
We only want to use a subset of CEL.
The text was updated successfully, but these errors were encountered: