Skip to content

Commit

Permalink
Refactor: Move privacy init up (#3958)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo authored Oct 9, 2024
1 parent 64584f6 commit 87d4412
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
return
}

allBidderRequests := make([]BidderRequest, 0, len(impsByBidder))
var allBidderRequestErrs []error
explicitBuyerUIDs, err := extractBuyerUIDs(req.BidRequest.User)
if err != nil {
errs = []error{err}
return
}
lowerCaseExplicitBuyerUIDs := make(map[string]string)
for bidder, uid := range explicitBuyerUIDs {
lowerKey := strings.ToLower(bidder)
lowerCaseExplicitBuyerUIDs[lowerKey] = uid
}

bidderParamsInReqExt, err := ExtractReqExtBidderParamsMap(req.BidRequest)
if err != nil {
Expand All @@ -101,12 +104,58 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
return
}

lowerCaseExplicitBuyerUIDs := make(map[string]string)
for bidder, uid := range explicitBuyerUIDs {
lowerKey := strings.ToLower(bidder)
lowerCaseExplicitBuyerUIDs[lowerKey] = uid
var gpp gpplib.GppContainer
if req.BidRequest.Regs != nil && len(req.BidRequest.Regs.GPP) > 0 {
var gppErrs []error
gpp, gppErrs = gpplib.Parse(req.BidRequest.Regs.GPP)
if len(gppErrs) > 0 {
errs = append(errs, gppErrs[0])
}
}

consent, err := getConsent(req, gpp)
if err != nil {
errs = append(errs, err)
}

ccpaEnforcer, err := extractCCPA(req.BidRequest, rs.privacyConfig, &auctionReq.Account, requestAliases, channelTypeMap[auctionReq.LegacyLabels.RType], gpp)
if err != nil {
errs = append(errs, err)
}

lmtEnforcer := extractLMT(req.BidRequest, rs.privacyConfig)

// request level privacy policies
coppa := req.BidRequest.Regs != nil && req.BidRequest.Regs.COPPA == 1
lmt := lmtEnforcer.ShouldEnforce(unknownBidder)

privacyLabels.CCPAProvided = ccpaEnforcer.CanEnforce()
privacyLabels.CCPAEnforced = ccpaEnforcer.ShouldEnforce(unknownBidder)
privacyLabels.COPPAEnforced = coppa
privacyLabels.LMTEnforced = lmt

var gdprPerms gdpr.Permissions = &gdpr.AlwaysAllow{}

if gdprEnforced {
privacyLabels.GDPREnforced = true
parsedConsent, err := vendorconsent.ParseString(consent)
if err == nil {
version := int(parsedConsent.Version())
privacyLabels.GDPRTCFVersion = metrics.TCFVersionToValue(version)
}

gdprRequestInfo := gdpr.RequestInfo{
AliasGVLIDs: requestAliasesGVLIDs,
Consent: consent,
GDPRSignal: gdprSignal,
PublisherID: auctionReq.LegacyLabels.PubID,
}
gdprPerms = rs.gdprPermsBuilder(auctionReq.TCF2Config, gdprRequestInfo)
}

allBidderRequests := make([]BidderRequest, 0, len(impsByBidder))
var allBidderRequestErrs []error

for bidder, imps := range impsByBidder {
coreBidder, isRequestAlias := resolveBidder(bidder, requestAliases)

Expand Down Expand Up @@ -159,60 +208,11 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
//this function should be executed after getAuctionBidderRequests
allBidderRequests = mergeBidderRequests(allBidderRequests, bidderNameToBidderReq)

var gpp gpplib.GppContainer
if req.BidRequest.Regs != nil && len(req.BidRequest.Regs.GPP) > 0 {
var gppErrs []error
gpp, gppErrs = gpplib.Parse(req.BidRequest.Regs.GPP)
if len(gppErrs) > 0 {
errs = append(errs, gppErrs[0])
}
}

if auctionReq.Account.PriceFloors.IsAdjustForBidAdjustmentEnabled() {
//Apply BidAdjustmentFactor to imp.BidFloor
applyBidAdjustmentToFloor(allBidderRequests, bidAdjustmentFactors)
}

consent, err := getConsent(req, gpp)
if err != nil {
errs = append(errs, err)
}

ccpaEnforcer, err := extractCCPA(req.BidRequest, rs.privacyConfig, &auctionReq.Account, requestAliases, channelTypeMap[auctionReq.LegacyLabels.RType], gpp)
if err != nil {
errs = append(errs, err)
}

lmtEnforcer := extractLMT(req.BidRequest, rs.privacyConfig)

// request level privacy policies
coppa := req.BidRequest.Regs != nil && req.BidRequest.Regs.COPPA == 1
lmt := lmtEnforcer.ShouldEnforce(unknownBidder)

privacyLabels.CCPAProvided = ccpaEnforcer.CanEnforce()
privacyLabels.CCPAEnforced = ccpaEnforcer.ShouldEnforce(unknownBidder)
privacyLabels.COPPAEnforced = coppa
privacyLabels.LMTEnforced = lmt

var gdprPerms gdpr.Permissions = &gdpr.AlwaysAllow{}

if gdprEnforced {
privacyLabels.GDPREnforced = true
parsedConsent, err := vendorconsent.ParseString(consent)
if err == nil {
version := int(parsedConsent.Version())
privacyLabels.GDPRTCFVersion = metrics.TCFVersionToValue(version)
}

gdprRequestInfo := gdpr.RequestInfo{
AliasGVLIDs: requestAliasesGVLIDs,
Consent: consent,
GDPRSignal: gdprSignal,
PublisherID: auctionReq.LegacyLabels.PubID,
}
gdprPerms = rs.gdprPermsBuilder(auctionReq.TCF2Config, gdprRequestInfo)
}

allowedBidderRequests = make([]BidderRequest, 0, len(allBidderRequests))

for _, bidderRequest := range allBidderRequests {
Expand Down

0 comments on commit 87d4412

Please sign in to comment.