-
Notifications
You must be signed in to change notification settings - Fork 762
/
Copy pathadapter_util.go
139 lines (117 loc) · 5.87 KB
/
adapter_util.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
package exchange
import (
"fmt"
"net/http"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/metrics"
"github.com/prebid/prebid-server/v2/openrtb_ext"
)
func BuildAdapters(client *http.Client, cfg *config.Configuration, infos config.BidderInfos, me metrics.MetricsEngine) (map[openrtb_ext.BidderName]AdaptedBidder, []error) {
server := config.Server{ExternalUrl: cfg.ExternalURL, GvlID: cfg.GDPR.HostVendorID, DataCenter: cfg.DataCenter}
bidders, errs := buildBidders(infos, newAdapterBuilders(), server)
if len(errs) > 0 {
return nil, errs
}
exchangeBidders := make(map[openrtb_ext.BidderName]AdaptedBidder, len(bidders))
for bidderName, bidder := range bidders {
info := infos[string(bidderName)]
exchangeBidder := AdaptBidder(bidder, client, cfg, me, bidderName, info.Debug, info.EndpointCompression)
exchangeBidder = addValidatedBidderMiddleware(exchangeBidder)
exchangeBidders[bidderName] = exchangeBidder
}
return exchangeBidders, nil
}
func buildBidders(infos config.BidderInfos, builders map[openrtb_ext.BidderName]adapters.Builder, server config.Server) (map[openrtb_ext.BidderName]adapters.Bidder, []error) {
bidders := make(map[openrtb_ext.BidderName]adapters.Bidder)
var errs []error
for bidder, info := range infos {
bidderName, bidderNameFound := openrtb_ext.NormalizeBidderName(bidder)
if !bidderNameFound {
errs = append(errs, fmt.Errorf("%v: unknown bidder", bidder))
continue
}
if len(info.AliasOf) > 0 {
if err := setAliasBuilder(info, builders, bidderName); err != nil {
errs = append(errs, fmt.Errorf("%v: failed to set alias builder: %v", bidder, err))
continue
}
}
builder, builderFound := builders[bidderName]
if !builderFound {
errs = append(errs, fmt.Errorf("%v: builder not registered", bidder))
continue
}
if info.IsEnabled() {
adapterInfo := buildAdapterInfo(info)
bidderInstance, builderErr := builder(bidderName, adapterInfo, server)
if builderErr != nil {
errs = append(errs, fmt.Errorf("%v: %v", bidder, builderErr))
continue
}
bidders[bidderName] = adapters.BuildInfoAwareBidder(bidderInstance, info)
}
}
return bidders, errs
}
func setAliasBuilder(info config.BidderInfo, builders map[openrtb_ext.BidderName]adapters.Builder, bidderName openrtb_ext.BidderName) error {
parentBidderName, parentBidderFound := openrtb_ext.NormalizeBidderName(info.AliasOf)
if !parentBidderFound {
return fmt.Errorf("unknown parent bidder: %v for alias: %v", info.AliasOf, bidderName)
}
builder, builderFound := builders[parentBidderName]
if !builderFound {
return fmt.Errorf("%v: parent builder not registered", parentBidderName)
}
builders[bidderName] = builder
return nil
}
func buildAdapterInfo(bidderInfo config.BidderInfo) config.Adapter {
adapter := config.Adapter{}
adapter.Endpoint = bidderInfo.Endpoint
adapter.ExtraAdapterInfo = bidderInfo.ExtraAdapterInfo
adapter.PlatformID = bidderInfo.PlatformID
adapter.AppSecret = bidderInfo.AppSecret
adapter.XAPI = bidderInfo.XAPI
return adapter
}
// GetActiveBidders returns a map of all active bidder names.
func GetActiveBidders(infos config.BidderInfos) map[string]openrtb_ext.BidderName {
activeBidders := make(map[string]openrtb_ext.BidderName)
for name, info := range infos {
if info.IsEnabled() {
activeBidders[name] = openrtb_ext.BidderName(name)
}
}
return activeBidders
}
func GetDisabledBidderWarningMessages(infos config.BidderInfos) map[string]string {
removed := map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
"yssp": `Bidder "yssp" is no longer available in Prebid Server. If you're looking to use the Yahoo SSP adapter, please rename it to "yahooAds" in your configuration.`,
"andbeyondmedia": `Bidder "andbeyondmedia" is no longer available in Prebid Server. If you're looking to use the AndBeyond.Media SSP adapter, please rename it to "beyondmedia" in your configuration.`,
"oftmedia": `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
"groupm": `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
"verizonmedia": `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
"engagebdr": `Bidder "engagebdr" is no longer available in Prebid Server. Please update your configuration.`,
"ninthdecimal": `Bidder "ninthdecimal" is no longer available in Prebid Server. Please update your configuration.`,
"kubient": `Bidder "kubient" is no longer available in Prebid Server. Please update your configuration.`,
"applogy": `Bidder "applogy" is no longer available in Prebid Server. Please update your configuration.`,
"rhythmone": `Bidder "rhythmone" is no longer available in Prebid Server. Please update your configuration.`,
"nanointeractive": `Bidder "nanointeractive" is no longer available in Prebid Server. Please update your configuration.`,
}
return mergeRemovedAndDisabledBidderWarningMessages(removed, infos)
}
func mergeRemovedAndDisabledBidderWarningMessages(removed map[string]string, infos config.BidderInfos) map[string]string {
disabledBidders := removed
for name, info := range infos {
if info.Disabled {
msg := fmt.Sprintf(`Bidder "%s" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`, name)
disabledBidders[name] = msg
}
}
return disabledBidders
}