Skip to content

Commit

Permalink
Merge branch 'master' of github.com:prebid/prebid-server
Browse files Browse the repository at this point in the history
  • Loading branch information
banakemi committed Dec 12, 2021
2 parents c4f1358 + 5bb455c commit 3dd722d
Show file tree
Hide file tree
Showing 331 changed files with 17,278 additions and 13,450 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"containerEnv": {
"GOPRIVATE": "${localEnv:GOPRIVATE}",
"PBS_GDPR_DEFAULT_VALUE": "0"
},
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

Expand Down
51 changes: 32 additions & 19 deletions adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type bidTtxExt struct {
func (a *TtxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var adapterRequests []*adapters.RequestData
var groupedImps = make(map[string][]openrtb2.Imp)

// Construct request extension common to all imps
// NOTE: not blocking adapter requests on errors
Expand All @@ -64,27 +65,39 @@ func (a *TtxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapter
}
request.Ext = reqExt

// Break up multi-imp request into multiple external requests since we don't
// support SRA in our exchange server
// We only support SRA for requests containing same prod and
// zoneID, therefore group all imps accordingly and create a http
// request for each such group
for i := 0; i < len(request.Imp); i++ {
if adapterReq, err := a.makeRequest(*request, request.Imp[i]); err == nil {
adapterRequests = append(adapterRequests, adapterReq)
if impCopy, err := makeImps(request.Imp[i]); err == nil {
var impExt Ext

// Skip over imps whose extensions cannot be read since
// we cannot glean Prod or ZoneID which are required to
// group together. However let's not block request creation.
if err := json.Unmarshal(impCopy.Ext, &impExt); err == nil {
impKey := impExt.Ttx.Prod + impExt.Ttx.Zoneid
groupedImps[impKey] = append(groupedImps[impKey], impCopy)
} else {
errs = append(errs, err)
}
} else {
errs = append(errs, err)
}
}

for _, impList := range groupedImps {
if adapterReq, err := a.makeRequest(*request, impList); err == nil {
adapterRequests = append(adapterRequests, adapterReq)
} else {
errs = append(errs, err)
}
}
return adapterRequests, errs
}

func (a *TtxAdapter) makeRequest(request openrtb2.BidRequest, imp openrtb2.Imp) (*adapters.RequestData, error) {
impCopy, err := makeImps(imp)

if err != nil {
return nil, err
}

request.Imp = []openrtb2.Imp{*impCopy}
func (a *TtxAdapter) makeRequest(request openrtb2.BidRequest, impList []openrtb2.Imp) (*adapters.RequestData, error) {
request.Imp = impList

// Last Step
reqJSON, err := json.Marshal(request)
Expand All @@ -103,23 +116,23 @@ func (a *TtxAdapter) makeRequest(request openrtb2.BidRequest, imp openrtb2.Imp)
}, nil
}

func makeImps(imp openrtb2.Imp) (*openrtb2.Imp, error) {
func makeImps(imp openrtb2.Imp) (openrtb2.Imp, error) {
if imp.Banner == nil && imp.Video == nil {
return nil, &errortypes.BadInput{
return openrtb2.Imp{}, &errortypes.BadInput{
Message: fmt.Sprintf("Imp ID %s must have at least one of [Banner, Video] defined", imp.ID),
}
}

var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
}

var ttxExt openrtb_ext.ExtImp33across
if err := json.Unmarshal(bidderExt.Bidder, &ttxExt); err != nil {
return nil, &errortypes.BadInput{
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
}
Expand All @@ -135,7 +148,7 @@ func makeImps(imp openrtb2.Imp) (*openrtb2.Imp, error) {

impExtJSON, err := json.Marshal(impExt)
if err != nil {
return nil, &errortypes.BadInput{
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
}
Expand All @@ -149,13 +162,13 @@ func makeImps(imp openrtb2.Imp) (*openrtb2.Imp, error) {
imp.Video = videoCopy

if err != nil {
return nil, &errortypes.BadInput{
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
}
}

return &imp, nil
return imp, nil
}

func makeReqExt(request *openrtb2.BidRequest) ([]byte, error) {
Expand Down
172 changes: 163 additions & 9 deletions adapters/33across/33acrosstest/exemplary/multi-imp-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@
"productId": "inview"
}
}
},
{
"id": "test-imp-id3",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"ext": {
"bidder": {
"siteId": "fake-site-id1",
"productId": "inview"
}
}
},
{
"id": "test-imp-id4",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"ext": {
"bidder": {
"siteId": "fake-site-id",
"productId": "siab"
}
}
}
],
"site": {}
Expand Down Expand Up @@ -58,6 +82,18 @@
"zoneid": "fake-site-id"
}
}
},
{
"id":"test-imp-id2",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"ext": {
"ttx": {
"prod": "inview",
"zoneid": "fake-site-id"
}
}
}
],
"site": {}
Expand All @@ -70,7 +106,8 @@
"seatbid": [
{
"seat": "ttx",
"bid": [{
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id1",
"price": 0.500000,
Expand All @@ -83,7 +120,22 @@
"mediaType": "banner"
}
}
}]
},
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id2",
"price": 0.600000,
"adm": "some-test-ad",
"crid": "crid_10",
"h": 90,
"w": 728,
"ext": {
"ttx": {
"mediaType": "banner"
}
}
}
]
}
],
"cur": "USD"
Expand All @@ -107,13 +159,74 @@
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id2",
"id":"test-imp-id3",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"ext": {
"ttx": {
"prod": "inview",
"zoneid": "fake-site-id1"
}
}
}
],
"site": {}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "ttx",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id3",
"price": 0.500000,
"adm": "some-test-ad",
"crid": "crid_10",
"h": 90,
"w": 728,
"ext": {
"ttx": {
"mediaType": "banner"
}
}
}
]
}
],
"cur": "USD"
}
}
},
{
"expectedRequest": {
"uri": "http://ssc.33across.com",
"body": {
"ext": {
"ttx": {
"caller": [
{
"name": "Prebid-Server",
"version": "n/a"
}
]
}
},
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id4",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"ext": {
"ttx": {
"prod": "siab",
"zoneid": "fake-site-id"
}
}
Expand All @@ -129,10 +242,11 @@
"seatbid": [
{
"seat": "ttx",
"bid": [{
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id2",
"price": 0.600000,
"impid": "test-imp-id4",
"price": 0.500000,
"adm": "some-test-ad",
"crid": "crid_10",
"h": 90,
Expand All @@ -142,7 +256,8 @@
"mediaType": "banner"
}
}
}]
}
]
}
],
"cur": "USD"
Expand Down Expand Up @@ -171,6 +286,23 @@
}
},
"type": "banner"
},
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id2",
"price": 0.6,
"adm": "some-test-ad",
"crid": "crid_10",
"w": 728,
"h": 90,
"ext": {
"ttx": {
"mediaType": "banner"
}
}
},
"type": "banner"
}
]
},
Expand All @@ -180,8 +312,30 @@
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id2",
"price": 0.6,
"impid": "test-imp-id3",
"price": 0.5,
"adm": "some-test-ad",
"crid": "crid_10",
"w": 728,
"h": 90,
"ext": {
"ttx": {
"mediaType": "banner"
}
}
},
"type": "banner"
}
]
},
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id4",
"price": 0.5,
"adm": "some-test-ad",
"crid": "crid_10",
"w": 728,
Expand Down
Loading

0 comments on commit 3dd722d

Please sign in to comment.