From 7792d7cab2a6c1bf900d323f00433749bba61836 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 15 Aug 2017 15:06:00 -0400 Subject: [PATCH 01/18] Adding a dedicated FamilyName type within adapters --- adapters/adapter.go | 27 ++++++++++++++++++++++++++- adapters/appnexus.go | 4 ++-- adapters/facebook.go | 4 ++-- adapters/index.go | 4 ++-- adapters/openrtb_util.go | 6 +++--- adapters/pubmatic.go | 6 +++--- adapters/pulsepoint.go | 4 ++-- adapters/rubicon.go | 2 +- 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/adapters/adapter.go b/adapters/adapter.go index 03a9585a9ad..f6364fd2d7c 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -9,6 +9,31 @@ import ( "time" ) +// FamilyName type to verify and centralize FamilyName usage +type FamilyName int + +const ( + FNappnexus FamilyName = iota + FNfacebook + FNindex + FNpubmatic + FNpulsepoint + FNrubicon +) + +var validFamilyNames = [...]string{ + "adnxs", + "audienceNetwork", + "indexExchange", + "pubmatic", + "pulsepoint", + "rubicon", +} + +func (n FamilyName) String() string { + return validFamilyNames[int(n)] +} + // Adapters connect prebid-server to a demand partner. Their primary purpose is to produce bids // in response to Auction requests. type Adapter interface { @@ -17,7 +42,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() string + FamilyName() FamilyName // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index a4f29cbec40..961c71dbaaf 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -30,8 +30,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() string { - return "adnxs" +func (a *AppNexusAdapter) FamilyName() FamilyName { + return FNappnexus } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index b3de45f32ff..965bfcf928f 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -28,8 +28,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() string { - return "audienceNetwork" +func (a *FacebookAdapter) FamilyName() FamilyName { + return FNfacebook } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 669d4ab0201..2a138171a47 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -29,8 +29,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() string { - return "indexExchange" +func (a *IndexAdapter) FamilyName() FamilyName { + return FNindex } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index 2b5dea9db16..15f43528284 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -6,7 +6,7 @@ import ( "github.com/prebid/openrtb" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily string) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily FamilyName) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -50,8 +50,8 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily Page: req.Url, }, Device: req.Device, - User: &openrtb.User{ - BuyerUID: req.GetUserID(bidderFamily), + User: &openrtb.User{ // Make the family name conversion to string here. + BuyerUID: req.GetUserID(string(bidderFamily)), ID: req.GetUserID("adnxs"), }, Source: &openrtb.Source{ diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index db2c742ffef..42b048891b4 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -27,8 +27,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() string { - return "pubmatic" +func (a *PubmaticAdapter) FamilyName() FamilyName { + return FNpubmatic } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -84,7 +84,7 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder httpReq.Header.Add("Accept", "application/json") httpReq.AddCookie(&http.Cookie{ Name: "KADUSERCOOKIE", - Value: req.GetUserID(a.FamilyName()), + Value: req.GetUserID(string(a.FamilyName())), }) pbResp, err := ctxhttp.Do(ctx, a.http.Client, httpReq) diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index 1f6d6037745..dfdd1580615 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -29,8 +29,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() string { - return "pulsepoint" +func (a *PulsePointAdapter) FamilyName() FamilyName { + return FNpulsepoint } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 1163c97745b..943bac5d883 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -216,7 +216,7 @@ func (a *RubiconAdapter) callOne(ctx context.Context, req *pbs.PBSRequest, reqJS func (a *RubiconAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) { requests := make([]bytes.Buffer, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { - rubiReq := makeOpenRTBGeneric(req, bidder, a.FamilyName()) + rubiReq := makeOpenRTBGeneric(req, bidder, string(a.FamilyName())) // only grab this ad unit rubiReq.Imp = rubiReq.Imp[i : i+1] From b6eb1f27304ec66c2d1da87caeea67306355a0e9 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 15 Aug 2017 16:43:46 -0400 Subject: [PATCH 02/18] Define a family.Name type for strict checking on valid family names, and moved declaration to its own package to avoid circular dependencies. Need to fix tests still --- adapters/adapter.go | 28 ++-------------------------- adapters/appnexus.go | 5 +++-- adapters/facebook.go | 5 +++-- adapters/index.go | 5 +++-- adapters/openrtb_util.go | 7 ++++--- adapters/pubmatic.go | 7 ++++--- adapters/pulsepoint.go | 5 +++-- adapters/rubicon.go | 7 ++++--- family/family.go | 26 ++++++++++++++++++++++++++ pbs/pbsrequest.go | 5 +++-- 10 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 family/family.go diff --git a/adapters/adapter.go b/adapters/adapter.go index f6364fd2d7c..b6f1146bed7 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -3,37 +3,13 @@ package adapters import ( "context" "crypto/tls" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "github.com/prebid/prebid-server/ssl" "net/http" "time" ) -// FamilyName type to verify and centralize FamilyName usage -type FamilyName int - -const ( - FNappnexus FamilyName = iota - FNfacebook - FNindex - FNpubmatic - FNpulsepoint - FNrubicon -) - -var validFamilyNames = [...]string{ - "adnxs", - "audienceNetwork", - "indexExchange", - "pubmatic", - "pulsepoint", - "rubicon", -} - -func (n FamilyName) String() string { - return validFamilyNames[int(n)] -} - // Adapters connect prebid-server to a demand partner. Their primary purpose is to produce bids // in response to Auction requests. type Adapter interface { @@ -42,7 +18,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() FamilyName + FamilyName() family.Name // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index 961c71dbaaf..c1c84ce4464 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -16,6 +16,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" ) type AppNexusAdapter struct { @@ -30,8 +31,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() FamilyName { - return FNappnexus +func (a *AppNexusAdapter) FamilyName() family.Name { + return family.Appnexus } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index 965bfcf928f..d7f780708ff 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -28,8 +29,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() FamilyName { - return FNfacebook +func (a *FacebookAdapter) FamilyName() family.Name { + return family.Facebook } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 2a138171a47..9f662734b64 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -15,6 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" ) type IndexAdapter struct { @@ -29,8 +30,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() FamilyName { - return FNindex +func (a *IndexAdapter) FamilyName() family.Name { + return family.Index } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index 15f43528284..7bf233030e7 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -4,9 +4,10 @@ import ( "github.com/prebid/prebid-server/pbs" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily FamilyName) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily family.Name) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -51,8 +52,8 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily }, Device: req.Device, User: &openrtb.User{ // Make the family name conversion to string here. - BuyerUID: req.GetUserID(string(bidderFamily)), - ID: req.GetUserID("adnxs"), + BuyerUID: req.GetUserID(bidderFamily), + ID: req.GetUserID(family.Appnexus), }, Source: &openrtb.Source{ FD: 1, // upstream, aka header diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index 42b048891b4..f7ae58c28d0 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -11,6 +11,7 @@ import ( "net/url" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -27,8 +28,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() FamilyName { - return FNpubmatic +func (a *PubmaticAdapter) FamilyName() family.Name { + return family.Pubmatic } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -84,7 +85,7 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder httpReq.Header.Add("Accept", "application/json") httpReq.AddCookie(&http.Cookie{ Name: "KADUSERCOOKIE", - Value: req.GetUserID(string(a.FamilyName())), + Value: req.GetUserID(a.FamilyName()), }) pbResp, err := ctxhttp.Do(ctx, a.http.Client, httpReq) diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index dfdd1580615..0eaf3d028d3 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -29,8 +30,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() FamilyName { - return FNpulsepoint +func (a *PulsePointAdapter) FamilyName() family.Name { + return family.Pulsepoint } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 943bac5d883..8b344a15996 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -15,6 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" ) type RubiconAdapter struct { @@ -31,8 +32,8 @@ func (a *RubiconAdapter) Name() string { } // used for cookies and such -func (a *RubiconAdapter) FamilyName() string { - return "rubicon" +func (a *RubiconAdapter) FamilyName() family.Name { + return family.Rubicon } func (a *RubiconAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -216,7 +217,7 @@ func (a *RubiconAdapter) callOne(ctx context.Context, req *pbs.PBSRequest, reqJS func (a *RubiconAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) { requests := make([]bytes.Buffer, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { - rubiReq := makeOpenRTBGeneric(req, bidder, string(a.FamilyName())) + rubiReq := makeOpenRTBGeneric(req, bidder, a.FamilyName()) // only grab this ad unit rubiReq.Imp = rubiReq.Imp[i : i+1] diff --git a/family/family.go b/family/family.go new file mode 100644 index 00000000000..323d753dfff --- /dev/null +++ b/family/family.go @@ -0,0 +1,26 @@ +package family + +// Family Name type to verify and centralize FamilyName usage +type Name int + +const ( + Appnexus Name = iota + Facebook + Index + Pubmatic + Pulsepoint + Rubicon +) + +var validFamilyNames = [...]string{ + "adnxs", + "audienceNetwork", + "indexExchange", + "pubmatic", + "pulsepoint", + "rubicon", +} + +func (n Name) String() string { + return validFamilyNames[int(n)] +} diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index 449d3dd7b7b..d5bd6c93bf2 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -15,6 +15,7 @@ import ( "github.com/prebid/openrtb" "github.com/prebid/prebid-server/cache" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/prebid" ) @@ -229,8 +230,8 @@ func (req PBSRequest) Elapsed() int { return int(time.Since(req.Start) / 1000000) } -func (req PBSRequest) GetUserID(BidderCode string) string { - if uid, ok := req.UserIDs[BidderCode]; ok { +func (req PBSRequest) GetUserID(BidderCode family.Name) string { + if uid, ok := req.UserIDs[string(BidderCode)]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. return uid } return "" From b8e7bdeedc3c3cb5b6f678a1509dd20f91d8b445 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Wed, 16 Aug 2017 10:17:28 -0400 Subject: [PATCH 03/18] Test fixing round one --- adapters/openrtb_util_test.go | 5 +++-- adapters/pulsepoint_test.go | 2 +- pbs_light.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adapters/openrtb_util_test.go b/adapters/openrtb_util_test.go index 6054d0750cc..649f6d4326b 100644 --- a/adapters/openrtb_util_test.go +++ b/adapters/openrtb_util_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/prebid/openrtb" + "github.com/prebid/prebid-server/family" ) func TestOpenRTB(t *testing.T) { @@ -26,7 +27,7 @@ func TestOpenRTB(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, "test") + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Rubicon) assert.Equal(t, resp.Imp[0].ID, "unitCode") assert.EqualValues(t, resp.Imp[0].Banner.W, 10) @@ -44,6 +45,6 @@ func TestOpenRTBNoSize(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, "test") + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Index) assert.Equal(t, resp.Imp[0].ID, "") } diff --git a/adapters/pulsepoint_test.go b/adapters/pulsepoint_test.go index ff27c6dad97..2ad6c30eb27 100644 --- a/adapters/pulsepoint_test.go +++ b/adapters/pulsepoint_test.go @@ -30,7 +30,7 @@ type PulsePointOrtbMockService struct { func TestPulsePointAdapterNames(t *testing.T) { adapter := NewPulsePointAdapter(DefaultHTTPAdapterConfig, "http://localhost/bid", "http://localhost") VerifyStringValue(adapter.Name(), "pulsepoint", t) - VerifyStringValue(adapter.FamilyName(), "pulsepoint", t) + VerifyStringValue(string(adapter.FamilyName()), "pulsepoint", t) } /** diff --git a/pbs_light.go b/pbs_light.go index 62f41635252..74fd6b69887 100644 --- a/pbs_light.go +++ b/pbs_light.go @@ -188,7 +188,7 @@ func cookieSync(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { for _, bidder := range csReq.Bidders { if ex, ok := exchanges[bidder]; ok { - if _, ok := cookies.UIDs[ex.FamilyName()]; !ok { + if _, ok := cookies.UIDs[string(ex.FamilyName())]; !ok { b := pbs.PBSBidder{ BidderCode: bidder, NoCookie: true, From 6ab5fc5ec4cd9c08e1b04c934b2b8a868746211d Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Wed, 16 Aug 2017 11:07:14 -0400 Subject: [PATCH 04/18] Initial bugfixes --- pbs_light.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbs_light.go b/pbs_light.go index 74fd6b69887..9f6fe771f66 100644 --- a/pbs_light.go +++ b/pbs_light.go @@ -188,7 +188,7 @@ func cookieSync(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { for _, bidder := range csReq.Bidders { if ex, ok := exchanges[bidder]; ok { - if _, ok := cookies.UIDs[string(ex.FamilyName())]; !ok { + if _, ok := cookies.UIDs[ex.FamilyName().String()]; !ok { b := pbs.PBSBidder{ BidderCode: bidder, NoCookie: true, From 12664b3aa0dc62cb3c99fd50167c5b0a0c2e6c46 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Wed, 16 Aug 2017 11:07:42 -0400 Subject: [PATCH 05/18] Initial bugfixes (missed file) --- pbs/pbsrequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index d5bd6c93bf2..d544f95f649 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -231,7 +231,7 @@ func (req PBSRequest) Elapsed() int { } func (req PBSRequest) GetUserID(BidderCode family.Name) string { - if uid, ok := req.UserIDs[string(BidderCode)]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. + if uid, ok := req.UserIDs[BidderCode.String()]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. return uid } return "" From 29c5bb699a557c4ca676a327c7ff6ae3c5e68ca0 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Wed, 16 Aug 2017 11:39:36 -0400 Subject: [PATCH 06/18] Now passes ./validate.sh --- adapters/pulsepoint_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/pulsepoint_test.go b/adapters/pulsepoint_test.go index 2ad6c30eb27..8fb73a8537b 100644 --- a/adapters/pulsepoint_test.go +++ b/adapters/pulsepoint_test.go @@ -30,7 +30,7 @@ type PulsePointOrtbMockService struct { func TestPulsePointAdapterNames(t *testing.T) { adapter := NewPulsePointAdapter(DefaultHTTPAdapterConfig, "http://localhost/bid", "http://localhost") VerifyStringValue(adapter.Name(), "pulsepoint", t) - VerifyStringValue(string(adapter.FamilyName()), "pulsepoint", t) + VerifyStringValue(adapter.FamilyName().String(), "pulsepoint", t) } /** From dfaaf0ec538ca28040cb87f3b29441f570654667 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Thu, 17 Aug 2017 13:42:37 -0400 Subject: [PATCH 07/18] Move family -> constants --- adapters/adapter.go | 4 ++-- adapters/appnexus.go | 6 +++--- adapters/facebook.go | 6 +++--- adapters/index.go | 6 +++--- adapters/openrtb_util.go | 8 ++++---- adapters/openrtb_util_test.go | 6 +++--- adapters/pubmatic.go | 6 +++--- adapters/pulsepoint.go | 6 +++--- adapters/rubicon.go | 6 +++--- pbs/pbsrequest.go | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/adapters/adapter.go b/adapters/adapter.go index b6f1146bed7..b68cc473bb6 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -3,7 +3,7 @@ package adapters import ( "context" "crypto/tls" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" "github.com/prebid/prebid-server/pbs" "github.com/prebid/prebid-server/ssl" "net/http" @@ -18,7 +18,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() family.Name + FamilyName() constants.FamilyName // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index c1c84ce4464..b0c602da538 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -16,7 +16,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" ) type AppNexusAdapter struct { @@ -31,8 +31,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() family.Name { - return family.Appnexus +func (a *AppNexusAdapter) FamilyName() constants.FamilyName { + return constants.FNAppnexus } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index d7f780708ff..6cfc27a8343 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -29,8 +29,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() family.Name { - return family.Facebook +func (a *FacebookAdapter) FamilyName() constants.FamilyName { + return constants.FNFacebook } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 9f662734b64..331f580d345 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -15,7 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" ) type IndexAdapter struct { @@ -30,8 +30,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() family.Name { - return family.Index +func (a *IndexAdapter) FamilyName() constants.FamilyName { + return constants.FNIndex } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index 7bf233030e7..c87a7608c84 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -4,10 +4,10 @@ import ( "github.com/prebid/prebid-server/pbs" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily family.Name) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily constants.FamilyName) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -51,9 +51,9 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily Page: req.Url, }, Device: req.Device, - User: &openrtb.User{ // Make the family name conversion to string here. + User: &openrtb.User{ BuyerUID: req.GetUserID(bidderFamily), - ID: req.GetUserID(family.Appnexus), + ID: req.GetUserID(constants.FNAppnexus), }, Source: &openrtb.Source{ FD: 1, // upstream, aka header diff --git a/adapters/openrtb_util_test.go b/adapters/openrtb_util_test.go index 649f6d4326b..63055579dfd 100644 --- a/adapters/openrtb_util_test.go +++ b/adapters/openrtb_util_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" ) func TestOpenRTB(t *testing.T) { @@ -27,7 +27,7 @@ func TestOpenRTB(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Rubicon) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, constants.FNRubicon) assert.Equal(t, resp.Imp[0].ID, "unitCode") assert.EqualValues(t, resp.Imp[0].Banner.W, 10) @@ -45,6 +45,6 @@ func TestOpenRTBNoSize(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Index) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, constants.FNIndex) assert.Equal(t, resp.Imp[0].ID, "") } diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index f7ae58c28d0..c25eebc9887 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -11,7 +11,7 @@ import ( "net/url" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -28,8 +28,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() family.Name { - return family.Pubmatic +func (a *PubmaticAdapter) FamilyName() constants.FamilyName { + return constants.FNPubmatic } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index 0eaf3d028d3..d72373e4bdf 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -13,7 +13,7 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -30,8 +30,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() family.Name { - return family.Pulsepoint +func (a *PulsePointAdapter) FamilyName() constants.FamilyName { + return constants.FNPulsepoint } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 8b344a15996..0653054f979 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -15,7 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" ) type RubiconAdapter struct { @@ -32,8 +32,8 @@ func (a *RubiconAdapter) Name() string { } // used for cookies and such -func (a *RubiconAdapter) FamilyName() family.Name { - return family.Rubicon +func (a *RubiconAdapter) FamilyName() constants.FamilyName { + return constants.FNRubicon } func (a *RubiconAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index d544f95f649..b105f9b22eb 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -15,7 +15,7 @@ import ( "github.com/prebid/openrtb" "github.com/prebid/prebid-server/cache" - "github.com/prebid/prebid-server/family" + "github.com/prebid/prebid-server/constants" "github.com/prebid/prebid-server/prebid" ) @@ -230,7 +230,7 @@ func (req PBSRequest) Elapsed() int { return int(time.Since(req.Start) / 1000000) } -func (req PBSRequest) GetUserID(BidderCode family.Name) string { +func (req PBSRequest) GetUserID(BidderCode constants.FamilyName) string { if uid, ok := req.UserIDs[BidderCode.String()]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. return uid } From 2a27acf48584926dc9237011e344958713bbb5c1 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Thu, 17 Aug 2017 14:22:26 -0400 Subject: [PATCH 08/18] Now with the family package removed and constants actually added --- family/family.go => constants/constants.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename family/family.go => constants/constants.go (59%) diff --git a/family/family.go b/constants/constants.go similarity index 59% rename from family/family.go rename to constants/constants.go index 323d753dfff..7d0cf55834a 100644 --- a/family/family.go +++ b/constants/constants.go @@ -1,15 +1,15 @@ -package family +package constants // Family Name type to verify and centralize FamilyName usage -type Name int +type FamilyName int const ( - Appnexus Name = iota - Facebook - Index - Pubmatic - Pulsepoint - Rubicon + FNAppnexus FamilyName = iota + FNFacebook + FNIndex + FNPubmatic + FNPulsepoint + FNRubicon ) var validFamilyNames = [...]string{ @@ -21,6 +21,6 @@ var validFamilyNames = [...]string{ "rubicon", } -func (n Name) String() string { +func (n FamilyName) String() string { return validFamilyNames[int(n)] } From 608aef198504b341c46358a01540cb624c9bf281 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:24:28 -0400 Subject: [PATCH 09/18] Revert "drop unused cache code (#95)" This reverts commit 2a8c64bf1c1b03ba1672d9dc1bcd1b968cdb30c7. --- cache/cache.go | 12 +++ cache/dummycache/dummycache.go | 42 +++++++++++ cache/dummycache/dummycache_test.go | 18 +++++ cache/filecache/filecache.go | 66 ++++++++++++++++ cache/filecache/filecache_test.go | 38 +++++++++- cache/postgrescache/postgrescache.go | 91 ++++++++++++++++++++++- cache/postgrescache/postgrescache_test.go | 7 +- 7 files changed, 267 insertions(+), 7 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 427ec74d9d8..ac2c4288f16 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -20,7 +20,9 @@ type Configuration struct { type Cache interface { Close() error Accounts() AccountsService + Apps() AppsService Config() ConfigService + Domains() DomainsService } type AccountsService interface { @@ -28,7 +30,17 @@ type AccountsService interface { Set(*Account) error } +type AppsService interface { + Get(string) (*App, error) + Set(*App) error +} + type ConfigService interface { Get(string) (string, error) Set(string, string) error } + +type DomainsService interface { + Get(string) (*Domain, error) + Set(*Domain) error +} diff --git a/cache/dummycache/dummycache.go b/cache/dummycache/dummycache.go index 8cf9f2c4dff..f61d3fcd67d 100644 --- a/cache/dummycache/dummycache.go +++ b/cache/dummycache/dummycache.go @@ -9,6 +9,8 @@ import ( // Cache dummy config that will echo back results type Cache struct { accounts *accountService + domains *domainService + apps *appsService config *configService } @@ -16,6 +18,8 @@ type Cache struct { func New() (*Cache, error) { return &Cache{ accounts: &accountService{}, + domains: &domainService{}, + apps: &appsService{}, config: &configService{}, }, nil } @@ -23,6 +27,12 @@ func New() (*Cache, error) { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } +func (c *Cache) Domains() cache.DomainsService { + return c.domains +} +func (c *Cache) Apps() cache.AppsService { + return c.apps +} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -43,6 +53,38 @@ func (s *accountService) Set(account *cache.Account) error { return nil } +// DomainService handles the domain information +type domainService struct { +} + +// Get echos back the domain +func (s *domainService) Get(id string) (*cache.Domain, error) { + return &cache.Domain{ + Domain: id, + }, nil +} + +// Set will always return nil since this is a dummy service +func (s *domainService) Set(domain *cache.Domain) error { + return nil +} + +// AppsService handles apps information +type appsService struct { +} + +// Get echos back the app +func (s *appsService) Get(id string) (*cache.App, error) { + return &cache.App{ + Bundle: id, + }, nil +} + +// Set will always return nil since this is a dummy service +func (s *appsService) Set(app *cache.App) error { + return nil +} + // ConfigService not supported, always returns an error type configService struct { c string diff --git a/cache/dummycache/dummycache_test.go b/cache/dummycache/dummycache_test.go index 74004feaa38..b8b35a14242 100644 --- a/cache/dummycache/dummycache_test.go +++ b/cache/dummycache/dummycache_test.go @@ -6,6 +6,24 @@ func TestDummyCache(t *testing.T) { c, _ := New() + domain, err := c.Domains().Get("one.com") + if err != nil { + t.Fatal(err) + } + + if domain.Domain != "one.com" { + t.Error("Wrong domain returned") + } + + app, err := c.Apps().Get("com.app.one") + if err != nil { + t.Fatal(err) + } + + if app.Bundle != "com.app.one" { + t.Error("Wrong app returned") + } + account, err := c.Accounts().Get("account1") if err != nil { t.Fatal(err) diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go index 1ddc05121b0..503c33459c5 100644 --- a/cache/filecache/filecache.go +++ b/cache/filecache/filecache.go @@ -11,6 +11,8 @@ import ( type shared struct { Configs map[string]string + Domains map[string]bool + Apps map[string]bool Accounts map[string]bool } @@ -18,6 +20,8 @@ type shared struct { type Cache struct { shared *shared accounts *accountService + domains *domainService + apps *appsService config *configService } @@ -28,6 +32,8 @@ type fileConfig struct { type fileCacheFile struct { Configs []fileConfig `yaml:"configs"` + Domains []string `yaml:"domains"` + Apps []string `yaml:"apps"` Accounts []string `yaml:"accounts"` } @@ -63,6 +69,18 @@ func New(filename string) (*Cache, error) { } glog.Infof("Loaded %d configs", len(u.Configs)) + s.Domains = make(map[string]bool, len(u.Domains)) + for _, domain := range u.Domains { + s.Domains[domain] = true + } + glog.Infof("Loaded %d domains", len(u.Domains)) + + s.Apps = make(map[string]bool, len(u.Apps)) + for _, app := range u.Apps { + s.Apps[app] = true + } + glog.Infof("Loaded %d apps", len(u.Apps)) + s.Accounts = make(map[string]bool, len(u.Accounts)) for _, Account := range u.Accounts { s.Accounts[Account] = true @@ -72,6 +90,8 @@ func New(filename string) (*Cache, error) { return &Cache{ shared: s, accounts: &accountService{s}, + domains: &domainService{s}, + apps: &appsService{s}, config: &configService{s}, }, nil } @@ -85,6 +105,12 @@ func (c *Cache) Close() error { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } +func (c *Cache) Domains() cache.DomainsService { + return c.domains +} +func (c *Cache) Apps() cache.AppsService { + return c.apps +} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -109,6 +135,46 @@ func (s *accountService) Set(account *cache.Account) error { return nil } +// DomainService handles the domain information +type domainService struct { + shared *shared +} + +// Get will return back the domain if it exists in memory +func (s *domainService) Get(id string) (*cache.Domain, error) { + if _, ok := s.shared.Domains[id]; !ok { + return nil, fmt.Errorf("Not found") + } + return &cache.Domain{ + Domain: id, + }, nil +} + +// Set will always return nil since this is a dummy service +func (s *domainService) Set(domain *cache.Domain) error { + return nil +} + +// AppsService handles apps information +type appsService struct { + shared *shared +} + +// Get will return the App if it exists +func (s *appsService) Get(id string) (*cache.App, error) { + if _, ok := s.shared.Apps[id]; !ok { + return nil, fmt.Errorf("Not found") + } + return &cache.App{ + Bundle: id, + }, nil +} + +// Set will always return nil since this is a dummy service +func (s *appsService) Set(app *cache.App) error { + return nil +} + // ConfigService not supported, always returns an error type configService struct { shared *shared diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go index 80a72803bbe..665492a30b5 100644 --- a/cache/filecache/filecache_test.go +++ b/cache/filecache/filecache_test.go @@ -10,6 +10,8 @@ import ( func TestFileCache(t *testing.T) { fcf := fileCacheFile{ + Domains: []string{"one.com", "two.com", "three.com"}, + Apps: []string{"com.app.one", "com.app.two", "com.app.three"}, Accounts: []string{"account1", "account2", "account3"}, Configs: []fileConfig{ { @@ -49,18 +51,46 @@ func TestFileCache(t *testing.T) { t.Fatal(err) } + d, err := dataCache.Domains().Get("one.com") + if err != nil { + t.Fatal(err) + } + + if d.Domain != "one.com" { + t.Error("fetched invalid domain") + } + + d, err = dataCache.Domains().Get("abc123") + if err == nil { + t.Error("domain should not exist in cache") + } + + app, err := dataCache.Apps().Get("com.app.one") + if err != nil { + t.Fatal(err) + } + + if app.Bundle != "com.app.one" { + t.Error("fetched invalid app") + } + + app, err = dataCache.Apps().Get("abc123") + if err == nil { + t.Error("domain should not exist in cache") + } + a, err := dataCache.Accounts().Get("account1") if err != nil { t.Fatal(err) } if a.ID != "account1" { - t.Error("fetched invalid account") + t.Error("fetched invalid domain") } a, err = dataCache.Accounts().Get("abc123") if err == nil { - t.Error("account should not exist in cache") + t.Error("domain should not exist in cache") } c, err := dataCache.Config().Get("one") @@ -69,11 +99,11 @@ func TestFileCache(t *testing.T) { } if c != "config1" { - t.Error("fetched invalid config") + t.Error("fetched invalid domain") } c, err = dataCache.Config().Get("abc123") if err == nil { - t.Error("config should not exist in cache") + t.Error("domain should not exist in cache") } } diff --git a/cache/postgrescache/postgrescache.go b/cache/postgrescache/postgrescache.go index 9e602bf1226..722b2d3402b 100644 --- a/cache/postgrescache/postgrescache.go +++ b/cache/postgrescache/postgrescache.go @@ -5,7 +5,6 @@ import ( "database/sql" "encoding/gob" "fmt" - _ "github.com/lib/pq" "github.com/coocood/freecache" @@ -77,8 +76,11 @@ func newShared(conf PostgresConfig) (*shared, error) { // Cache postgres type Cache struct { - shared *shared + shared *shared + accounts *accountService + domains *domainService + apps *appsService config *configService } @@ -92,6 +94,8 @@ func New(cfg PostgresConfig) (*Cache, error) { return &Cache{ shared: shared, accounts: &accountService{shared: shared}, + domains: &domainService{shared: shared}, + apps: &appsService{shared: shared}, config: &configService{shared: shared}, }, nil } @@ -99,6 +103,12 @@ func New(cfg PostgresConfig) (*Cache, error) { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } +func (c *Cache) Domains() cache.DomainsService { + return c.domains +} +func (c *Cache) Apps() cache.AppsService { + return c.apps +} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -156,6 +166,83 @@ func (s *accountService) Set(account *cache.Account) error { return nil } +// DomainService handles the domain information +type domainService struct { + shared *shared +} + +// Set +func (s *domainService) Set(domain *cache.Domain) error { + return nil +} + +func (s *domainService) Get(key string) (*cache.Domain, error) { + var domain string + var d cache.Domain + + b, err := s.shared.lru.Get([]byte(key)) + if err == nil { + buf := bytes.NewReader(b) + if err = gob.NewDecoder(buf).Decode(&d); err != nil { + panic(err) + } + return &d, nil + } + + if err := s.shared.db.QueryRow("SELECT domain FROM domains_domain where domain = $1 LIMIT 1", key).Scan(&domain); err != nil { + /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ + return nil, err + } + + d.Domain = domain + + buf := bytes.Buffer{} + if err := gob.NewEncoder(&buf).Encode(&d); err != nil { + panic(err) + } + + s.shared.lru.Set([]byte(key), buf.Bytes(), s.shared.ttlSeconds) + return &d, nil +} + +// AppsService handles apps information +type appsService struct { + shared *shared +} + +func (s *appsService) Set(app *cache.App) error { + return nil +} + +func (s *appsService) Get(key string) (*cache.App, error) { + var bundle string + var app cache.App + + b, err := s.shared.lru.Get([]byte(key)) + if err == nil { + buf := bytes.NewReader(b) + if err = gob.NewDecoder(buf).Decode(&app); err != nil { + panic(err) + } + return &app, nil + } + + if err := s.shared.db.QueryRow("SELECT bundle FROM mobile_bundle where bundle = $1 LIMIT 1", key).Scan(&bundle); err != nil { + /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ + return nil, err + } + + app.Bundle = bundle + + buf := bytes.Buffer{} + if err := gob.NewEncoder(&buf).Encode(&app); err != nil { + panic(err) + } + + s.shared.lru.Set([]byte(key), buf.Bytes(), s.shared.ttlSeconds) + return &app, nil +} + // ConfigService type configService struct { shared *shared diff --git a/cache/postgrescache/postgrescache_test.go b/cache/postgrescache/postgrescache_test.go index cc3d6cfc795..0bfac79acbd 100644 --- a/cache/postgrescache/postgrescache_test.go +++ b/cache/postgrescache/postgrescache_test.go @@ -31,8 +31,11 @@ func TestPostgresConfig(t *testing.T) { } type StubCache struct { - shared *shared + shared *shared + accounts *accountService + domains *domainService + apps *appsService config *configService } @@ -42,6 +45,8 @@ func StubNew(cfg PostgresConfig) *Cache { return &Cache{ shared: shared, accounts: &accountService{shared: shared}, + domains: &domainService{shared: shared}, + apps: &appsService{shared: shared}, config: &configService{shared: shared}, } } From bd763ff16aa723169007176fd5452da8d26e47c9 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:37:00 -0400 Subject: [PATCH 10/18] Revert "Revert "drop unused cache code (#95)"" Fixing bad revert This reverts commit 608aef198504b341c46358a01540cb624c9bf281. --- cache/cache.go | 12 --- cache/dummycache/dummycache.go | 42 ----------- cache/dummycache/dummycache_test.go | 18 ----- cache/filecache/filecache.go | 66 ---------------- cache/filecache/filecache_test.go | 38 +--------- cache/postgrescache/postgrescache.go | 91 +---------------------- cache/postgrescache/postgrescache_test.go | 7 +- 7 files changed, 7 insertions(+), 267 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index ac2c4288f16..427ec74d9d8 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -20,9 +20,7 @@ type Configuration struct { type Cache interface { Close() error Accounts() AccountsService - Apps() AppsService Config() ConfigService - Domains() DomainsService } type AccountsService interface { @@ -30,17 +28,7 @@ type AccountsService interface { Set(*Account) error } -type AppsService interface { - Get(string) (*App, error) - Set(*App) error -} - type ConfigService interface { Get(string) (string, error) Set(string, string) error } - -type DomainsService interface { - Get(string) (*Domain, error) - Set(*Domain) error -} diff --git a/cache/dummycache/dummycache.go b/cache/dummycache/dummycache.go index f61d3fcd67d..8cf9f2c4dff 100644 --- a/cache/dummycache/dummycache.go +++ b/cache/dummycache/dummycache.go @@ -9,8 +9,6 @@ import ( // Cache dummy config that will echo back results type Cache struct { accounts *accountService - domains *domainService - apps *appsService config *configService } @@ -18,8 +16,6 @@ type Cache struct { func New() (*Cache, error) { return &Cache{ accounts: &accountService{}, - domains: &domainService{}, - apps: &appsService{}, config: &configService{}, }, nil } @@ -27,12 +23,6 @@ func New() (*Cache, error) { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } -func (c *Cache) Domains() cache.DomainsService { - return c.domains -} -func (c *Cache) Apps() cache.AppsService { - return c.apps -} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -53,38 +43,6 @@ func (s *accountService) Set(account *cache.Account) error { return nil } -// DomainService handles the domain information -type domainService struct { -} - -// Get echos back the domain -func (s *domainService) Get(id string) (*cache.Domain, error) { - return &cache.Domain{ - Domain: id, - }, nil -} - -// Set will always return nil since this is a dummy service -func (s *domainService) Set(domain *cache.Domain) error { - return nil -} - -// AppsService handles apps information -type appsService struct { -} - -// Get echos back the app -func (s *appsService) Get(id string) (*cache.App, error) { - return &cache.App{ - Bundle: id, - }, nil -} - -// Set will always return nil since this is a dummy service -func (s *appsService) Set(app *cache.App) error { - return nil -} - // ConfigService not supported, always returns an error type configService struct { c string diff --git a/cache/dummycache/dummycache_test.go b/cache/dummycache/dummycache_test.go index b8b35a14242..74004feaa38 100644 --- a/cache/dummycache/dummycache_test.go +++ b/cache/dummycache/dummycache_test.go @@ -6,24 +6,6 @@ func TestDummyCache(t *testing.T) { c, _ := New() - domain, err := c.Domains().Get("one.com") - if err != nil { - t.Fatal(err) - } - - if domain.Domain != "one.com" { - t.Error("Wrong domain returned") - } - - app, err := c.Apps().Get("com.app.one") - if err != nil { - t.Fatal(err) - } - - if app.Bundle != "com.app.one" { - t.Error("Wrong app returned") - } - account, err := c.Accounts().Get("account1") if err != nil { t.Fatal(err) diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go index 503c33459c5..1ddc05121b0 100644 --- a/cache/filecache/filecache.go +++ b/cache/filecache/filecache.go @@ -11,8 +11,6 @@ import ( type shared struct { Configs map[string]string - Domains map[string]bool - Apps map[string]bool Accounts map[string]bool } @@ -20,8 +18,6 @@ type shared struct { type Cache struct { shared *shared accounts *accountService - domains *domainService - apps *appsService config *configService } @@ -32,8 +28,6 @@ type fileConfig struct { type fileCacheFile struct { Configs []fileConfig `yaml:"configs"` - Domains []string `yaml:"domains"` - Apps []string `yaml:"apps"` Accounts []string `yaml:"accounts"` } @@ -69,18 +63,6 @@ func New(filename string) (*Cache, error) { } glog.Infof("Loaded %d configs", len(u.Configs)) - s.Domains = make(map[string]bool, len(u.Domains)) - for _, domain := range u.Domains { - s.Domains[domain] = true - } - glog.Infof("Loaded %d domains", len(u.Domains)) - - s.Apps = make(map[string]bool, len(u.Apps)) - for _, app := range u.Apps { - s.Apps[app] = true - } - glog.Infof("Loaded %d apps", len(u.Apps)) - s.Accounts = make(map[string]bool, len(u.Accounts)) for _, Account := range u.Accounts { s.Accounts[Account] = true @@ -90,8 +72,6 @@ func New(filename string) (*Cache, error) { return &Cache{ shared: s, accounts: &accountService{s}, - domains: &domainService{s}, - apps: &appsService{s}, config: &configService{s}, }, nil } @@ -105,12 +85,6 @@ func (c *Cache) Close() error { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } -func (c *Cache) Domains() cache.DomainsService { - return c.domains -} -func (c *Cache) Apps() cache.AppsService { - return c.apps -} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -135,46 +109,6 @@ func (s *accountService) Set(account *cache.Account) error { return nil } -// DomainService handles the domain information -type domainService struct { - shared *shared -} - -// Get will return back the domain if it exists in memory -func (s *domainService) Get(id string) (*cache.Domain, error) { - if _, ok := s.shared.Domains[id]; !ok { - return nil, fmt.Errorf("Not found") - } - return &cache.Domain{ - Domain: id, - }, nil -} - -// Set will always return nil since this is a dummy service -func (s *domainService) Set(domain *cache.Domain) error { - return nil -} - -// AppsService handles apps information -type appsService struct { - shared *shared -} - -// Get will return the App if it exists -func (s *appsService) Get(id string) (*cache.App, error) { - if _, ok := s.shared.Apps[id]; !ok { - return nil, fmt.Errorf("Not found") - } - return &cache.App{ - Bundle: id, - }, nil -} - -// Set will always return nil since this is a dummy service -func (s *appsService) Set(app *cache.App) error { - return nil -} - // ConfigService not supported, always returns an error type configService struct { shared *shared diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go index 665492a30b5..80a72803bbe 100644 --- a/cache/filecache/filecache_test.go +++ b/cache/filecache/filecache_test.go @@ -10,8 +10,6 @@ import ( func TestFileCache(t *testing.T) { fcf := fileCacheFile{ - Domains: []string{"one.com", "two.com", "three.com"}, - Apps: []string{"com.app.one", "com.app.two", "com.app.three"}, Accounts: []string{"account1", "account2", "account3"}, Configs: []fileConfig{ { @@ -51,46 +49,18 @@ func TestFileCache(t *testing.T) { t.Fatal(err) } - d, err := dataCache.Domains().Get("one.com") - if err != nil { - t.Fatal(err) - } - - if d.Domain != "one.com" { - t.Error("fetched invalid domain") - } - - d, err = dataCache.Domains().Get("abc123") - if err == nil { - t.Error("domain should not exist in cache") - } - - app, err := dataCache.Apps().Get("com.app.one") - if err != nil { - t.Fatal(err) - } - - if app.Bundle != "com.app.one" { - t.Error("fetched invalid app") - } - - app, err = dataCache.Apps().Get("abc123") - if err == nil { - t.Error("domain should not exist in cache") - } - a, err := dataCache.Accounts().Get("account1") if err != nil { t.Fatal(err) } if a.ID != "account1" { - t.Error("fetched invalid domain") + t.Error("fetched invalid account") } a, err = dataCache.Accounts().Get("abc123") if err == nil { - t.Error("domain should not exist in cache") + t.Error("account should not exist in cache") } c, err := dataCache.Config().Get("one") @@ -99,11 +69,11 @@ func TestFileCache(t *testing.T) { } if c != "config1" { - t.Error("fetched invalid domain") + t.Error("fetched invalid config") } c, err = dataCache.Config().Get("abc123") if err == nil { - t.Error("domain should not exist in cache") + t.Error("config should not exist in cache") } } diff --git a/cache/postgrescache/postgrescache.go b/cache/postgrescache/postgrescache.go index 722b2d3402b..9e602bf1226 100644 --- a/cache/postgrescache/postgrescache.go +++ b/cache/postgrescache/postgrescache.go @@ -5,6 +5,7 @@ import ( "database/sql" "encoding/gob" "fmt" + _ "github.com/lib/pq" "github.com/coocood/freecache" @@ -76,11 +77,8 @@ func newShared(conf PostgresConfig) (*shared, error) { // Cache postgres type Cache struct { - shared *shared - + shared *shared accounts *accountService - domains *domainService - apps *appsService config *configService } @@ -94,8 +92,6 @@ func New(cfg PostgresConfig) (*Cache, error) { return &Cache{ shared: shared, accounts: &accountService{shared: shared}, - domains: &domainService{shared: shared}, - apps: &appsService{shared: shared}, config: &configService{shared: shared}, }, nil } @@ -103,12 +99,6 @@ func New(cfg PostgresConfig) (*Cache, error) { func (c *Cache) Accounts() cache.AccountsService { return c.accounts } -func (c *Cache) Domains() cache.DomainsService { - return c.domains -} -func (c *Cache) Apps() cache.AppsService { - return c.apps -} func (c *Cache) Config() cache.ConfigService { return c.config } @@ -166,83 +156,6 @@ func (s *accountService) Set(account *cache.Account) error { return nil } -// DomainService handles the domain information -type domainService struct { - shared *shared -} - -// Set -func (s *domainService) Set(domain *cache.Domain) error { - return nil -} - -func (s *domainService) Get(key string) (*cache.Domain, error) { - var domain string - var d cache.Domain - - b, err := s.shared.lru.Get([]byte(key)) - if err == nil { - buf := bytes.NewReader(b) - if err = gob.NewDecoder(buf).Decode(&d); err != nil { - panic(err) - } - return &d, nil - } - - if err := s.shared.db.QueryRow("SELECT domain FROM domains_domain where domain = $1 LIMIT 1", key).Scan(&domain); err != nil { - /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ - return nil, err - } - - d.Domain = domain - - buf := bytes.Buffer{} - if err := gob.NewEncoder(&buf).Encode(&d); err != nil { - panic(err) - } - - s.shared.lru.Set([]byte(key), buf.Bytes(), s.shared.ttlSeconds) - return &d, nil -} - -// AppsService handles apps information -type appsService struct { - shared *shared -} - -func (s *appsService) Set(app *cache.App) error { - return nil -} - -func (s *appsService) Get(key string) (*cache.App, error) { - var bundle string - var app cache.App - - b, err := s.shared.lru.Get([]byte(key)) - if err == nil { - buf := bytes.NewReader(b) - if err = gob.NewDecoder(buf).Decode(&app); err != nil { - panic(err) - } - return &app, nil - } - - if err := s.shared.db.QueryRow("SELECT bundle FROM mobile_bundle where bundle = $1 LIMIT 1", key).Scan(&bundle); err != nil { - /* TODO -- We should store failed attempts in the LRU as well to stop from hitting to DB */ - return nil, err - } - - app.Bundle = bundle - - buf := bytes.Buffer{} - if err := gob.NewEncoder(&buf).Encode(&app); err != nil { - panic(err) - } - - s.shared.lru.Set([]byte(key), buf.Bytes(), s.shared.ttlSeconds) - return &app, nil -} - // ConfigService type configService struct { shared *shared diff --git a/cache/postgrescache/postgrescache_test.go b/cache/postgrescache/postgrescache_test.go index 0bfac79acbd..cc3d6cfc795 100644 --- a/cache/postgrescache/postgrescache_test.go +++ b/cache/postgrescache/postgrescache_test.go @@ -31,11 +31,8 @@ func TestPostgresConfig(t *testing.T) { } type StubCache struct { - shared *shared - + shared *shared accounts *accountService - domains *domainService - apps *appsService config *configService } @@ -45,8 +42,6 @@ func StubNew(cfg PostgresConfig) *Cache { return &Cache{ shared: shared, accounts: &accountService{shared: shared}, - domains: &domainService{shared: shared}, - apps: &appsService{shared: shared}, config: &configService{shared: shared}, } } From f17e4720fae65d7be659d5ff679dc7b49976fe0e Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:11 -0400 Subject: [PATCH 11/18] Revert "Now with the family package removed and constants actually added" This reverts commit 2a27acf48584926dc9237011e344958713bbb5c1. --- constants/constants.go => family/family.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename constants/constants.go => family/family.go (59%) diff --git a/constants/constants.go b/family/family.go similarity index 59% rename from constants/constants.go rename to family/family.go index 7d0cf55834a..323d753dfff 100644 --- a/constants/constants.go +++ b/family/family.go @@ -1,15 +1,15 @@ -package constants +package family // Family Name type to verify and centralize FamilyName usage -type FamilyName int +type Name int const ( - FNAppnexus FamilyName = iota - FNFacebook - FNIndex - FNPubmatic - FNPulsepoint - FNRubicon + Appnexus Name = iota + Facebook + Index + Pubmatic + Pulsepoint + Rubicon ) var validFamilyNames = [...]string{ @@ -21,6 +21,6 @@ var validFamilyNames = [...]string{ "rubicon", } -func (n FamilyName) String() string { +func (n Name) String() string { return validFamilyNames[int(n)] } From 47a6377e09b25c6a8ed1738b5834ae402ddfd4e7 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:31 -0400 Subject: [PATCH 12/18] Revert "Move family -> constants" This reverts commit dfaaf0ec538ca28040cb87f3b29441f570654667. --- adapters/adapter.go | 4 ++-- adapters/appnexus.go | 6 +++--- adapters/facebook.go | 6 +++--- adapters/index.go | 6 +++--- adapters/openrtb_util.go | 8 ++++---- adapters/openrtb_util_test.go | 6 +++--- adapters/pubmatic.go | 6 +++--- adapters/pulsepoint.go | 6 +++--- adapters/rubicon.go | 6 +++--- pbs/pbsrequest.go | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/adapters/adapter.go b/adapters/adapter.go index b68cc473bb6..b6f1146bed7 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -3,7 +3,7 @@ package adapters import ( "context" "crypto/tls" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "github.com/prebid/prebid-server/ssl" "net/http" @@ -18,7 +18,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() constants.FamilyName + FamilyName() family.Name // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index b0c602da538..c1c84ce4464 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -16,7 +16,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" ) type AppNexusAdapter struct { @@ -31,8 +31,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() constants.FamilyName { - return constants.FNAppnexus +func (a *AppNexusAdapter) FamilyName() family.Name { + return family.Appnexus } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index 6cfc27a8343..d7f780708ff 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -29,8 +29,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() constants.FamilyName { - return constants.FNFacebook +func (a *FacebookAdapter) FamilyName() family.Name { + return family.Facebook } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 331f580d345..9f662734b64 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -15,7 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" ) type IndexAdapter struct { @@ -30,8 +30,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() constants.FamilyName { - return constants.FNIndex +func (a *IndexAdapter) FamilyName() family.Name { + return family.Index } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index c87a7608c84..7bf233030e7 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -4,10 +4,10 @@ import ( "github.com/prebid/prebid-server/pbs" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily constants.FamilyName) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily family.Name) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -51,9 +51,9 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily Page: req.Url, }, Device: req.Device, - User: &openrtb.User{ + User: &openrtb.User{ // Make the family name conversion to string here. BuyerUID: req.GetUserID(bidderFamily), - ID: req.GetUserID(constants.FNAppnexus), + ID: req.GetUserID(family.Appnexus), }, Source: &openrtb.Source{ FD: 1, // upstream, aka header diff --git a/adapters/openrtb_util_test.go b/adapters/openrtb_util_test.go index 63055579dfd..649f6d4326b 100644 --- a/adapters/openrtb_util_test.go +++ b/adapters/openrtb_util_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" ) func TestOpenRTB(t *testing.T) { @@ -27,7 +27,7 @@ func TestOpenRTB(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, constants.FNRubicon) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Rubicon) assert.Equal(t, resp.Imp[0].ID, "unitCode") assert.EqualValues(t, resp.Imp[0].Banner.W, 10) @@ -45,6 +45,6 @@ func TestOpenRTBNoSize(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, constants.FNIndex) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Index) assert.Equal(t, resp.Imp[0].ID, "") } diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index c25eebc9887..f7ae58c28d0 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -11,7 +11,7 @@ import ( "net/url" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -28,8 +28,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() constants.FamilyName { - return constants.FNPubmatic +func (a *PubmaticAdapter) FamilyName() family.Name { + return family.Pubmatic } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index d72373e4bdf..0eaf3d028d3 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -13,7 +13,7 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -30,8 +30,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() constants.FamilyName { - return constants.FNPulsepoint +func (a *PulsePointAdapter) FamilyName() family.Name { + return family.Pulsepoint } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 0653054f979..8b344a15996 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -15,7 +15,7 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" ) type RubiconAdapter struct { @@ -32,8 +32,8 @@ func (a *RubiconAdapter) Name() string { } // used for cookies and such -func (a *RubiconAdapter) FamilyName() constants.FamilyName { - return constants.FNRubicon +func (a *RubiconAdapter) FamilyName() family.Name { + return family.Rubicon } func (a *RubiconAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index b105f9b22eb..d544f95f649 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -15,7 +15,7 @@ import ( "github.com/prebid/openrtb" "github.com/prebid/prebid-server/cache" - "github.com/prebid/prebid-server/constants" + "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/prebid" ) @@ -230,7 +230,7 @@ func (req PBSRequest) Elapsed() int { return int(time.Since(req.Start) / 1000000) } -func (req PBSRequest) GetUserID(BidderCode constants.FamilyName) string { +func (req PBSRequest) GetUserID(BidderCode family.Name) string { if uid, ok := req.UserIDs[BidderCode.String()]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. return uid } From 5446c3f141138ccabb88738e977ee3d70792dcf9 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:36 -0400 Subject: [PATCH 13/18] Revert "Now passes ./validate.sh" This reverts commit 29c5bb699a557c4ca676a327c7ff6ae3c5e68ca0. --- adapters/pulsepoint_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/pulsepoint_test.go b/adapters/pulsepoint_test.go index 8fb73a8537b..2ad6c30eb27 100644 --- a/adapters/pulsepoint_test.go +++ b/adapters/pulsepoint_test.go @@ -30,7 +30,7 @@ type PulsePointOrtbMockService struct { func TestPulsePointAdapterNames(t *testing.T) { adapter := NewPulsePointAdapter(DefaultHTTPAdapterConfig, "http://localhost/bid", "http://localhost") VerifyStringValue(adapter.Name(), "pulsepoint", t) - VerifyStringValue(adapter.FamilyName().String(), "pulsepoint", t) + VerifyStringValue(string(adapter.FamilyName()), "pulsepoint", t) } /** From 1fcf56c7309e33c5540edb45717619f9a1ad1a17 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:38 -0400 Subject: [PATCH 14/18] Revert "Initial bugfixes (missed file)" This reverts commit 12664b3aa0dc62cb3c99fd50167c5b0a0c2e6c46. --- pbs/pbsrequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index d544f95f649..d5bd6c93bf2 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -231,7 +231,7 @@ func (req PBSRequest) Elapsed() int { } func (req PBSRequest) GetUserID(BidderCode family.Name) string { - if uid, ok := req.UserIDs[BidderCode.String()]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. + if uid, ok := req.UserIDs[string(BidderCode)]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. return uid } return "" From 2d1a4b8f92a3b22162cc72ece5623b25c1a0ca29 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:39 -0400 Subject: [PATCH 15/18] Revert "Initial bugfixes" This reverts commit 6ab5fc5ec4cd9c08e1b04c934b2b8a868746211d. --- pbs_light.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbs_light.go b/pbs_light.go index 9f6fe771f66..74fd6b69887 100644 --- a/pbs_light.go +++ b/pbs_light.go @@ -188,7 +188,7 @@ func cookieSync(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { for _, bidder := range csReq.Bidders { if ex, ok := exchanges[bidder]; ok { - if _, ok := cookies.UIDs[ex.FamilyName().String()]; !ok { + if _, ok := cookies.UIDs[string(ex.FamilyName())]; !ok { b := pbs.PBSBidder{ BidderCode: bidder, NoCookie: true, From 5720bb578610be819c1a8f08b4ef4332aa0fa40c Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:40 -0400 Subject: [PATCH 16/18] Revert "Test fixing round one" This reverts commit b8e7bdeedc3c3cb5b6f678a1509dd20f91d8b445. --- adapters/openrtb_util_test.go | 5 ++--- adapters/pulsepoint_test.go | 2 +- pbs_light.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/adapters/openrtb_util_test.go b/adapters/openrtb_util_test.go index 649f6d4326b..6054d0750cc 100644 --- a/adapters/openrtb_util_test.go +++ b/adapters/openrtb_util_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" ) func TestOpenRTB(t *testing.T) { @@ -27,7 +26,7 @@ func TestOpenRTB(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Rubicon) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, "test") assert.Equal(t, resp.Imp[0].ID, "unitCode") assert.EqualValues(t, resp.Imp[0].Banner.W, 10) @@ -45,6 +44,6 @@ func TestOpenRTBNoSize(t *testing.T) { }, }, } - resp := makeOpenRTBGeneric(&pbReq, &pbBidder, family.Index) + resp := makeOpenRTBGeneric(&pbReq, &pbBidder, "test") assert.Equal(t, resp.Imp[0].ID, "") } diff --git a/adapters/pulsepoint_test.go b/adapters/pulsepoint_test.go index 2ad6c30eb27..ff27c6dad97 100644 --- a/adapters/pulsepoint_test.go +++ b/adapters/pulsepoint_test.go @@ -30,7 +30,7 @@ type PulsePointOrtbMockService struct { func TestPulsePointAdapterNames(t *testing.T) { adapter := NewPulsePointAdapter(DefaultHTTPAdapterConfig, "http://localhost/bid", "http://localhost") VerifyStringValue(adapter.Name(), "pulsepoint", t) - VerifyStringValue(string(adapter.FamilyName()), "pulsepoint", t) + VerifyStringValue(adapter.FamilyName(), "pulsepoint", t) } /** diff --git a/pbs_light.go b/pbs_light.go index 74fd6b69887..62f41635252 100644 --- a/pbs_light.go +++ b/pbs_light.go @@ -188,7 +188,7 @@ func cookieSync(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { for _, bidder := range csReq.Bidders { if ex, ok := exchanges[bidder]; ok { - if _, ok := cookies.UIDs[string(ex.FamilyName())]; !ok { + if _, ok := cookies.UIDs[ex.FamilyName()]; !ok { b := pbs.PBSBidder{ BidderCode: bidder, NoCookie: true, From 7dbda4f2d89202d1a2cad25c445331dabae6dd06 Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:41 -0400 Subject: [PATCH 17/18] Revert "Define a family.Name type for strict checking on valid family names, and moved declaration to its own package to avoid circular dependencies. Need to fix tests still" This reverts commit b6eb1f27304ec66c2d1da87caeea67306355a0e9. --- adapters/adapter.go | 28 ++++++++++++++++++++++++++-- adapters/appnexus.go | 5 ++--- adapters/facebook.go | 5 ++--- adapters/index.go | 5 ++--- adapters/openrtb_util.go | 7 +++---- adapters/pubmatic.go | 7 +++---- adapters/pulsepoint.go | 5 ++--- adapters/rubicon.go | 7 +++---- family/family.go | 26 -------------------------- pbs/pbsrequest.go | 5 ++--- 10 files changed, 45 insertions(+), 55 deletions(-) delete mode 100644 family/family.go diff --git a/adapters/adapter.go b/adapters/adapter.go index b6f1146bed7..f6364fd2d7c 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -3,13 +3,37 @@ package adapters import ( "context" "crypto/tls" - "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "github.com/prebid/prebid-server/ssl" "net/http" "time" ) +// FamilyName type to verify and centralize FamilyName usage +type FamilyName int + +const ( + FNappnexus FamilyName = iota + FNfacebook + FNindex + FNpubmatic + FNpulsepoint + FNrubicon +) + +var validFamilyNames = [...]string{ + "adnxs", + "audienceNetwork", + "indexExchange", + "pubmatic", + "pulsepoint", + "rubicon", +} + +func (n FamilyName) String() string { + return validFamilyNames[int(n)] +} + // Adapters connect prebid-server to a demand partner. Their primary purpose is to produce bids // in response to Auction requests. type Adapter interface { @@ -18,7 +42,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() family.Name + FamilyName() FamilyName // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index c1c84ce4464..961c71dbaaf 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -16,7 +16,6 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" ) type AppNexusAdapter struct { @@ -31,8 +30,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() family.Name { - return family.Appnexus +func (a *AppNexusAdapter) FamilyName() FamilyName { + return FNappnexus } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index d7f780708ff..965bfcf928f 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -29,8 +28,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() family.Name { - return family.Facebook +func (a *FacebookAdapter) FamilyName() FamilyName { + return FNfacebook } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 9f662734b64..2a138171a47 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -15,7 +15,6 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" ) type IndexAdapter struct { @@ -30,8 +29,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() family.Name { - return family.Index +func (a *IndexAdapter) FamilyName() FamilyName { + return FNindex } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index 7bf233030e7..15f43528284 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -4,10 +4,9 @@ import ( "github.com/prebid/prebid-server/pbs" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily family.Name) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily FamilyName) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -52,8 +51,8 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily }, Device: req.Device, User: &openrtb.User{ // Make the family name conversion to string here. - BuyerUID: req.GetUserID(bidderFamily), - ID: req.GetUserID(family.Appnexus), + BuyerUID: req.GetUserID(string(bidderFamily)), + ID: req.GetUserID("adnxs"), }, Source: &openrtb.Source{ FD: 1, // upstream, aka header diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index f7ae58c28d0..42b048891b4 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -11,7 +11,6 @@ import ( "net/url" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -28,8 +27,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() family.Name { - return family.Pubmatic +func (a *PubmaticAdapter) FamilyName() FamilyName { + return FNpubmatic } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -85,7 +84,7 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder httpReq.Header.Add("Accept", "application/json") httpReq.AddCookie(&http.Cookie{ Name: "KADUSERCOOKIE", - Value: req.GetUserID(a.FamilyName()), + Value: req.GetUserID(string(a.FamilyName())), }) pbResp, err := ctxhttp.Do(ctx, a.http.Client, httpReq) diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index 0eaf3d028d3..dfdd1580615 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -13,7 +13,6 @@ import ( "strings" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -30,8 +29,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() family.Name { - return family.Pulsepoint +func (a *PulsePointAdapter) FamilyName() FamilyName { + return FNpulsepoint } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 8b344a15996..943bac5d883 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -15,7 +15,6 @@ import ( "golang.org/x/net/context/ctxhttp" "github.com/prebid/openrtb" - "github.com/prebid/prebid-server/family" ) type RubiconAdapter struct { @@ -32,8 +31,8 @@ func (a *RubiconAdapter) Name() string { } // used for cookies and such -func (a *RubiconAdapter) FamilyName() family.Name { - return family.Rubicon +func (a *RubiconAdapter) FamilyName() string { + return "rubicon" } func (a *RubiconAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -217,7 +216,7 @@ func (a *RubiconAdapter) callOne(ctx context.Context, req *pbs.PBSRequest, reqJS func (a *RubiconAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) { requests := make([]bytes.Buffer, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { - rubiReq := makeOpenRTBGeneric(req, bidder, a.FamilyName()) + rubiReq := makeOpenRTBGeneric(req, bidder, string(a.FamilyName())) // only grab this ad unit rubiReq.Imp = rubiReq.Imp[i : i+1] diff --git a/family/family.go b/family/family.go deleted file mode 100644 index 323d753dfff..00000000000 --- a/family/family.go +++ /dev/null @@ -1,26 +0,0 @@ -package family - -// Family Name type to verify and centralize FamilyName usage -type Name int - -const ( - Appnexus Name = iota - Facebook - Index - Pubmatic - Pulsepoint - Rubicon -) - -var validFamilyNames = [...]string{ - "adnxs", - "audienceNetwork", - "indexExchange", - "pubmatic", - "pulsepoint", - "rubicon", -} - -func (n Name) String() string { - return validFamilyNames[int(n)] -} diff --git a/pbs/pbsrequest.go b/pbs/pbsrequest.go index d5bd6c93bf2..449d3dd7b7b 100644 --- a/pbs/pbsrequest.go +++ b/pbs/pbsrequest.go @@ -15,7 +15,6 @@ import ( "github.com/prebid/openrtb" "github.com/prebid/prebid-server/cache" - "github.com/prebid/prebid-server/family" "github.com/prebid/prebid-server/prebid" ) @@ -230,8 +229,8 @@ func (req PBSRequest) Elapsed() int { return int(time.Since(req.Start) / 1000000) } -func (req PBSRequest) GetUserID(BidderCode family.Name) string { - if uid, ok := req.UserIDs[string(BidderCode)]; ok { // TODO: consider moving UserIDs to an array indexed by the FamilyName int. +func (req PBSRequest) GetUserID(BidderCode string) string { + if uid, ok := req.UserIDs[BidderCode]; ok { return uid } return "" From 10fbc26c98e6d486e80eb64b16ee48acce1f0bed Mon Sep 17 00:00:00 2001 From: Hans Hjort Date: Tue, 26 Sep 2017 09:40:42 -0400 Subject: [PATCH 18/18] Revert "Adding a dedicated FamilyName type within adapters" This reverts commit 7792d7cab2a6c1bf900d323f00433749bba61836. --- adapters/adapter.go | 27 +-------------------------- adapters/appnexus.go | 4 ++-- adapters/facebook.go | 4 ++-- adapters/index.go | 4 ++-- adapters/openrtb_util.go | 6 +++--- adapters/pubmatic.go | 6 +++--- adapters/pulsepoint.go | 4 ++-- adapters/rubicon.go | 2 +- 8 files changed, 16 insertions(+), 41 deletions(-) diff --git a/adapters/adapter.go b/adapters/adapter.go index f6364fd2d7c..03a9585a9ad 100644 --- a/adapters/adapter.go +++ b/adapters/adapter.go @@ -9,31 +9,6 @@ import ( "time" ) -// FamilyName type to verify and centralize FamilyName usage -type FamilyName int - -const ( - FNappnexus FamilyName = iota - FNfacebook - FNindex - FNpubmatic - FNpulsepoint - FNrubicon -) - -var validFamilyNames = [...]string{ - "adnxs", - "audienceNetwork", - "indexExchange", - "pubmatic", - "pulsepoint", - "rubicon", -} - -func (n FamilyName) String() string { - return validFamilyNames[int(n)] -} - // Adapters connect prebid-server to a demand partner. Their primary purpose is to produce bids // in response to Auction requests. type Adapter interface { @@ -42,7 +17,7 @@ type Adapter interface { Name() string // FamilyName identifies the space of cookies which this adapter accesses. For example, an adapter // using the adnxs.com cookie space should return "adnxs". - FamilyName() FamilyName + FamilyName() string // Determines whether this adapter should get callouts if there is not a synched user ID SkipNoCookies() bool // GetUsersyncInfo returns the parameters which are needed to do sync users with this bidder. diff --git a/adapters/appnexus.go b/adapters/appnexus.go index 961c71dbaaf..a4f29cbec40 100644 --- a/adapters/appnexus.go +++ b/adapters/appnexus.go @@ -30,8 +30,8 @@ func (a *AppNexusAdapter) Name() string { } // used for cookies and such -func (a *AppNexusAdapter) FamilyName() FamilyName { - return FNappnexus +func (a *AppNexusAdapter) FamilyName() string { + return "adnxs" } func (a *AppNexusAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/facebook.go b/adapters/facebook.go index 965bfcf928f..b3de45f32ff 100644 --- a/adapters/facebook.go +++ b/adapters/facebook.go @@ -28,8 +28,8 @@ func (a *FacebookAdapter) Name() string { } // used for cookies and such -func (a *FacebookAdapter) FamilyName() FamilyName { - return FNfacebook +func (a *FacebookAdapter) FamilyName() string { + return "audienceNetwork" } // Facebook likes to parallelize to minimize latency diff --git a/adapters/index.go b/adapters/index.go index 2a138171a47..669d4ab0201 100644 --- a/adapters/index.go +++ b/adapters/index.go @@ -29,8 +29,8 @@ func (a *IndexAdapter) Name() string { } // used for cookies and such -func (a *IndexAdapter) FamilyName() FamilyName { - return FNindex +func (a *IndexAdapter) FamilyName() string { + return "indexExchange" } func (a *IndexAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/openrtb_util.go b/adapters/openrtb_util.go index 15f43528284..2b5dea9db16 100644 --- a/adapters/openrtb_util.go +++ b/adapters/openrtb_util.go @@ -6,7 +6,7 @@ import ( "github.com/prebid/openrtb" ) -func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily FamilyName) openrtb.BidRequest { +func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily string) openrtb.BidRequest { imps := make([]openrtb.Imp, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { @@ -50,8 +50,8 @@ func makeOpenRTBGeneric(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bidderFamily Page: req.Url, }, Device: req.Device, - User: &openrtb.User{ // Make the family name conversion to string here. - BuyerUID: req.GetUserID(string(bidderFamily)), + User: &openrtb.User{ + BuyerUID: req.GetUserID(bidderFamily), ID: req.GetUserID("adnxs"), }, Source: &openrtb.Source{ diff --git a/adapters/pubmatic.go b/adapters/pubmatic.go index 42b048891b4..db2c742ffef 100644 --- a/adapters/pubmatic.go +++ b/adapters/pubmatic.go @@ -27,8 +27,8 @@ func (a *PubmaticAdapter) Name() string { } // used for cookies and such -func (a *PubmaticAdapter) FamilyName() FamilyName { - return FNpubmatic +func (a *PubmaticAdapter) FamilyName() string { + return "pubmatic" } func (a *PubmaticAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { @@ -84,7 +84,7 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder httpReq.Header.Add("Accept", "application/json") httpReq.AddCookie(&http.Cookie{ Name: "KADUSERCOOKIE", - Value: req.GetUserID(string(a.FamilyName())), + Value: req.GetUserID(a.FamilyName()), }) pbResp, err := ctxhttp.Do(ctx, a.http.Client, httpReq) diff --git a/adapters/pulsepoint.go b/adapters/pulsepoint.go index dfdd1580615..1f6d6037745 100644 --- a/adapters/pulsepoint.go +++ b/adapters/pulsepoint.go @@ -29,8 +29,8 @@ func (a *PulsePointAdapter) Name() string { } // used for cookies and such -func (a *PulsePointAdapter) FamilyName() FamilyName { - return FNpulsepoint +func (a *PulsePointAdapter) FamilyName() string { + return "pulsepoint" } func (a *PulsePointAdapter) GetUsersyncInfo() *pbs.UsersyncInfo { diff --git a/adapters/rubicon.go b/adapters/rubicon.go index 943bac5d883..1163c97745b 100644 --- a/adapters/rubicon.go +++ b/adapters/rubicon.go @@ -216,7 +216,7 @@ func (a *RubiconAdapter) callOne(ctx context.Context, req *pbs.PBSRequest, reqJS func (a *RubiconAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) { requests := make([]bytes.Buffer, len(bidder.AdUnits)) for i, unit := range bidder.AdUnits { - rubiReq := makeOpenRTBGeneric(req, bidder, string(a.FamilyName())) + rubiReq := makeOpenRTBGeneric(req, bidder, a.FamilyName()) // only grab this ad unit rubiReq.Imp = rubiReq.Imp[i : i+1]