github.com/prebid/prebid-server/v2@v2.18.0/privacy/policyenforcer.go (about)

     1  package privacy
     2  
     3  // NOTE: Reanme this package. Will eventually replace in its entirety with Activites.
     4  
     5  // PolicyEnforcer determines if personally identifiable information (PII) should be removed or anonymized per the policy.
     6  type PolicyEnforcer interface {
     7  	// CanEnforce returns true when policy information is specifically provided by the publisher.
     8  	CanEnforce() bool
     9  
    10  	// ShouldEnforce returns true when the OpenRTB request should have personally identifiable
    11  	// information (PII) removed or anonymized per the policy.
    12  	ShouldEnforce(bidder string) bool
    13  }
    14  
    15  // NilPolicyEnforcer implements the PolicyEnforcer interface but will always return false.
    16  type NilPolicyEnforcer struct{}
    17  
    18  // CanEnforce is hardcoded to always return false.
    19  func (NilPolicyEnforcer) CanEnforce() bool {
    20  	return false
    21  }
    22  
    23  // ShouldEnforce is hardcoded to always return false.
    24  func (NilPolicyEnforcer) ShouldEnforce(bidder string) bool {
    25  	return false
    26  }
    27  
    28  // EnabledPolicyEnforcer decorates a PolicyEnforcer with an enabled flag.
    29  type EnabledPolicyEnforcer struct {
    30  	Enabled        bool
    31  	PolicyEnforcer PolicyEnforcer
    32  }
    33  
    34  // CanEnforce returns true when the PolicyEnforcer can enforce.
    35  func (p EnabledPolicyEnforcer) CanEnforce() bool {
    36  	return p.PolicyEnforcer.CanEnforce()
    37  }
    38  
    39  // ShouldEnforce returns true when the enforcer is enabled the PolicyEnforcer allows enforcement.
    40  func (p EnabledPolicyEnforcer) ShouldEnforce(bidder string) bool {
    41  	if p.Enabled {
    42  		return p.PolicyEnforcer.ShouldEnforce(bidder)
    43  	}
    44  	return false
    45  }