Tree shaking
Tree shaking for changes/window/decision keeps 69 lines, deletes 0 and adds 0. It keeps 2 files and removes 0.
window.rego: 49 lines kept, 0 deleted, 0 added
1# The change windows of a deployment pipeline. The policy reads the time of the query with `time.now_ns`, and
2# the time zone data with `time.clock` and `time.weekday`. These builtins are provided: the result of the query
3# depends on them, so a signed decision records their values.
4package changes.window
5
6now := time.now_ns()
7
8# The day and the time in the zone of the change window, for example "Thursday" and [14, 5, 0].
9weekday := time.weekday([now, data.changes.zone])
10
11clock := time.clock([now, data.changes.zone])
12
13default allow := false
14
15# A standard change needs the change window and no freeze.
16allow if {
17 input.change.kind == "standard"
18 in_window
19 count(freezes) == 0
20}
21
22# An emergency change can go at any time, if somebody approved it.
23allow if {
24 input.change.kind == "emergency"
25 input.change.approved_by != ""
26}
27
28in_window if {
29 weekday in data.changes.window.days
30 data.changes.window.from_hour <= clock[0]
31 clock[0] < data.changes.window.to_hour
32}
33
34# The freezes now.
35freezes contains freeze.reason if {
36 some freeze in data.changes.freezes
37 time.parse_rfc3339_ns(freeze.from) <= now
38 now < time.parse_rfc3339_ns(freeze.to)
39}
40
41reasons contains "outside the change window" if not in_window
42
43reasons contains reason if some reason in freezes
44
45decision := {
46 "allow": allow,
47 "local_time": sprintf("%s %02d:%02d %s", [weekday, clock[0], clock[1], data.changes.zone]),
48 "reasons": reasons,
49}
Counts
| Lines kept | 69 |
| Lines deleted | 0 |
| Lines added | 0 |
| Files kept | 2 |
| Files removed | 0 |
Builtins (11)
- count
- equal
- internal.member_2
- lt
- lte
- neq
- sprintf
- time.clock
- time.now_ns
- time.parse_rfc3339_ns
- time.weekday
Legend
1A kept line: the shaken bundle has it.
2A deleted line: the shaken bundle does not have it.
+An added line: only the shaken bundle has it.
- policy.rego a removed file