-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rule.go
43 lines (37 loc) · 1.19 KB
/
Rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package xacml
import ()
type Rule struct {
rule map[string]interface{}
}
func (rule Rule) Evaluate(request Request) Response {
ruleBody := rule.rule
response := Response{make(map[string]interface{})}
//Evaluate target
targetResponse := evaluateTargetBody(ruleBody["Target"], request)
if targetResponse == targetNoMatch {
//log.Println("Rule Target didn't match")
response.AddResult(ResponseNotApplicable, "Rule Target didn't match")
return response
}
if targetResponse == targetIndeterminate {
//log.Println("Error evaluating match")
response.AddResult(ResponseIndeterminate, "Error evaluating target")
return response
}
//Evaluate condition
conditionResponse := evaluateConditionBody(ruleBody["Condition"], request)
switch conditionResponse {
case ConditionTrue:
effect, _ := rule.rule["-Effect"].(string)
response.AddResult(effect, "")
return response
case ConditionFalse:
response.AddResult(ResponseNotApplicable, "Condition returned false")
return response
case ConditionIndeterminate:
response.AddResult(ResponseIndeterminate, "Error evaluating Condition")
return response
}
response.AddResult(ResponseIndeterminate, "No other case caught")
return response
}