github.com/prebid/prebid-server/v2@v2.18.0/privacy/ccpa/consentwriter.go (about)

     1  package ccpa
     2  
     3  import (
     4  	"github.com/prebid/openrtb/v20/openrtb2"
     5  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     6  )
     7  
     8  // ConsentWriter implements the old PolicyWriter interface for CCPA.
     9  // This is used where we have not converted to RequestWrapper yet
    10  type ConsentWriter struct {
    11  	Consent string
    12  }
    13  
    14  // Write mutates an OpenRTB bid request with the CCPA consent string.
    15  func (c ConsentWriter) Write(req *openrtb2.BidRequest) error {
    16  	if req == nil {
    17  		return nil
    18  	}
    19  	reqWrap := &openrtb_ext.RequestWrapper{BidRequest: req}
    20  
    21  	// Set consent string in USPrivacy
    22  	if c.Consent != "" {
    23  		if regsExt, err := reqWrap.GetRegExt(); err == nil {
    24  			regsExt.SetUSPrivacy(c.Consent)
    25  		} else {
    26  			return err
    27  		}
    28  	}
    29  
    30  	return reqWrap.RebuildRequest()
    31  }