@@ -5,6 +5,7 @@ use crate::{
55} ;
66use sea_orm:: TransactionTrait ;
77use serde_cyclonedx:: cyclonedx:: v_1_6:: Component ;
8+ use std:: str:: FromStr ;
89use tracing:: instrument;
910use trustify_common:: { hashing:: Digests , id:: Id } ;
1011use trustify_entity:: labels:: Labels ;
@@ -76,17 +77,43 @@ impl<'g> CyclonedxLoader<'g> {
7677 }
7778}
7879
80+ enum Kind {
81+ AIBOM ,
82+ CBOM ,
83+ }
84+
85+ impl Kind {
86+ fn as_str ( & self ) -> & ' static str {
87+ match self {
88+ Kind :: AIBOM => "aibom" ,
89+ Kind :: CBOM => "cbom" ,
90+ }
91+ }
92+ }
93+
94+ impl FromStr for Kind {
95+ type Err = ( ) ;
96+
97+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
98+ match s {
99+ "machine-learning-model" => Ok ( Kind :: AIBOM ) ,
100+ "cryptographic-asset" => Ok ( Kind :: CBOM ) ,
101+ _ => Err ( ( ) ) ,
102+ }
103+ }
104+ }
105+
79106fn extract_labels ( components : Option < & Vec < Component > > , labels_in : Labels ) -> Labels {
80107 let mut labels = Labels :: new ( ) . add ( "type" , "cyclonedx" ) ;
81108
82- // find if there are machine learning model components in the SBOM
83- if let Some ( components) = components
84- && components
85- . iter ( )
86- . any ( |c| c. type_ == "machine-learning-model" )
87- {
88- labels = labels. add ( "ai" , "machine-learning-model" ) ;
109+ if let Some ( components) = components {
110+ for component in components {
111+ if let Ok ( kind) = Kind :: from_str ( & component. type_ ) {
112+ labels = labels. add ( "kind" , kind. as_str ( ) ) ;
113+ }
114+ }
89115 }
116+
90117 if !labels_in. is_empty ( ) {
91118 return labels. extend ( labels_in. 0 . clone ( ) ) ;
92119 }
0 commit comments