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

OTT-1704: Bidder Response mapping framework for ortb bidder #806

Merged
merged 53 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
afb67ce
OTT-1704: Framework to build bid reponse for ortb bidder
Pubmatic-Dhruv-Sonone Jun 3, 2024
f898a5f
Fixing import
Pubmatic-Dhruv-Sonone Jun 3, 2024
b825550
OTT-1704: Bidder response framework draf
Pubmatic-Dhruv-Sonone Jun 3, 2024
fa1a6e3
renamed file
Pubmatic-Dhruv-Sonone Jun 3, 2024
4443c51
Fixing getValueFromLocation function
Pubmatic-Dhruv-Sonone Jun 3, 2024
97233a0
Refactor param_mapper
Pubmatic-Dhruv-Sonone Jun 3, 2024
5914f8c
updating get value from location function
Pubmatic-Dhruv-Sonone Jun 5, 2024
4c2fefc
Refactoring
Pubmatic-Dhruv-Sonone Jun 6, 2024
f7271a5
Merge branch 'ci' into OTT-1704
Pubmatic-Dhruv-Sonone Jun 6, 2024
7d67600
Refactoring
Pubmatic-Dhruv-Sonone Jun 6, 2024
a548369
Fixing MType parser
Pubmatic-Dhruv-Sonone Jun 7, 2024
ef55702
Adding param resolver
Pubmatic-Dhruv-Sonone Jun 8, 2024
c1067b3
resolver draft
Pubmatic-Dhruv-Sonone Jun 10, 2024
6eeeb55
Adding util and resolver package
Pubmatic-Dhruv-Sonone Jun 10, 2024
c6f9d6c
Refactoring code
Pubmatic-Dhruv-Sonone Jun 10, 2024
abd4d63
Adding unit test for resolver package
Pubmatic-Dhruv-Sonone Jun 10, 2024
05ec1a7
Adding UT
Pubmatic-Dhruv-Sonone Jun 10, 2024
81a9ea8
Adding unit test
Pubmatic-Dhruv-Sonone Jun 11, 2024
4c3a265
removing commented code
Pubmatic-Dhruv-Sonone Jun 12, 2024
d29f544
Merging lastest ci and refactoring
Pubmatic-Dhruv-Sonone Jun 12, 2024
c302e97
Adding unit tests and code refactor
Pubmatic-Dhruv-Sonone Jun 12, 2024
8da86d4
Fixing unit test and refactorign
Pubmatic-Dhruv-Sonone Jun 12, 2024
d2e1b0a
Refactoring
Pubmatic-Dhruv-Sonone Jun 12, 2024
45c645c
Unit test refactor
Pubmatic-Dhruv-Sonone Jun 12, 2024
897e269
refactoring
Pubmatic-Dhruv-Sonone Jun 12, 2024
46cce13
Fix for media type resolver
Pubmatic-Dhruv-Sonone Jun 12, 2024
1e98f26
Adding unit tests
Pubmatic-Dhruv-Sonone Jun 12, 2024
181c65b
Updated bidder-response-params
Pubmatic-Dhruv-Sonone Jun 12, 2024
1e5ca05
Fixing UT
Pubmatic-Dhruv-Sonone Jun 12, 2024
7490e3b
Fixing UT
Pubmatic-Dhruv-Sonone Jun 12, 2024
9ad16e6
Fixing mtype resolver
Pubmatic-Dhruv-Sonone Jun 12, 2024
e5e1c31
Adding support mtype autodetection from adm
Pubmatic-Dhruv-Sonone Jun 12, 2024
6673671
MediaType auto detection resolver changes
Pubmatic-Dhruv-Sonone Jun 13, 2024
d4f0649
Refactoring
Pubmatic-Dhruv-Sonone Jun 13, 2024
63df904
Changing logic
Pubmatic-Dhruv-Sonone Jun 13, 2024
89c151c
Addresssing review comments
Pubmatic-Dhruv-Sonone Jun 13, 2024
1392b8b
Merging latest ci
Pubmatic-Dhruv-Sonone Jun 13, 2024
13bb68e
Fixing UT
Pubmatic-Dhruv-Sonone Jun 13, 2024
8e35081
Fixing test cases
Pubmatic-Dhruv-Sonone Jun 14, 2024
cea55c6
Addressing review comments
Pubmatic-Dhruv-Sonone Jun 14, 2024
d448245
Removing redundant code
Pubmatic-Dhruv-Sonone Jun 14, 2024
a42a9d2
Bidder validation fix
Pubmatic-Dhruv-Sonone Jun 14, 2024
534837c
fix bidder validate test
Pubmatic-Dhruv-Sonone Jun 14, 2024
d19bcd5
Fixing UT
Pubmatic-Dhruv-Sonone Jun 14, 2024
ea09724
Fixing UT
Pubmatic-Dhruv-Sonone Jun 14, 2024
7dbc3cc
moving constant
Pubmatic-Dhruv-Sonone Jun 14, 2024
0bb2f3f
Addressing review comments
Pubmatic-Dhruv-Sonone Jun 16, 2024
c2d28f5
Addressing review comments
Pubmatic-Dhruv-Sonone Jun 16, 2024
de38c94
Addressing review comments
Pubmatic-Dhruv-Sonone Jun 17, 2024
cfd9047
Fixing response param path
Pubmatic-Dhruv-Sonone Jun 17, 2024
58168e3
Fixing semgroup check
Pubmatic-Dhruv-Sonone Jun 17, 2024
583e23f
Test
Pubmatic-Dhruv-Sonone Jun 17, 2024
f931f65
test
Pubmatic-Dhruv-Sonone Jun 17, 2024
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
26 changes: 26 additions & 0 deletions adapters/ortbbidder/bidderparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ func (bcfg *BidderConfig) setRequestParams(bidderName string, requestParams map[
bcfg.bidderConfigMap[bidderName].requestParams = requestParams
}

// setResponseParams sets the bidder specific responseParams
func (bcfg *BidderConfig) setResponseParams(bidderName string, responseParams map[string]BidderParamMapper) {
if bcfg == nil {
return
}
if bcfg.bidderConfigMap == nil {
bcfg.bidderConfigMap = make(map[string]*config)
}
if _, found := bcfg.bidderConfigMap[bidderName]; !found {
bcfg.bidderConfigMap[bidderName] = &config{}
}
bcfg.bidderConfigMap[bidderName].responseParams = responseParams
}

// GetRequestParams returns bidder specific requestParams
func (bcfg *BidderConfig) GetRequestParams(bidderName string) (map[string]BidderParamMapper, bool) {
if bcfg == nil || len(bcfg.bidderConfigMap) == 0 {
Expand All @@ -52,3 +66,15 @@ func (bcfg *BidderConfig) GetRequestParams(bidderName string) (map[string]Bidder
}
return bidderConfig.requestParams, true
}

// GetResponseParams returns bidder specific responseParams
func (bcfg *BidderConfig) GetResponseParams(bidderName string) (map[string]BidderParamMapper, bool) {
if bcfg == nil || len(bcfg.bidderConfigMap) == 0 {
return nil, false
}
bidderConfig, _ := bcfg.bidderConfigMap[bidderName]
if bidderConfig == nil {
return nil, false
}
return bidderConfig.responseParams, true
}
104 changes: 87 additions & 17 deletions adapters/ortbbidder/bidderparams/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,101 @@ const (
)

// LoadBidderConfig creates a bidderConfig from JSON files specified in dirPath directory.
func LoadBidderConfig(dirPath string, isBidderAllowed func(string) bool) (*BidderConfig, error) {
files, err := os.ReadDir(dirPath)
// func LoadBidderConfig(requestParamsDirPath, responseParamsDirPath string, isBidderAllowed func(string) bool) (*BidderConfig, error) {
// bidderConfigMap := &BidderConfig{bidderConfigMap: make(map[string]*config)}
// files, err := os.ReadDir(requestParamsDirPath)
// if err != nil {
// return nil, fmt.Errorf("error:[%s] dirPath:[%s]", err.Error(), requestParamsDirPath)
// }

// for _, file := range files {
// bidderName, ok := strings.CutSuffix(file.Name(), ".json")
// if !ok {
// return nil, fmt.Errorf("error:[invalid_json_file_name] filename:[%s]", file.Name())
// }
// if !isBidderAllowed(bidderName) {
// continue
// }
// requestParamsConfig, err := readFile(requestParamsDirPath, file.Name())
// if err != nil {
// return nil, fmt.Errorf("error:[fail_to_read_file] dir:[%s] filename:[%s] err:[%s]", requestParamsDirPath, file.Name(), err.Error())
// }
// requestParams, err := prepareRequestParams(bidderName, requestParamsConfig)
// if err != nil {
// return nil, err
// }
// bidderConfigMap.setRequestParams(bidderName, requestParams)
// }

// files, err = os.ReadDir(responseParamsDirPath)
// if err != nil {
// return nil, fmt.Errorf("error:[%s] dirPath:[%s]", err.Error(), responseParamsDirPath)
// }
// for _, file := range files {
// bidderName, ok := strings.CutSuffix(file.Name(), ".json")
// if !ok {
// return nil, fmt.Errorf("error:[invalid_json_file_name] filename:[%s]", file.Name())
// }
// if !isBidderAllowed(bidderName) {
// continue
// }
// responseParamsConfig, err := readFile(responseParamsDirPath, file.Name())
// if err != nil {
// return nil, fmt.Errorf("error:[fail_to_read_file] dir:[%s] filename:[%s] err:[%s]", responseParamsDirPath, file.Name(), err.Error())
// }
// requestParams, err := prepareRequestParams(bidderName, responseParamsConfig)
// if err != nil {
// return nil, err
// }
// bidderConfigMap.setResponseParams(bidderName, requestParams)
// }

// return bidderConfigMap, nil
// }

// LoadBidderConfig creates a bidderConfig from JSON files specified in dirPath directory.
func LoadBidderConfig(requestParamsDirPath, responseParamsDirPath string, isBidderAllowed func(string) bool) (*BidderConfig, error) {
bidderConfigMap := &BidderConfig{bidderConfigMap: make(map[string]*config)}

err := processParams(requestParamsDirPath, bidderConfigMap.setRequestParams, isBidderAllowed)
if err != nil {
return nil, fmt.Errorf("error:[%s] dirPath:[%s]", err.Error(), dirPath)
return nil, err
}
bidderConfigMap := &BidderConfig{bidderConfigMap: make(map[string]*config)}

err = processParams(responseParamsDirPath, bidderConfigMap.setResponseParams, isBidderAllowed)
if err != nil {
return nil, err
}

return bidderConfigMap, nil
}

func processParams(paramsDirPath string, setParams func(string, map[string]BidderParamMapper), isBidderAllowed func(string) bool) error {
files, err := os.ReadDir(paramsDirPath)
if err != nil {
return fmt.Errorf("error:[%s] dirPath:[%s]", err.Error(), paramsDirPath)
}

for _, file := range files {
bidderName, ok := strings.CutSuffix(file.Name(), ".json")
if !ok {
return nil, fmt.Errorf("error:[invalid_json_file_name] filename:[%s]", file.Name())
return fmt.Errorf("error:[invalid_json_file_name] filename:[%s]", file.Name())
}
if !isBidderAllowed(bidderName) {
continue
}
requestParamsConfig, err := readFile(dirPath, file.Name())
paramsConfig, err := readFile(paramsDirPath, file.Name())
if err != nil {
return nil, fmt.Errorf("error:[fail_to_read_file] dir:[%s] filename:[%s] err:[%s]", dirPath, file.Name(), err.Error())
return fmt.Errorf("error:[fail_to_read_file] dir:[%s] filename:[%s] err:[%s]", paramsDirPath, file.Name(), err.Error())
}
requestParams, err := prepareRequestParams(bidderName, requestParamsConfig)
params, err := prepareParams(bidderName, paramsConfig)
if err != nil {
return nil, err
return err
}
bidderConfigMap.setRequestParams(bidderName, requestParams)
setParams(bidderName, params)
}
return bidderConfigMap, nil

return nil
}

// readFile reads the file from directory and unmarshals it into the map[string]any
Expand All @@ -53,17 +123,17 @@ func readFile(dirPath, file string) (map[string]any, error) {
return contentMap, err
}

// prepareRequestParams parse the requestParamsConfig and returns the requestParams
func prepareRequestParams(bidderName string, requestParamsConfig map[string]any) (map[string]BidderParamMapper, error) {
params, found := requestParamsConfig[propertiesKey]
// prepareParams parse the requestParamsConfig and returns the requestParams
func prepareParams(bidderName string, paramsConfig map[string]any) (map[string]BidderParamMapper, error) {
params, found := paramsConfig[propertiesKey]
if !found {
return nil, nil
}
paramsMap, ok := params.(map[string]any)
if !ok {
return nil, fmt.Errorf("error:[invalid_json_file_content_malformed_properties] bidderName:[%s]", bidderName)
}
requestParams := make(map[string]BidderParamMapper, len(paramsMap))
paramsCfg := make(map[string]BidderParamMapper, len(paramsMap))
for paramName, paramValue := range paramsMap {
paramValueMap, ok := paramValue.(map[string]any)
if !ok {
Expand All @@ -77,9 +147,9 @@ func prepareRequestParams(bidderName string, requestParamsConfig map[string]any)
if !ok {
return nil, fmt.Errorf("error:[incorrect_location_in_bidderparam] bidder:[%s] bidderParam:[%s]", bidderName, paramName)
}
requestParams[paramName] = BidderParamMapper{
paramsCfg[paramName] = BidderParamMapper{
location: strings.Split(locationStr, "."),
}
}
return requestParams, nil
return paramsCfg, nil
}
Loading
Loading