I am new to rego code and writing a rule to check for employee names if they present in the approved employee list. If not, it should print out the employees who are not part of the list. Here is the input I am giving:
{ "valid_employee_names": { "first_name.2113690404": "emp_Maria", "first_name.2641279496": "emp_Rosie", "first_name.3921413181": "emp_Shaun", "first_name.588579514": "emp_John" }, "destroy": false }
Here is the rego rule:
valid_name := {i: Reason |
check_list := {["emp_John","emp_Monika","emp_Cindy","emp_Katie","emp_Kein"]}
doc = input[i]; i="valid_employee_names"
key_ids := [k | doc[k]; startswith(k, "first_name.")]
resource := {
doc[k] : doc[replace(k, ".key", ".value")] | key_ids[_] == k
}
emp_name := [m | resource[m]; startswith(m, "emp_")]
list := {x| x:=check_list[_]}
not(list[emp_name])
Reason := sprintf("Employees not on record found - %v . :: ", emp_name)
}
I always get the same output that employees not on record are found. Can anyone point me to see what needs to be corrected/updated?
Thanks!