-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapter aliases: moved adapter related configs to bidder.yaml files (#…
…2353) * Adapter aliases: moved adapter related configs to bidder.yaml files * Moved adapter configs from config.go to bidder.yaml files * Removed ymal mappers * Clean up * Initial unit tests fix * Merge with latest master * Unit tests clean up * Added pbs.json or pbs.yaml config support * Fixes and unit tests, added ssyncer merge functions back * Merge fixes * Returned back adapter config set up using env variables * Unit tests fixes * Added test for adapter config overrides from environment variables * Minor improvements * Added more tests fro env variables, fixed mapstructures from bidder info * Code review refactoring * Code review refactoring and merge conflicts fixes * Typo fix Co-authored-by: vsolovei <[email protected]>
- Loading branch information
1 parent
59dd6fb
commit fb564dd
Showing
182 changed files
with
1,629 additions
and
1,391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.