rego4k debugger
Query
decision := data.changes.window.decision
Write a policy, an input and a query. Then click Debug.
# The change windows of a deployment pipeline. The policy reads the time of the query with `time.now_ns`, and # the time zone data with `time.clock` and `time.weekday`. These builtins are provided: the result of the query # depends on them, so a signed decision records their values. package changes.window now := time.now_ns() # The day and the time in the zone of the change window, for example "Thursday" and [14, 5, 0]. weekday := time.weekday([now, data.changes.zone]) clock := time.clock([now, data.changes.zone]) default allow := false # A standard change needs the change window and no freeze. allow if { input.change.kind == "standard" in_window count(freezes) == 0 } # An emergency change can go at any time, if somebody approved it. allow if { input.change.kind == "emergency" input.change.approved_by != "" } in_window if { weekday in data.changes.window.days data.changes.window.from_hour <= clock[0] clock[0] < data.changes.window.to_hour } # The freezes now. freezes contains freeze.reason if { some freeze in data.changes.freezes time.parse_rfc3339_ns(freeze.from) <= now now < time.parse_rfc3339_ns(freeze.to) } reasons contains "outside the change window" if not in_window reasons contains reason if some reason in freezes decision := { "allow": allow, "local_time": sprintf("%s %02d:%02d %s", [weekday, clock[0], clock[1], data.changes.zone]), "reasons": reasons, }
Input (JSON)
{ "change": { "approved_by": "carol", "kind": "emergency", "service": "checkout" } }