File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
governance/second-generation/cloud-agnostic
test/check-external-http-api Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ # This policy uses the Sentinel HTTP import to call an external API,
2
+ # https://yesno.wtf/api that randomly returns "yes" or "no"
3
+ # This simulates what a policy might do to check an external system
4
+ # that has a JSON-based API in order to confirm that the run is
5
+ # allowed to do an apply.
6
+
7
+ # For example, some customers require tickets to be opened and approved
8
+ # before an apply can be done. The HTTP import could be used to check
9
+ # those types of systems.
10
+
11
+ # It also uses the Sentinel case statement
12
+
13
+ # Note that the single associated test.json test case will pass sometimes and
14
+ # fail the other times depending on the value returned by the API. To see the
15
+ # answer that was returned, run `sentinel test -run=check -verbose`
16
+
17
+
18
+ ##### Imports #####
19
+ import "http"
20
+ import "json"
21
+
22
+ ##### Functions #####
23
+
24
+ # Validate that the proposed monthly cost is less than the limit
25
+ check_external_approval_system = func() {
26
+ req = http.request("https://yesno.wtf/api")
27
+ res = json.unmarshal(http.get(req).body)
28
+ answer = res.answer
29
+ print("answer:", answer)
30
+
31
+ case answer {
32
+ # https://yesno.wtf/api returns "maybe" every 10,000th time
33
+ when "yes", "maybe":
34
+ return true
35
+ when "no":
36
+ return false
37
+ else:
38
+ return false
39
+ }
40
+
41
+ }
42
+
43
+ ##### Rules #####
44
+ approved = check_external_approval_system()
45
+ main = rule {
46
+ approved
47
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "test" : {
3
+ "main" : true
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments