-
Notifications
You must be signed in to change notification settings - Fork 769
/
Copy pathrule_condition.go
84 lines (67 loc) · 1.72 KB
/
rule_condition.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package privacy
// noClausesDefinedResult represents the default return when there is no matching criteria specified.
const noClausesDefinedResult = true
type ConditionRule struct {
result ActivityResult
componentName []string
componentType []string
gppSID []int8
}
func (r ConditionRule) Evaluate(target Component, request ActivityRequest) ActivityResult {
if matched := evaluateComponentName(target, r.componentName); !matched {
return ActivityAbstain
}
if matched := evaluateComponentType(target, r.componentType); !matched {
return ActivityAbstain
}
if matched := evaluateGPPSID(r.gppSID, request); !matched {
return ActivityAbstain
}
return r.result
}
func evaluateComponentName(target Component, componentNames []string) bool {
// no clauses are considered a match
if len(componentNames) == 0 {
return noClausesDefinedResult
}
for _, n := range componentNames {
if target.MatchesName(n) {
return true
}
}
return false
}
func evaluateComponentType(target Component, componentTypes []string) bool {
if len(componentTypes) == 0 {
return noClausesDefinedResult
}
// if there are clauses, at least one needs to match
for _, t := range componentTypes {
if target.MatchesType(t) {
return true
}
}
return false
}
func evaluateGPPSID(sid []int8, request ActivityRequest) bool {
if len(sid) == 0 {
return noClausesDefinedResult
}
for _, x := range getGPPSID(request) {
for _, y := range sid {
if x == y {
return true
}
}
}
return false
}
func getGPPSID(request ActivityRequest) []int8 {
if request.IsPolicies() {
return request.policies.GPPSID
}
if request.IsBidRequest() && request.bidRequest.Regs != nil {
return request.bidRequest.Regs.GPPSID
}
return nil
}