github.com/prebid/prebid-server/v2@v2.18.0/.semgrep/adapter/bid-type-if-check.go (about)

     1  /*
     2  	bid-type-if-check tests
     3  	https://semgrep.dev/docs/writing-rules/testing-rules
     4  	"ruleid" prefix in comment indicates patterns that should be flagged by semgrep
     5  	"ok" prefix in comment indidcates  patterns that should not be flagged by the semgrep
     6  */
     7  
     8  func getMediaTypeForImp(impID string, imps []openrtb2.Imp) openrtb_ext.BidType {
     9  	for _, imp := range imps {
    10  		if imp.ID == impID {
    11  			// ruleid: bid-type-if-check
    12  			if imp.Banner != nil {
    13  				return openrtb_ext.BidTypeBanner, nil
    14  				// ruleid: bid-type-if-check
    15  			} else if imp.Video != nil {
    16  				return openrtb_ext.BidTypeVideo, nil
    17  				// ruleid: bid-type-if-check
    18  			} else if imp.Native != nil {
    19  				return openrtb_ext.BidTypeNative, nil
    20  				// ruleid: bid-type-if-check
    21  			} else if imp.Audio != nil {
    22  				return openrtb_ext.BidTypeAudio, nil
    23  			}
    24  		}
    25  	}
    26  	return openrtb_ext.BidTypeBanner
    27  }
    28  
    29  func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
    30  	for _, imp := range imps {
    31  		if imp.ID == impID {
    32  			// ruleid: bid-type-if-check
    33  			if imp.Banner != nil {
    34  				return openrtb_ext.BidTypeBanner, nil
    35  			}
    36  		}
    37  	}
    38  	return "", &errortypes.BadInput{
    39  		Message: fmt.Sprintf("Failed to find native/banner/video impression \"%s\" ", impID),
    40  	}
    41  }
    42  
    43  func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
    44  	for _, imp := range imps {
    45  		if imp.ID == impID {
    46  			// ruleid: bid-type-if-check
    47  			if imp.Banner != nil {
    48  				return openrtb_ext.BidTypeBanner
    49  			}
    50  		}
    51  	}
    52  	return "", &errortypes.BadInput{
    53  		Message: fmt.Sprintf("Failed to find native/banner/video impression \"%s\" ", impID),
    54  	}
    55  }