Search code examples
open-policy-agent

How to check if value is defined in rego?


I want to check if a variable is defined in OPA policy.

> subject
1 error occurred: 1:1: rego_unsafe_var_error: var subject is unsafe

Is there a function to check if a variable is defined


Solution

  • You can use show command to show active module definition.

    
    > show
    package repl
    
    b = 45534543
    
    a = 3423
    
    sites = [
        {"name": "prod"},
        {"name": "smoke1"},
        {"name": "dev"},
    ]
    
    

    You will find the list of defined variables here.