@@ -274,6 +274,7 @@ func (impl *ImageScanServiceImpl) RegisterScanExecutionHistoryAndState(scanEvent
274274 impl .Logger .Errorw ("Failed to save executionHistory" , "err" , err , "model" , executionHistoryModel )
275275 return nil , executionHistoryDirPath , err
276276 }
277+
277278 // creating folder for storing all details if not exist
278279 isExist , err := helper .DoesFileExist (bean .ScanOutputDirectory )
279280 if err != nil {
@@ -509,9 +510,9 @@ func (impl *ImageScanServiceImpl) ConvertEndStepOutputAndSaveVulnerabilities(ste
509510 for _ , vul := range uniqueVulnerabilityMap {
510511 if val , ok := allSavedCvesMap [vul .Name ]; ok {
511512 // updating cve here if vulnerability has a new severity
512- vulnerabilitySeverity := bean .SeverityStringToEnum (bean .ConvertToLowerCase (vul .Severity ))
513- if vulnerabilitySeverity != val .Severity {
514- val .UpdateNewSeverityInCveStore (vulnerabilitySeverity , userId )
513+ vulnerabilityStandardSeverity := bean .StandardSeverityStringToEnum (bean .ConvertToLowerCase (vul .Severity ))
514+ if vulnerabilityStandardSeverity != val .GetSeverity () {
515+ val .UpdateNewSeverityInCveStore (vul . Severity , userId )
515516 cvesToUpdate = append (cvesToUpdate , val )
516517 }
517518 } else {
@@ -522,7 +523,7 @@ func (impl *ImageScanServiceImpl) ConvertEndStepOutputAndSaveVulnerabilities(ste
522523
523524 imageScanExecutionResults := make ([]* repository.ImageScanExecutionResult , 0 , len (vulnerabilities ))
524525 for _ , vul := range vulnerabilities {
525- imageScanExecutionResult := createImageScanExecutionResultObject (executionHistoryId , vul .Name , vul .Package , vul .PackageVersion , vul .FixedInVersion , tool .Id )
526+ imageScanExecutionResult := createImageScanExecutionResultObject (executionHistoryId , vul .Name , vul .Package , vul .PackageVersion , vul .FixedInVersion , vul . Class , vul . Type , vul . TargetName , tool .Id )
526527 imageScanExecutionResults = append (imageScanExecutionResults , imageScanExecutionResult )
527528 }
528529 tx , err := impl .CveStoreRepository .GetConnection ().Begin ()
@@ -562,7 +563,7 @@ func (impl *ImageScanServiceImpl) ConvertEndStepOutputAndSaveVulnerabilities(ste
562563}
563564
564565func isV1Template (resultDescriptorTemplate string ) bool {
565- var mappings []bean. Mapping
566+ var mappings []map [ string ] interface {}
566567 err := json .Unmarshal ([]byte (resultDescriptorTemplate ), & mappings )
567568 return err != nil && isValidGoTemplate (resultDescriptorTemplate ) //checking error too because our new result descriptor template can pass go templating too as it contains a simple json
568569}
@@ -593,33 +594,46 @@ func (impl *ImageScanServiceImpl) getImageScanOutputObjectsV1(stepOutput []byte,
593594
594595func (impl * ImageScanServiceImpl ) getImageScanOutputObjectsV2 (stepOutput []byte , resultDescriptorTemplate string ) ([]* bean.ImageScanOutputObject , error ) {
595596 var vulnerabilities []* bean.ImageScanOutputObject
596- var mappings []bean. Mapping
597+ var mappings []map [ string ] interface {}
597598 err := json .Unmarshal ([]byte (resultDescriptorTemplate ), & mappings )
598599 if err != nil {
599600 impl .Logger .Errorw ("error in un-marshaling result descriptor template" , "err" , err , "resultDescriptorTemplate" , resultDescriptorTemplate )
600601 return nil , err
601602 }
602- var processArray func (mapping bean.Mapping , value gjson.Result )
603- processArray = func (mapping bean.Mapping , value gjson.Result ) {
603+ var processArray func (mapping map [string ]interface {}, value gjson.Result )
604+ processArray = func (mapping map [string ]interface {}, value gjson.Result ) {
605+ vulnerabilitiesPath := mapping [bean .MappingKeyPathToVulnerabilitiesArray ].(string )
606+ vulnerabilityDataKeyPathsMap := mapping [bean .MappingKeyPathToVulnerabilityDataKeys ].(map [string ]interface {})
607+ resultDataKeyPathsMap := mapping [bean .MappingKeyPathToResultDataKeys ].(map [string ]interface {})
608+
604609 value .ForEach (func (_ , nestedValue gjson.Result ) bool {
605- if nestedValue .IsArray () {
606- // if the nested value is an array, recursively process it
607- processArray (mapping , nestedValue )
608- } else {
609- vulnerability := & bean.ImageScanOutputObject {
610- Name : nestedValue .Get (mapping [bean .MappingKeyName ]).String (),
611- Package : nestedValue .Get (mapping [bean .MappingKeyPackage ]).String (),
612- PackageVersion : nestedValue .Get (mapping [bean .MappingKeyPackageVersion ]).String (),
613- FixedInVersion : nestedValue .Get (mapping [bean .MappingKeyFixedInVersion ]).String (),
614- Severity : nestedValue .Get (mapping [bean .MappingKeySeverity ]).String (),
610+ targetName , class , resType := "" , "" , ""
611+ if nestedValue .IsObject () {
612+ targetName , class , resType = nestedValue .Get (resultDataKeyPathsMap [bean .MappingTarget ].(string )).String (), nestedValue .Get (resultDataKeyPathsMap [bean .MappingClass ].(string )).String (), nestedValue .Get (resultDataKeyPathsMap [bean .MappingType ].(string )).String ()
613+
614+ if nestedValue .Get (vulnerabilitiesPath ).IsArray () {
615+ nestedValue .Get (vulnerabilitiesPath ).ForEach (func (_ , vul gjson.Result ) bool {
616+ vulnerability := & bean.ImageScanOutputObject {
617+ Name : vul .Get (vulnerabilityDataKeyPathsMap [bean .MappingKeyName ].(string )).String (),
618+ Package : vul .Get (vulnerabilityDataKeyPathsMap [bean .MappingKeyPackage ].(string )).String (),
619+ PackageVersion : vul .Get (vulnerabilityDataKeyPathsMap [bean .MappingKeyPackageVersion ].(string )).String (),
620+ FixedInVersion : vul .Get (vulnerabilityDataKeyPathsMap [bean .MappingKeyFixedInVersion ].(string )).String (),
621+ Severity : vul .Get (vulnerabilityDataKeyPathsMap [bean .MappingKeySeverity ].(string )).String (),
622+ TargetName : targetName ,
623+ Class : class ,
624+ Type : resType ,
625+ }
626+ vulnerabilities = append (vulnerabilities , vulnerability )
627+ return true
628+ })
615629 }
616- vulnerabilities = append (vulnerabilities , vulnerability )
617630 }
618631 return true
619632 })
620633 }
634+
621635 for _ , mapping := range mappings {
622- result := gjson .Get (string (stepOutput ), mapping [bean .MappingKeyPathToVulnerabilitiesArray ] )
636+ result := gjson .Get (string (stepOutput ), mapping [bean .MappingKeyPathToResultsArray ].( string ) )
623637 if ! result .Exists () {
624638 continue
625639 }
@@ -734,13 +748,13 @@ func (impl *ImageScanServiceImpl) CreateScanExecutionRegistryForClairV4(vs []*cl
734748 cvesToBeSaved = append (cvesToBeSaved , cveStore )
735749 } else {
736750 // updating cve here if vulnerability has a new severity
737- vulnerabilitySeverity := bean .SeverityStringToEnum (bean .ConvertToLowerCase (item .Severity ))
738- if vulnerabilitySeverity != cveStore .Severity {
739- cveStore .UpdateNewSeverityInCveStore (vulnerabilitySeverity , userId )
751+ vulnerabilityStandardSeverity := bean .StandardSeverityStringToEnum (bean .ConvertToLowerCase (item .Severity ))
752+ if vulnerabilityStandardSeverity != cveStore .GetSeverity () {
753+ cveStore .UpdateNewSeverityInCveStore (item . Severity , userId )
740754 cvesToUpdate = append (cvesToUpdate , cveStore )
741755 }
742756 }
743- imageScanExecutionResult := createImageScanExecutionResultObject (executionHistory .Id , item .Name , item .Package .Name , item .Package .Version , item .FixedInVersion , toolId )
757+ imageScanExecutionResult := createImageScanExecutionResultObject (executionHistory .Id , item .Name , item .Package .Name , item .Package .Version , item .FixedInVersion , "" , "" , "" , toolId )
744758 imageScanExecutionResultsToBeSaved = append (imageScanExecutionResultsToBeSaved , imageScanExecutionResult )
745759 }
746760 tx , err := impl .CveStoreRepository .GetConnection ().Begin ()
@@ -797,13 +811,13 @@ func (impl *ImageScanServiceImpl) CreateScanExecutionRegistryForClairV2(vs []*cl
797811 cvesToBeSaved = append (cvesToBeSaved , cveStore )
798812 } else {
799813 // updating cve here if vulnerability has a new severity
800- vulnerabilitySeverity := bean .SeverityStringToEnum (bean .ConvertToLowerCase (item .Severity ))
801- if vulnerabilitySeverity != cveStore .Severity {
802- cveStore .UpdateNewSeverityInCveStore (vulnerabilitySeverity , userId )
814+ vulnerabilityStandardSeverity := bean .StandardSeverityStringToEnum (bean .ConvertToLowerCase (item .Severity ))
815+ if vulnerabilityStandardSeverity != cveStore .GetSeverity () {
816+ cveStore .UpdateNewSeverityInCveStore (item . Severity , userId )
803817 cvesToUpdate = append (cvesToUpdate , cveStore )
804818 }
805819 }
806- imageScanExecutionResult := createImageScanExecutionResultObject (executionHistory .Id , item .Name , item .FeatureName , item .FeatureVersion , item .FixedBy , toolId )
820+ imageScanExecutionResult := createImageScanExecutionResultObject (executionHistory .Id , item .Name , item .FeatureName , item .FeatureVersion , item .FixedBy , "" , "" , "" , toolId )
807821 imageScanExecutionResultsToBeSaved = append (imageScanExecutionResultsToBeSaved , imageScanExecutionResult )
808822 }
809823 tx , err := impl .CveStoreRepository .GetConnection ().Begin ()
0 commit comments