github.com/prebid/prebid-server/v2@v2.18.0/openrtb_ext/convert_up.go (about) 1 package openrtb_ext 2 3 import ( 4 "fmt" 5 6 "github.com/prebid/openrtb/v20/openrtb2" 7 ) 8 9 func ConvertUpTo26(r *RequestWrapper) error { 10 if err := convertUpEnsureExt(r); err != nil { 11 return err 12 } 13 14 // schain 15 moveSupplyChainFrom24To25(r) 16 moveSupplyChainFrom25To26(r) 17 18 // gdpr 19 moveGDPRFrom25To26(r) 20 moveConsentFrom25To26(r) 21 22 // ccpa 23 moveUSPrivacyFrom25To26(r) 24 25 // eid 26 moveEIDFrom25To26(r) 27 28 // imp 29 for _, imp := range r.GetImp() { 30 moveRewardedFromPrebidExtTo26(imp) 31 } 32 33 return nil 34 } 35 36 // convertUpEnsureExt gets all extension objects required for migration to verify there 37 // are no access errors. 38 func convertUpEnsureExt(r *RequestWrapper) error { 39 if _, err := r.GetRequestExt(); err != nil { 40 return fmt.Errorf("req.ext is invalid: %v", err) 41 } 42 43 if _, err := r.GetSourceExt(); err != nil { 44 return fmt.Errorf("req.source.ext is invalid: %v", err) 45 } 46 47 if _, err := r.GetRegExt(); err != nil { 48 return fmt.Errorf("req.regs.ext is invalid: %v", err) 49 } 50 51 if _, err := r.GetUserExt(); err != nil { 52 return fmt.Errorf("req.user.ext is invalid: %v", err) 53 } 54 55 for i, imp := range r.GetImp() { 56 if _, err := imp.GetImpExt(); err != nil { 57 return fmt.Errorf("imp[%v].imp.ext is invalid: %v", i, err) 58 } 59 } 60 61 return nil 62 } 63 64 // moveSupplyChainFrom24To25 modifies the request to move the OpenRTB 2.4 supply chain 65 // object (req.ext.schain) to the OpenRTB 2.5 location (req.source.ext.schain). If the 66 // OpenRTB 2.5 location is already present the OpenRTB 2.4 supply chain object is dropped. 67 func moveSupplyChainFrom24To25(r *RequestWrapper) { 68 // read and clear 2.4 location 69 reqExt, _ := r.GetRequestExt() 70 schain24 := reqExt.GetSChain() 71 reqExt.SetSChain(nil) 72 73 // move to 2.5 location if not already present 74 sourceExt, _ := r.GetSourceExt() 75 if sourceExt.GetSChain() == nil { 76 sourceExt.SetSChain(schain24) 77 } 78 } 79 80 // moveSupplyChainFrom25To26 modifies the request to move the OpenRTB 2.5 supply chain 81 // object (req.source.ext.schain) to the OpenRTB 2.6 location (req.source.schain). If the 82 // OpenRTB 2.6 location is already present the OpenRTB 2.5 supply chain object is dropped. 83 func moveSupplyChainFrom25To26(r *RequestWrapper) { 84 // read and clear 2.5 location 85 sourceExt, _ := r.GetSourceExt() 86 schain25 := sourceExt.GetSChain() 87 sourceExt.SetSChain(nil) 88 89 // move to 2.6 location if not already present 90 if schain25 != nil { 91 // source may be nil if moved indirectly from an OpenRTB 2.4 location, since the ext 92 // is not defined on the source object. 93 if r.Source == nil { 94 r.Source = &openrtb2.Source{} 95 } 96 97 if r.Source.SChain == nil { 98 r.Source.SChain = schain25 99 } 100 } 101 } 102 103 // moveGDPRFrom25To26 modifies the request to move the OpenRTB 2.5 GDPR signal field 104 // (req.regs.ext.gdpr) to the OpenRTB 2.6 location (req.regs.gdpr). If the OpenRTB 2.6 105 // location is already present the OpenRTB 2.5 GDPR signal is dropped. 106 func moveGDPRFrom25To26(r *RequestWrapper) { 107 // read and clear 2.5 location 108 regsExt, _ := r.GetRegExt() 109 gdpr25 := regsExt.GetGDPR() 110 regsExt.SetGDPR(nil) 111 112 // move to 2.6 location 113 if gdpr25 != nil && r.Regs.GDPR == nil { 114 r.Regs.GDPR = gdpr25 115 } 116 } 117 118 // moveConsentFrom25To26 modifies the request to move the OpenRTB 2.5 GDPR consent field 119 // (req.user.ext.consent) to the OpenRTB 2.6 location (req.user.consent). If the OpenRTB 2.6 120 // location is already present the OpenRTB 2.5 GDPR consent is dropped. 121 func moveConsentFrom25To26(r *RequestWrapper) { 122 // read and clear 2.5 location 123 userExt, _ := r.GetUserExt() 124 consent25 := userExt.GetConsent() 125 userExt.SetConsent(nil) 126 127 // move to 2.6 location 128 if consent25 != nil && r.User.Consent == "" { 129 r.User.Consent = *consent25 130 } 131 } 132 133 // moveUSPrivacyFrom25To26 modifies the request to move the OpenRTB 2.5 US Privacy (CCPA) 134 // consent string (req.regs.ext.usprivacy) to the OpenRTB 2.6 location (req.regs.usprivacy). 135 // If the OpenRTB 2.6 location is already present the OpenRTB 2.5 consent string is dropped. 136 func moveUSPrivacyFrom25To26(r *RequestWrapper) { 137 // read and clear 2.5 location 138 regsExt, _ := r.GetRegExt() 139 usPrivacy25 := regsExt.GetUSPrivacy() 140 regsExt.SetUSPrivacy("") 141 142 // move to 2.6 location 143 if usPrivacy25 != "" && r.Regs.USPrivacy == "" { 144 r.Regs.USPrivacy = usPrivacy25 145 } 146 } 147 148 // moveEIDFrom25To26 modifies the request to move the OpenRTB 2.5 external identifiers 149 // (req.user.ext.eids) to the OpenRTB 2.6 location (req.user.eids). If the OpenRTB 2.6 150 // location is already present the OpenRTB 2.5 external identifiers is dropped. 151 func moveEIDFrom25To26(r *RequestWrapper) { 152 // read and clear 2.5 location 153 userExt, _ := r.GetUserExt() 154 eid25 := userExt.GetEid() 155 userExt.SetEid(nil) 156 157 // move to 2.6 location 158 if eid25 != nil && r.User.EIDs == nil { 159 r.User.EIDs = *eid25 160 } 161 } 162 163 // moveRewardedFromPrebidExtTo26 modifies the impression to move the Prebid specific 164 // rewarded video signal (imp[].ext.prebid.is_rewarded_inventory) to the OpenRTB 2.6 165 // location (imp[].rwdd). If the OpenRTB 2.6 location is already present the Prebid 166 // specific extension is dropped. 167 func moveRewardedFromPrebidExtTo26(i *ImpWrapper) { 168 // read and clear prebid ext 169 impExt, _ := i.GetImpExt() 170 rwddPrebidExt := (*int8)(nil) 171 if p := impExt.GetPrebid(); p != nil { 172 rwddPrebidExt = p.IsRewardedInventory 173 p.IsRewardedInventory = nil 174 impExt.SetPrebid(p) 175 } 176 177 // move to 2.6 location 178 if rwddPrebidExt != nil && i.Rwdd == 0 { 179 i.Rwdd = *rwddPrebidExt 180 } 181 }