forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenforcer.go
43 lines (35 loc) · 1.38 KB
/
enforcer.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 privacy
// PolicyEnforcer determines if personally identifiable information (PII) should be removed or anonymized per the policy.
type PolicyEnforcer interface {
// CanEnforce returns true when policy information is specifically provided by the publisher.
CanEnforce() bool
// ShouldEnforce returns true when the OpenRTB request should have personally identifiable
// information (PII) removed or anonymized per the policy.
ShouldEnforce(bidder string) bool
}
// NilPolicyEnforcer implements the PolicyEnforcer interface but will always return false.
type NilPolicyEnforcer struct{}
// CanEnforce is hardcoded to always return false.
func (NilPolicyEnforcer) CanEnforce() bool {
return false
}
// ShouldEnforce is hardcoded to always return false.
func (NilPolicyEnforcer) ShouldEnforce(bidder string) bool {
return false
}
// EnabledPolicyEnforcer decorates a PolicyEnforcer with an enabled flag.
type EnabledPolicyEnforcer struct {
Enabled bool
PolicyEnforcer PolicyEnforcer
}
// CanEnforce returns true when the PolicyEnforcer can enforce.
func (p EnabledPolicyEnforcer) CanEnforce() bool {
return p.PolicyEnforcer.CanEnforce()
}
// ShouldEnforce returns true when the enforcer is enabled the PolicyEnforcer allows enforcement.
func (p EnabledPolicyEnforcer) ShouldEnforce(bidder string) bool {
if p.Enabled {
return p.PolicyEnforcer.ShouldEnforce(bidder)
}
return false
}