Skip to content

Commit

Permalink
Implement EID Permissions (prebid#1633)
Browse files Browse the repository at this point in the history
* Implement EID Permissions
  • Loading branch information
SyntaxNode authored and shunj-nb committed Nov 8, 2022
1 parent eb0153e commit d7fae56
Show file tree
Hide file tree
Showing 9 changed files with 1,053 additions and 37 deletions.
49 changes: 49 additions & 0 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ func (deps *endpointDeps) validateRequest(req *openrtb.BidRequest) []error {
if err := validateSChains(bidExt); err != nil {
return []error{err}
}

if err := deps.validateEidPermissions(bidExt, aliases); err != nil {
return []error{err}
}
}

if (req.Site == nil && req.App == nil) || (req.Site != nil && req.App != nil) {
Expand Down Expand Up @@ -444,6 +448,51 @@ func validateSChains(req *openrtb_ext.ExtRequest) error {
return err
}

func (deps *endpointDeps) validateEidPermissions(req *openrtb_ext.ExtRequest, aliases map[string]string) error {
if req == nil || req.Prebid.Data == nil {
return nil
}

uniqueSources := make(map[string]struct{}, len(req.Prebid.Data.EidPermissions))
for i, eid := range req.Prebid.Data.EidPermissions {
if len(eid.Source) == 0 {
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] missing required field: "source"`, i)
}

if _, exists := uniqueSources[eid.Source]; exists {
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] duplicate entry with field: "source"`, i)
}
uniqueSources[eid.Source] = struct{}{}

if len(eid.Bidders) == 0 {
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] missing or empty required field: "bidders"`, i)
}

if err := validateBidders(eid.Bidders, deps.bidderMap, aliases); err != nil {
return fmt.Errorf(`request.ext.prebid.data.eidpermissions[%d] contains %v`, i, err)
}
}

return nil
}

func validateBidders(bidders []string, knownBidders map[string]openrtb_ext.BidderName, knownAliases map[string]string) error {
for _, bidder := range bidders {
if bidder == "*" {
if len(bidders) > 1 {
return errors.New(`bidder wildcard "*" mixed with specific bidders`)
}
} else {
_, isCoreBidder := knownBidders[bidder]
_, isAlias := knownAliases[bidder]
if !isCoreBidder && !isAlias {
return fmt.Errorf(`unrecognized bidder "%v"`, bidder)
}
}
}
return nil
}

func (deps *endpointDeps) validateImp(imp *openrtb.Imp, aliases map[string]string, index int) []error {
if imp.ID == "" {
return []error{fmt.Errorf("request.imp[%d] missing required field: \"id\"", index)}
Expand Down
Loading

0 comments on commit d7fae56

Please sign in to comment.