-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ORTB 2.4 schain support #2108
Merged
+764
−258
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
330ea15
Add ORTB 2.4 schain support
bsardo 47b2aa2
go fmt
bsardo efccf8b
Refactor schain writer tests and increase test coverage
bsardo 97cecff
Update exchange utils schain test
bsardo d778631
Remove test covering logic in writer
bsardo e70939d
Map ORTB 2.4 schain to ORTB 2.5 location upstream in validation step
bsardo f3040ba
Add request wrapper test coverage to push package coverage over 30%
bsardo b09cf34
Add wrapper schain method comment and minor test improvement
bsardo 14b3346
Remove warnings added when debugging
bsardo bb83cc6
Remove glog import
bsardo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"github.com/prebid/prebid-server/privacy" | ||
"github.com/prebid/prebid-server/privacy/ccpa" | ||
"github.com/prebid/prebid-server/privacy/lmt" | ||
"github.com/prebid/prebid-server/schain" | ||
) | ||
|
||
var integrationTypeMap = map[metrics.RequestType]config.IntegrationType{ | ||
|
@@ -31,23 +32,6 @@ var integrationTypeMap = map[metrics.RequestType]config.IntegrationType{ | |
|
||
const unknownBidder string = "" | ||
|
||
func BidderToPrebidSChains(sChains []*openrtb_ext.ExtRequestPrebidSChain) (map[string]*openrtb_ext.ExtRequestPrebidSChainSChain, error) { | ||
bidderToSChains := make(map[string]*openrtb_ext.ExtRequestPrebidSChainSChain) | ||
|
||
for _, schainWrapper := range sChains { | ||
for _, bidder := range schainWrapper.Bidders { | ||
if _, present := bidderToSChains[bidder]; present { | ||
return nil, fmt.Errorf("request.ext.prebid.schains contains multiple schains for bidder %s; "+ | ||
"it must contain no more than one per bidder.", bidder) | ||
} else { | ||
bidderToSChains[bidder] = &schainWrapper.SChain | ||
} | ||
} | ||
} | ||
|
||
return bidderToSChains, nil | ||
} | ||
|
||
// cleanOpenRTBRequests splits the input request into requests which are sanitized for each bidder. Intended behavior is: | ||
// | ||
// 1. BidRequest.Imp[].Ext will only contain the "prebid" field and a "bidder" field which has the params for the intended Bidder. | ||
|
@@ -210,6 +194,22 @@ func extractLMT(orig *openrtb2.BidRequest, privacyConfig config.Privacy) privacy | |
} | ||
} | ||
|
||
func unpackSourceExt(bidRequest *openrtb2.BidRequest) (*openrtb_ext.ExtSource, error) { | ||
var sourceExt *openrtb_ext.ExtSource | ||
|
||
if bidRequest.Source == nil || bidRequest.Source.Ext == nil { | ||
return nil, nil | ||
} | ||
|
||
if len(bidRequest.Source.Ext) > 0 { | ||
err := json.Unmarshal(bidRequest.Source.Ext, &sourceExt) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error decoding Request.source.ext: %s", err.Error()) | ||
} | ||
} | ||
return sourceExt, nil | ||
} | ||
|
||
func getAuctionBidderRequests(req AuctionRequest, | ||
requestExt *openrtb_ext.ExtRequest, | ||
bidderToSyncerKey map[string]string, | ||
|
@@ -228,14 +228,14 @@ func getAuctionBidderRequests(req AuctionRequest, | |
return nil, []error{err} | ||
} | ||
|
||
var sChainsByBidder map[string]*openrtb_ext.ExtRequestPrebidSChainSChain | ||
requestSourceExt, err := unpackSourceExt(req.BidRequest) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
// Quick extra wrapper until RequestWrapper makes its way into CleanRequests | ||
if requestExt != nil { | ||
sChainsByBidder, err = BidderToPrebidSChains(requestExt.Prebid.SChains) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
sChainWriter, err := schain.NewSChainWriter(requestExt, requestSourceExt) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
var errs []error | ||
|
@@ -245,7 +245,7 @@ func getAuctionBidderRequests(req AuctionRequest, | |
reqCopy := *req.BidRequest | ||
reqCopy.Imp = imps | ||
|
||
prepareSource(&reqCopy, bidder, sChainsByBidder) | ||
sChainWriter.Write(&reqCopy, bidder) | ||
|
||
if len(bidderParamsInReqExt) != 0 { | ||
|
||
|
@@ -315,43 +315,10 @@ func getExtJson(req *openrtb2.BidRequest, unpackedExt *openrtb_ext.ExtRequest) ( | |
|
||
extCopy := *unpackedExt | ||
extCopy.Prebid.SChains = nil | ||
extCopy.SChain = nil | ||
return json.Marshal(extCopy) | ||
} | ||
|
||
func prepareSource(req *openrtb2.BidRequest, bidder string, sChainsByBidder map[string]*openrtb_ext.ExtRequestPrebidSChainSChain) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic has been moved to the schain writer implementation |
||
const sChainWildCard = "*" | ||
var selectedSChain *openrtb_ext.ExtRequestPrebidSChainSChain | ||
|
||
wildCardSChain := sChainsByBidder[sChainWildCard] | ||
bidderSChain := sChainsByBidder[bidder] | ||
|
||
// source should not be modified | ||
if bidderSChain == nil && wildCardSChain == nil { | ||
return | ||
} | ||
|
||
if bidderSChain != nil { | ||
selectedSChain = bidderSChain | ||
} else { | ||
selectedSChain = wildCardSChain | ||
} | ||
|
||
// set source | ||
if req.Source == nil { | ||
req.Source = &openrtb2.Source{} | ||
} else { | ||
sourceCopy := *req.Source | ||
req.Source = &sourceCopy | ||
} | ||
schain := openrtb_ext.ExtRequestPrebidSChain{ | ||
SChain: *selectedSChain, | ||
} | ||
sourceExt, err := json.Marshal(schain) | ||
if err == nil { | ||
req.Source.Ext = sourceExt | ||
} | ||
} | ||
|
||
// extractBuyerUIDs parses the values from user.ext.prebid.buyeruids, and then deletes those values from the ext. | ||
// This prevents a Bidder from using these values to figure out who else is involved in the Auction. | ||
func extractBuyerUIDs(user *openrtb2.User) (map[string]string, error) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was copied to
schain/schain.go
.