Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter aliases: moved adapter related configs to bidder.yaml files #2353

Merged
merged 24 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 5 additions & 75 deletions config/adapter.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,13 @@
package config

import (
"fmt"
"text/template"

validator "github.com/asaskevich/govalidator"
"github.com/prebid/prebid-server/macros"
)

type Adapter struct {
Disabled bool `mapstructure:"disabled"`
Endpoint string `mapstructure:"endpoint"`
ExtraAdapterInfo string `mapstructure:"extra_info"`
Syncer *Syncer `mapstructure:"usersync"`

// needed for backwards compatibility
UserSyncURL string `mapstructure:"usersync_url"`
Endpoint string
ExtraAdapterInfo string

// needed for Rubicon
XAPI AdapterXAPI `mapstructure:"xapi"`
XAPI AdapterXAPI

// needed for Facebook
PlatformID string `mapstructure:"platform_id"`
AppSecret string `mapstructure:"app_secret"`
}

type AdapterXAPI struct {
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Tracker string `mapstructure:"tracker"`
}

// validateAdapters validates adapter's endpoint and user sync URL
func validateAdapters(adapterMap map[string]Adapter, errs []error) []error {
for adapterName, adapter := range adapterMap {
if !adapter.Disabled {
errs = validateAdapterEndpoint(adapter.Endpoint, adapterName, errs)
}
}
return errs
}

var testEndpointTemplateParams = macros.EndpointTemplateParams{
Host: "anyHost",
PublisherID: "anyPublisherID",
AccountID: "anyAccountID",
ZoneID: "anyZoneID",
SourceId: "anySourceID",
AdUnit: "anyAdUnit",
}

// validateAdapterEndpoint makes sure that an adapter has a valid endpoint
// associated with it
func validateAdapterEndpoint(endpoint string, adapterName string, errs []error) []error {
if endpoint == "" {
return append(errs, fmt.Errorf("There's no default endpoint available for %s. Calls to this bidder/exchange will fail. "+
"Please set adapters.%s.endpoint in your app config", adapterName, adapterName))
}

// Create endpoint template
endpointTemplate, err := template.New("endpointTemplate").Parse(endpoint)
if err != nil {
return append(errs, fmt.Errorf("Invalid endpoint template: %s for adapter: %s. %v", endpoint, adapterName, err))
}
// Resolve macros (if any) in the endpoint URL
resolvedEndpoint, err := macros.ResolveMacros(endpointTemplate, testEndpointTemplateParams)
if err != nil {
return append(errs, fmt.Errorf("Unable to resolve endpoint: %s for adapter: %s. %v", endpoint, adapterName, err))
}
// Validate the resolved endpoint
//
// Validating using both IsURL and IsRequestURL because IsURL allows relative paths
// whereas IsRequestURL requires absolute path but fails to check other valid URL
// format constraints.
//
// For example: IsURL will allow "abcd.com" but IsRequestURL won't
// IsRequestURL will allow "http://http://abcd.com" but IsURL won't
if !validator.IsURL(resolvedEndpoint) || !validator.IsRequestURL(resolvedEndpoint) {
errs = append(errs, fmt.Errorf("The endpoint: %s for %s is not a valid URL", resolvedEndpoint, adapterName))
}
return errs
PlatformID string
AppSecret string
}
Loading