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

Use bidder name instead of syncer key #2948

Merged
merged 7 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
13 changes: 3 additions & 10 deletions endpoints/setuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ func NewSetUIDEndpoint(cfg *config.Configuration, syncersByBidder map[string]use
encoder := usersync.Base64Encoder{}
decoder := usersync.Base64Decoder{}

// convert map of syncers by bidder to map of syncers by key
// - its safe to assume that if multiple bidders map to the same key, the syncers are interchangeable.
syncersByKey := make(map[string]usersync.Syncer, len(syncersByBidder))
for _, v := range syncersByBidder {
syncersByKey[v.Key()] = v
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption is still generally true, but the bidder name is now important for activity control so this approach is no longer valid.


return httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
so := analytics.SetUIDObject{
Status: http.StatusOK,
Expand All @@ -65,7 +58,7 @@ func NewSetUIDEndpoint(cfg *config.Configuration, syncersByBidder map[string]use

query := r.URL.Query()

syncer, err := getSyncer(query, syncersByKey)
syncer, err := getSyncer(query, syncersByBidder)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -313,14 +306,14 @@ func parseConsentFromGppStr(gppQueryValue string) (string, error) {
return gdprConsent, nil
}

func getSyncer(query url.Values, syncersByKey map[string]usersync.Syncer) (usersync.Syncer, error) {
func getSyncer(query url.Values, syncersByBidder map[string]usersync.Syncer) (usersync.Syncer, error) {
key := query.Get("bidder")

if key == "" {
return nil, errors.New(`"bidder" query param is required`)
}

syncer, syncerExists := syncersByKey[key]
syncer, syncerExists := syncersByBidder[key]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should key within the brackets [key] now be called bidder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this change is already present in this PR: #2897 (comment)
But yes, it will be simpler to have it here :)

if !syncerExists {
return nil, errors.New("The bidder name provided is not supported by Prebid Server")
}
Expand Down
6 changes: 3 additions & 3 deletions usersync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var ErrSyncerKeyRequired = errors.New("key is required")

// NewSyncer creates a new Syncer from the provided configuration, or return an error if macro substition
// fails or an endpoint url is invalid.
func NewSyncer(hostConfig config.UserSync, syncerConfig config.Syncer) (Syncer, error) {
func NewSyncer(hostConfig config.UserSync, syncerConfig config.Syncer, bidder string) (Syncer, error) {
if syncerConfig.Key == "" {
return nil, ErrSyncerKeyRequired
}
Expand All @@ -80,7 +80,7 @@ func NewSyncer(hostConfig config.UserSync, syncerConfig config.Syncer) (Syncer,

if syncerConfig.IFrame != nil {
var err error
syncer.iframe, err = buildTemplate(syncerConfig.Key, setuidSyncTypeIFrame, hostConfig, syncerConfig.ExternalURL, *syncerConfig.IFrame)
syncer.iframe, err = buildTemplate(bidder, setuidSyncTypeIFrame, hostConfig, syncerConfig.ExternalURL, *syncerConfig.IFrame)
if err != nil {
return nil, fmt.Errorf("iframe %v", err)
}
Expand All @@ -91,7 +91,7 @@ func NewSyncer(hostConfig config.UserSync, syncerConfig config.Syncer) (Syncer,

if syncerConfig.Redirect != nil {
var err error
syncer.redirect, err = buildTemplate(syncerConfig.Key, setuidSyncTypeRedirect, hostConfig, syncerConfig.ExternalURL, *syncerConfig.Redirect)
syncer.redirect, err = buildTemplate(bidder, setuidSyncTypeRedirect, hostConfig, syncerConfig.ExternalURL, *syncerConfig.Redirect)
if err != nil {
return nil, fmt.Errorf("redirect %v", err)
}
Expand Down
19 changes: 9 additions & 10 deletions usersync/syncersbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ func BuildSyncers(hostConfig *config.Configuration, bidderInfos config.BidderInf
continue
}

syncer, err := NewSyncer(hostUserSyncConfig, primaryCfg.cfg)
if err != nil {
errs = append(errs, SyncerBuildError{
Bidder: primaryCfg.name,
SyncerKey: key,
Err: err,
})
continue
}

for _, bidder := range cfgGroup {
syncer, err := NewSyncer(hostUserSyncConfig, primaryCfg.cfg, bidder.name)
if err != nil {
errs = append(errs, SyncerBuildError{
Bidder: primaryCfg.name,
SyncerKey: key,
Err: err,
})
continue
}
syncers[bidder.name] = syncer
}
}
Expand Down