Skip to content

Commit

Permalink
task 3678
Browse files Browse the repository at this point in the history
  • Loading branch information
przemkaczmarek committed Dec 20, 2024
1 parent f3b5bce commit 36dba89
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
10 changes: 10 additions & 0 deletions config/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Account struct {
DefaultBidLimit int `mapstructure:"default_bid_limit" json:"default_bid_limit"`
BidAdjustments *openrtb_ext.ExtRequestPrebidBidAdjustments `mapstructure:"bidadjustments" json:"bidadjustments"`
Privacy AccountPrivacy `mapstructure:"privacy" json:"privacy"`
EEACountries []string `mapstructure:"eea_countries" json:"eea_countries"`
}

// CookieSync represents the account-level defaults for the cookie sync endpoint.
Expand Down Expand Up @@ -381,3 +382,12 @@ func (ip *IPv4) Validate(errs []error) []error {
}
return errs
}

func (a *Account) ValidateEEACountries(errs []error) []error {
for _, country := range a.EEACountries {
if len(country) != 2 { // Check if country code is valid
errs = append(errs, fmt.Errorf("invalid EEA country code: %s", country))
}
}
return errs
}
15 changes: 12 additions & 3 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,17 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog

recordImpMetrics(r.BidRequestWrapper, e.me)

// Retrieve host and account-level EEA countries config
eeaCountries := SelectEEACountries(e.privacyConfig.GDPR.EEACountries, r.Account.EEACountries)

// Create a map for efficient lookup
eeaCountriesMap := make(map[string]struct{})
for _, country := range eeaCountries {
eeaCountriesMap[strings.ToUpper(country)] = struct{}{}
}

// Make our best guess if GDPR applies
gdprDefaultValue := e.parseGDPRDefaultValue(r.BidRequestWrapper)
gdprDefaultValue := e.parseGDPRDefaultValue(r.BidRequestWrapper, eeaCountriesMap)
gdprSignal, err := getGDPR(r.BidRequestWrapper)
if err != nil {
return nil, err
Expand Down Expand Up @@ -571,7 +580,7 @@ func buildMultiBidMap(prebid *openrtb_ext.ExtRequestPrebid) map[string]openrtb_e
return multiBidMap
}

func (e *exchange) parseGDPRDefaultValue(r *openrtb_ext.RequestWrapper) gdpr.Signal {
func (e *exchange) parseGDPRDefaultValue(r *openrtb_ext.RequestWrapper, eeaCountriesMap map[string]struct{}) gdpr.Signal {
gdprDefaultValue := e.gdprDefaultValue

var geo *openrtb2.Geo
Expand All @@ -584,7 +593,7 @@ func (e *exchange) parseGDPRDefaultValue(r *openrtb_ext.RequestWrapper) gdpr.Sig
if geo != nil {
// If we have a country set, and it is on the list, we assume GDPR applies if not set on the request.
// Otherwise we assume it does not apply as long as it appears "valid" (is 3 characters long).
if _, found := e.privacyConfig.GDPR.EEACountriesMap[strings.ToUpper(geo.Country)]; found {
if _, found := eeaCountriesMap[strings.ToUpper(geo.Country)]; found {
gdprDefaultValue = gdpr.SignalYes
} else if len(geo.Country) == 3 {
// The country field is formatted properly as a three character country code
Expand Down
12 changes: 12 additions & 0 deletions exchange/gdpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ func enforceGDPR(signal gdpr.Signal, defaultValue gdpr.Signal, channelEnabled bo
gdprApplies := signal == gdpr.SignalYes || (signal == gdpr.SignalAmbiguous && defaultValue == gdpr.SignalYes)
return gdprApplies && channelEnabled
}

// SelectEEACountries selects the EEA countries based on host and account configurations.
// Account-level configuration takes precedence over the host-level configuration.
func SelectEEACountries(hostEEACountries []string, accountEEACountries []string) []string {
// If account-level configuration is provided, it takes precedence.
if len(accountEEACountries) > 0 {
return accountEEACountries
}

// Otherwise, return the host-level configuration.
return hostEEACountries
}

0 comments on commit 36dba89

Please sign in to comment.