forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bidders.go
executable file
·278 lines (258 loc) · 10.6 KB
/
bidders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package openrtb_ext
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"github.com/xeipuuv/gojsonschema"
)
const schemaDirectory = "static/bidder-params"
// BidderName may refer to a bidder ID, or an Alias which is defined in the request.
type BidderName string
// BidderNameGeneral is reserved for non-bidder specific messages when using a map keyed on the bidder name.
const BidderNameGeneral = BidderName("general")
// These names _must_ coincide with the bidder code in Prebid.js, if an adapter also exists in that project.
// Please keep these (and the BidderMap) alphabetized to minimize merge conflicts among adapter submissions.
// The bidder name 'general' is not allowed since it has special meaning in message maps.
const (
Bidder33Across BidderName = "33across"
BidderAdform BidderName = "adform"
BidderAdgeneration BidderName = "adgeneration"
BidderAdhese BidderName = "adhese"
BidderAdkernel BidderName = "adkernel"
BidderAdkernelAdn BidderName = "adkernelAdn"
BidderAdpone BidderName = "adpone"
BidderAdman BidderName = "adman"
BidderAdmixer BidderName = "admixer"
BidderAdOcean BidderName = "adocean"
BidderAdtarget BidderName = "adtarget"
BidderAdtelligent BidderName = "adtelligent"
BidderAdvangelists BidderName = "advangelists"
BidderAJA BidderName = "aja"
BidderApplogy BidderName = "applogy"
BidderAppnexus BidderName = "appnexus"
BidderAdoppler BidderName = "adoppler"
BidderAvocet BidderName = "avocet"
BidderBeachfront BidderName = "beachfront"
BidderBeintoo BidderName = "beintoo"
BidderBrightroll BidderName = "brightroll"
BidderConsumable BidderName = "consumable"
BidderConversant BidderName = "conversant"
BidderCpmstar BidderName = "cpmstar"
BidderDatablocks BidderName = "datablocks"
BidderDmx BidderName = "dmx"
BidderEmxDigital BidderName = "emx_digital"
BidderEngageBDR BidderName = "engagebdr"
BidderEPlanning BidderName = "eplanning"
BidderFacebook BidderName = "audienceNetwork"
BidderGamma BidderName = "gamma"
BidderGamoshi BidderName = "gamoshi"
BidderGrid BidderName = "grid"
BidderGumGum BidderName = "gumgum"
BidderImprovedigital BidderName = "improvedigital"
BidderIx BidderName = "ix"
BidderKidoz BidderName = "kidoz"
BidderKubient BidderName = "kubient"
BidderLifestreet BidderName = "lifestreet"
BidderLockerDome BidderName = "lockerdome"
BidderLunaMedia BidderName = "lunamedia"
BidderMarsmedia BidderName = "marsmedia"
BidderMgid BidderName = "mgid"
BidderMobileFuse BidderName = "mobilefuse"
BidderNanoInteractive BidderName = "nanointeractive"
BidderNinthDecimal BidderName = "ninthdecimal"
BidderOpenx BidderName = "openx"
BidderOrbidder BidderName = "orbidder"
BidderPubmatic BidderName = "pubmatic"
BidderPubnative BidderName = "pubnative"
BidderPulsepoint BidderName = "pulsepoint"
BidderRhythmone BidderName = "rhythmone"
BidderRTBHouse BidderName = "rtbhouse"
BidderRubicon BidderName = "rubicon"
BidderSharethrough BidderName = "sharethrough"
BidderSmartadserver BidderName = "smartadserver"
BidderSmartRTB BidderName = "smartrtb"
BidderSomoaudience BidderName = "somoaudience"
BidderSonobi BidderName = "sonobi"
BidderSovrn BidderName = "sovrn"
BidderSynacormedia BidderName = "synacormedia"
BidderTappx BidderName = "tappx"
BidderTelaria BidderName = "telaria"
BidderTriplelift BidderName = "triplelift"
BidderTripleliftNative BidderName = "triplelift_native"
BidderUcfunnel BidderName = "ucfunnel"
BidderUnruly BidderName = "unruly"
BidderValueImpression BidderName = "valueimpression"
BidderVerizonMedia BidderName = "verizonmedia"
BidderVisx BidderName = "visx"
BidderVrtcal BidderName = "vrtcal"
BidderYeahmobi BidderName = "yeahmobi"
BidderYieldlab BidderName = "yieldlab"
BidderYieldmo BidderName = "yieldmo"
BidderYieldone BidderName = "yieldone"
BidderZeroClickFraud BidderName = "zeroclickfraud"
)
// BidderMap stores all the valid OpenRTB 2.x Bidders in the project. This map *must not* be mutated.
// The bidder name 'general' is not allowed since it has special meaning in message maps.
var BidderMap = map[string]BidderName{
"33across": Bidder33Across,
"adform": BidderAdform,
"adgeneration": BidderAdgeneration,
"adhese": BidderAdhese,
"adkernel": BidderAdkernel,
"adkernelAdn": BidderAdkernelAdn,
"adman": BidderAdman,
"admixer": BidderAdmixer,
"adocean": BidderAdOcean,
"adpone": BidderAdpone,
"adtarget": BidderAdtarget,
"adtelligent": BidderAdtelligent,
"advangelists": BidderAdvangelists,
"aja": BidderAJA,
"applogy": BidderApplogy,
"appnexus": BidderAppnexus,
"adoppler": BidderAdoppler,
"avocet": BidderAvocet,
"beachfront": BidderBeachfront,
"beintoo": BidderBeintoo,
"brightroll": BidderBrightroll,
"consumable": BidderConsumable,
"conversant": BidderConversant,
"cpmstar": BidderCpmstar,
"datablocks": BidderDatablocks,
"dmx": BidderDmx,
"emx_digital": BidderEmxDigital,
"engagebdr": BidderEngageBDR,
"eplanning": BidderEPlanning,
"audienceNetwork": BidderFacebook,
"gamma": BidderGamma,
"gamoshi": BidderGamoshi,
"grid": BidderGrid,
"gumgum": BidderGumGum,
"improvedigital": BidderImprovedigital,
"ix": BidderIx,
"kidoz": BidderKidoz,
"kubient": BidderKubient,
"lifestreet": BidderLifestreet,
"lockerdome": BidderLockerDome,
"lunamedia": BidderLunaMedia,
"marsmedia": BidderMarsmedia,
"mgid": BidderMgid,
"mobilefuse": BidderMobileFuse,
"nanointeractive": BidderNanoInteractive,
"ninthdecimal": BidderNinthDecimal,
"openx": BidderOpenx,
"orbidder": BidderOrbidder,
"pubmatic": BidderPubmatic,
"pubnative": BidderPubnative,
"pulsepoint": BidderPulsepoint,
"rhythmone": BidderRhythmone,
"rtbhouse": BidderRTBHouse,
"rubicon": BidderRubicon,
"sharethrough": BidderSharethrough,
"smartadserver": BidderSmartadserver,
"smartrtb": BidderSmartRTB,
"somoaudience": BidderSomoaudience,
"sonobi": BidderSonobi,
"sovrn": BidderSovrn,
"synacormedia": BidderSynacormedia,
"tappx": BidderTappx,
"telaria": BidderTelaria,
"triplelift": BidderTriplelift,
"triplelift_native": BidderTripleliftNative,
"ucfunnel": BidderUcfunnel,
"unruly": BidderUnruly,
"valueimpression": BidderValueImpression,
"verizonmedia": BidderVerizonMedia,
"visx": BidderVisx,
"vrtcal": BidderVrtcal,
"yeahmobi": BidderYeahmobi,
"yieldlab": BidderYieldlab,
"yieldmo": BidderYieldmo,
"yieldone": BidderYieldone,
"zeroclickfraud": BidderZeroClickFraud,
}
// BidderList returns the values of the BidderMap
func BidderList() []BidderName {
bidders := make([]BidderName, 0, len(BidderMap))
for _, value := range BidderMap {
bidders = append(bidders, value)
}
return bidders
}
func (name BidderName) MarshalJSON() ([]byte, error) {
return []byte(name), nil
}
func (name *BidderName) String() string {
if name == nil {
return ""
}
return string(*name)
}
// The BidderParamValidator is used to enforce bidrequest.imp[i].ext.{anyBidder} values.
//
// This is treated differently from the other types because we rely on JSON-schemas to validate bidder params.
type BidderParamValidator interface {
Validate(name BidderName, ext json.RawMessage) error
// Schema returns the JSON schema used to perform validation.
Schema(name BidderName) string
}
// NewBidderParamsValidator makes a BidderParamValidator, assuming all the necessary files exist in the filesystem.
// This will error if, for example, a Bidder gets added but no JSON schema is written for them.
func NewBidderParamsValidator(schemaDirectory string) (BidderParamValidator, error) {
fileInfos, err := ioutil.ReadDir(schemaDirectory)
if err != nil {
return nil, fmt.Errorf("Failed to read JSON schemas from directory %s. %v", schemaDirectory, err)
}
schemaContents := make(map[BidderName]string, 50)
schemas := make(map[BidderName]*gojsonschema.Schema, 50)
for _, fileInfo := range fileInfos {
bidderName := strings.TrimSuffix(fileInfo.Name(), ".json")
if _, isValid := BidderMap[bidderName]; !isValid {
return nil, fmt.Errorf("File %s/%s does not match a valid BidderName.", schemaDirectory, fileInfo.Name())
}
toOpen, err := filepath.Abs(filepath.Join(schemaDirectory, fileInfo.Name()))
if err != nil {
return nil, fmt.Errorf("Failed to get an absolute representation of the path: %s, %v", toOpen, err)
}
schemaLoader := gojsonschema.NewReferenceLoader("file:///" + filepath.ToSlash(toOpen))
loadedSchema, err := gojsonschema.NewSchema(schemaLoader)
if err != nil {
return nil, fmt.Errorf("Failed to load json schema at %s: %v", toOpen, err)
}
fileBytes, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", schemaDirectory, fileInfo.Name()))
if err != nil {
return nil, fmt.Errorf("Failed to read file %s/%s: %v", schemaDirectory, fileInfo.Name(), err)
}
schemas[BidderName(bidderName)] = loadedSchema
schemaContents[BidderName(bidderName)] = string(fileBytes)
}
return &bidderParamValidator{
schemaContents: schemaContents,
parsedSchemas: schemas,
}, nil
}
type bidderParamValidator struct {
schemaContents map[BidderName]string
parsedSchemas map[BidderName]*gojsonschema.Schema
}
func (validator *bidderParamValidator) Validate(name BidderName, ext json.RawMessage) error {
result, err := validator.parsedSchemas[name].Validate(gojsonschema.NewBytesLoader(ext))
if err != nil {
return err
}
if !result.Valid() {
errBuilder := bytes.NewBuffer(make([]byte, 0, 300))
for _, err := range result.Errors() {
errBuilder.WriteString(err.String())
}
return errors.New(errBuilder.String())
}
return nil
}
func (validator *bidderParamValidator) Schema(name BidderName) string {
return validator.schemaContents[name]
}