github.com/prebid/prebid-server/v2@v2.18.0/dsa/writer.go (about)

     1  package dsa
     2  
     3  import (
     4  	"github.com/prebid/prebid-server/v2/config"
     5  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     6  )
     7  
     8  // Writer is used to write the default DSA to the request (req.regs.ext.dsa)
     9  type Writer struct {
    10  	Config      *config.AccountDSA
    11  	GDPRInScope bool
    12  }
    13  
    14  // Write sets the default DSA object on the request at regs.ext.dsa if it is
    15  // defined in the account config and it is not already present on the request
    16  func (dw Writer) Write(req *openrtb_ext.RequestWrapper) error {
    17  	if req == nil || getReqDSA(req) != nil {
    18  		return nil
    19  	}
    20  	if dw.Config == nil || dw.Config.DefaultUnpacked == nil {
    21  		return nil
    22  	}
    23  	if dw.Config.GDPROnly && !dw.GDPRInScope {
    24  		return nil
    25  	}
    26  	regExt, err := req.GetRegExt()
    27  	if err != nil {
    28  		return err
    29  	}
    30  	clonedDefaultUnpacked := dw.Config.DefaultUnpacked.Clone()
    31  	regExt.SetDSA(clonedDefaultUnpacked)
    32  	return nil
    33  }