CompileOptions returns options for the standard CEL function declarations and macros.
()
| 169 | |
| 170 | // CompileOptions returns options for the standard CEL function declarations and macros. |
| 171 | func (lib *stdLibrary) CompileOptions() []EnvOption { |
| 172 | funcs := stdlib.Functions() |
| 173 | macros := StandardMacros |
| 174 | if lib.subset != nil { |
| 175 | subMacros := []Macro{} |
| 176 | for _, m := range macros { |
| 177 | if lib.subset.SubsetMacro(m.Function()) { |
| 178 | subMacros = append(subMacros, m) |
| 179 | } |
| 180 | } |
| 181 | macros = subMacros |
| 182 | subFuncs := []*decls.FunctionDecl{} |
| 183 | for _, fn := range funcs { |
| 184 | if f, include := lib.subset.SubsetFunction(fn); include { |
| 185 | subFuncs = append(subFuncs, f) |
| 186 | } |
| 187 | } |
| 188 | funcs = subFuncs |
| 189 | } |
| 190 | return []EnvOption{ |
| 191 | func(e *Env) (*Env, error) { |
| 192 | var err error |
| 193 | if err = lib.subset.Validate(); err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | if len(funcs) > 0 { |
| 197 | e.ensureMutableFunctions() |
| 198 | } |
| 199 | for _, fn := range funcs { |
| 200 | existing, found := e.functions[fn.Name()] |
| 201 | if found { |
| 202 | fn, err = existing.Merge(fn) |
| 203 | if err != nil { |
| 204 | return nil, err |
| 205 | } |
| 206 | } |
| 207 | e.functions[fn.Name()] = fn |
| 208 | } |
| 209 | return e, nil |
| 210 | }, |
| 211 | Macros(macros...), |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // ProgramOptions returns function implementations for the standard CEL functions. |
| 216 | func (*stdLibrary) ProgramOptions() []ProgramOption { |
nothing calls this directly
no test coverage detected