github.com/prebid/prebid-server/v2@v2.18.0/exchange/adapter_util.go (about)

     1  package exchange
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/prebid/prebid-server/v2/adapters"
     8  	"github.com/prebid/prebid-server/v2/config"
     9  	"github.com/prebid/prebid-server/v2/metrics"
    10  	"github.com/prebid/prebid-server/v2/openrtb_ext"
    11  )
    12  
    13  func BuildAdapters(client *http.Client, cfg *config.Configuration, infos config.BidderInfos, me metrics.MetricsEngine) (map[openrtb_ext.BidderName]AdaptedBidder, []error) {
    14  	server := config.Server{ExternalUrl: cfg.ExternalURL, GvlID: cfg.GDPR.HostVendorID, DataCenter: cfg.DataCenter}
    15  	bidders, errs := buildBidders(infos, newAdapterBuilders(), server)
    16  
    17  	if len(errs) > 0 {
    18  		return nil, errs
    19  	}
    20  
    21  	exchangeBidders := make(map[openrtb_ext.BidderName]AdaptedBidder, len(bidders))
    22  	for bidderName, bidder := range bidders {
    23  		info := infos[string(bidderName)]
    24  		exchangeBidder := AdaptBidder(bidder, client, cfg, me, bidderName, info.Debug, info.EndpointCompression)
    25  		exchangeBidder = addValidatedBidderMiddleware(exchangeBidder)
    26  		exchangeBidders[bidderName] = exchangeBidder
    27  	}
    28  	return exchangeBidders, nil
    29  }
    30  
    31  func buildBidders(infos config.BidderInfos, builders map[openrtb_ext.BidderName]adapters.Builder, server config.Server) (map[openrtb_ext.BidderName]adapters.Bidder, []error) {
    32  	bidders := make(map[openrtb_ext.BidderName]adapters.Bidder)
    33  	var errs []error
    34  
    35  	for bidder, info := range infos {
    36  		bidderName, bidderNameFound := openrtb_ext.NormalizeBidderName(bidder)
    37  		if !bidderNameFound {
    38  			errs = append(errs, fmt.Errorf("%v: unknown bidder", bidder))
    39  			continue
    40  		}
    41  
    42  		if len(info.AliasOf) > 0 {
    43  			if err := setAliasBuilder(info, builders, bidderName); err != nil {
    44  				errs = append(errs, fmt.Errorf("%v: failed to set alias builder: %v", bidder, err))
    45  				continue
    46  			}
    47  		}
    48  
    49  		builder, builderFound := builders[bidderName]
    50  		if !builderFound {
    51  			errs = append(errs, fmt.Errorf("%v: builder not registered", bidder))
    52  			continue
    53  		}
    54  
    55  		if info.IsEnabled() {
    56  			adapterInfo := buildAdapterInfo(info)
    57  			bidderInstance, builderErr := builder(bidderName, adapterInfo, server)
    58  
    59  			if builderErr != nil {
    60  				errs = append(errs, fmt.Errorf("%v: %v", bidder, builderErr))
    61  				continue
    62  			}
    63  			bidders[bidderName] = adapters.BuildInfoAwareBidder(bidderInstance, info)
    64  		}
    65  	}
    66  	return bidders, errs
    67  }
    68  
    69  func setAliasBuilder(info config.BidderInfo, builders map[openrtb_ext.BidderName]adapters.Builder, bidderName openrtb_ext.BidderName) error {
    70  	parentBidderName, parentBidderFound := openrtb_ext.NormalizeBidderName(info.AliasOf)
    71  	if !parentBidderFound {
    72  		return fmt.Errorf("unknown parent bidder: %v for alias: %v", info.AliasOf, bidderName)
    73  	}
    74  
    75  	builder, builderFound := builders[parentBidderName]
    76  	if !builderFound {
    77  		return fmt.Errorf("%v: parent builder not registered", parentBidderName)
    78  	}
    79  	builders[bidderName] = builder
    80  	return nil
    81  }
    82  
    83  func buildAdapterInfo(bidderInfo config.BidderInfo) config.Adapter {
    84  	adapter := config.Adapter{}
    85  	adapter.Endpoint = bidderInfo.Endpoint
    86  	adapter.ExtraAdapterInfo = bidderInfo.ExtraAdapterInfo
    87  	adapter.PlatformID = bidderInfo.PlatformID
    88  	adapter.AppSecret = bidderInfo.AppSecret
    89  	adapter.XAPI = bidderInfo.XAPI
    90  	return adapter
    91  }
    92  
    93  // GetActiveBidders returns a map of all active bidder names.
    94  func GetActiveBidders(infos config.BidderInfos) map[string]openrtb_ext.BidderName {
    95  	activeBidders := make(map[string]openrtb_ext.BidderName)
    96  
    97  	for name, info := range infos {
    98  		if info.IsEnabled() {
    99  			activeBidders[name] = openrtb_ext.BidderName(name)
   100  		}
   101  	}
   102  
   103  	return activeBidders
   104  }
   105  
   106  func GetDisabledBidderWarningMessages(infos config.BidderInfos) map[string]string {
   107  	removed := map[string]string{
   108  		"lifestreet":      `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
   109  		"adagio":          `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
   110  		"somoaudience":    `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
   111  		"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.`,
   112  		"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.`,
   113  		"oftmedia":        `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
   114  		"groupm":          `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
   115  		"verizonmedia":    `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
   116  		"brightroll":      `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
   117  		"engagebdr":       `Bidder "engagebdr" is no longer available in Prebid Server. Please update your configuration.`,
   118  		"ninthdecimal":    `Bidder "ninthdecimal" is no longer available in Prebid Server. Please update your configuration.`,
   119  		"kubient":         `Bidder "kubient" is no longer available in Prebid Server. Please update your configuration.`,
   120  		"applogy":         `Bidder "applogy" is no longer available in Prebid Server. Please update your configuration.`,
   121  		"rhythmone":       `Bidder "rhythmone" is no longer available in Prebid Server. Please update your configuration.`,
   122  		"nanointeractive": `Bidder "nanointeractive" is no longer available in Prebid Server. Please update your configuration.`,
   123  	}
   124  
   125  	return mergeRemovedAndDisabledBidderWarningMessages(removed, infos)
   126  }
   127  
   128  func mergeRemovedAndDisabledBidderWarningMessages(removed map[string]string, infos config.BidderInfos) map[string]string {
   129  	disabledBidders := removed
   130  
   131  	for name, info := range infos {
   132  		if info.Disabled {
   133  			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)
   134  			disabledBidders[name] = msg
   135  		}
   136  	}
   137  
   138  	return disabledBidders
   139  }