///|
fn main raise {
let resource_type = @cel.CelType::Map(
@cel.CelType::String,
@cel.CelType::List(@cel.CelType::String),
)
let env = @cel.TypeEnv::new()
.with_variable("role", @cel.CelType::String)
.with_variable("amount", @cel.CelType::Int)
.with_variable("limit", @cel.CelType::Int)
.with_variable("resource", resource_type)
let policy = "role == 'admin' || (amount <= limit && 'public' in resource.tags)"
let program = @cel.compile(policy, env)
let activation = @cel.Activation::new()
.bind("role", @cel.Value::String("reviewer"))
.bind("amount", @cel.Value::Int(75L))
.bind("limit", @cel.Value::Int(100L))
.bind(
"resource",
@cel.Value::Map([
{
key: @cel.Value::String("tags"),
value: @cel.Value::List([
@cel.Value::String("public"),
@cel.Value::String("verified"),
]),
},
]),
)
println("policy: \{policy}")
println("decision: \{program.eval(activation).display()}")
}