mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-05-11 02:28:22 +00:00
23 lines
494 B
Go
23 lines
494 B
Go
package util
|
|
|
|
import "github.com/google/cel-go/cel"
|
|
|
|
// InitCELProgram - Initialize a CEL program with given CEL command and a set of environments
|
|
func InitCELProgram(celCmd string, options ...cel.EnvOption) (*cel.Program, error) {
|
|
env, err := cel.NewEnv(options...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ast, issue := env.Compile(celCmd)
|
|
if issue.Err() != nil {
|
|
return nil, issue.Err()
|
|
}
|
|
|
|
program, err := env.Program(ast)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &program, nil
|
|
}
|