@@ -93,22 +93,7 @@ def _specialise_output_for_schema_version(self, bom_json: Dict[Any, Any]) -> str
93
93
del bom_json ['metadata' ]['properties' ]
94
94
95
95
# Iterate Components
96
- if 'components' in bom_json .keys ():
97
- for i in range (len (bom_json ['components' ])):
98
- if self .component_version_optional () and bom_json ['components' ][i ]['version' ] == "" :
99
- del bom_json ['components' ][i ]['version' ]
100
-
101
- if not self .component_supports_author () and 'author' in bom_json ['components' ][i ].keys ():
102
- del bom_json ['components' ][i ]['author' ]
103
-
104
- if not self .component_supports_mime_type_attribute () \
105
- and 'mime-type' in bom_json ['components' ][i ].keys ():
106
- del bom_json ['components' ][i ]['mime-type' ]
107
-
108
- if not self .component_supports_release_notes () and 'releaseNotes' in bom_json ['components' ][i ].keys ():
109
- del bom_json ['components' ][i ]['releaseNotes' ]
110
- else :
111
- bom_json ['components' ] = []
96
+ bom_json = self ._recurse_specialise_component (bom_json = bom_json )
112
97
113
98
# Iterate Services
114
99
if 'services' in bom_json .keys ():
@@ -126,11 +111,6 @@ def _specialise_output_for_schema_version(self, bom_json: Dict[Any, Any]) -> str
126
111
and 'hashes' in bom_json ['externalReferences' ][i ].keys ():
127
112
del bom_json ['externalReferences' ][i ]['hashes' ]
128
113
129
- # Iterate Vulnerabilities
130
- if 'vulnerabilities' in bom_json .keys ():
131
- for i in range (len (bom_json ['vulnerabilities' ])):
132
- print ("Checking " + str (bom_json ['vulnerabilities' ][i ]))
133
-
134
114
return json .dumps (bom_json )
135
115
136
116
def output_as_string (self ) -> str :
@@ -151,6 +131,61 @@ def _create_bom_element(self) -> Dict[str, Union[str, int]]:
151
131
def _get_schema_uri (self ) -> Optional [str ]:
152
132
pass
153
133
134
+ def _recurse_specialise_component (self , bom_json : Dict [Any , Any ], base_key : str = 'components' ) -> Dict [Any , Any ]:
135
+ if base_key in bom_json .keys ():
136
+ for i in range (len (bom_json [base_key ])):
137
+ if not self .component_supports_mime_type_attribute () \
138
+ and 'mime-type' in bom_json [base_key ][i ].keys ():
139
+ del bom_json [base_key ][i ]['mime-type' ]
140
+
141
+ if not self .component_supports_supplier () and 'supplier' in bom_json [base_key ][i ].keys ():
142
+ del bom_json [base_key ][i ]['supplier' ]
143
+
144
+ if not self .component_supports_author () and 'author' in bom_json [base_key ][i ].keys ():
145
+ del bom_json [base_key ][i ]['author' ]
146
+
147
+ if self .component_version_optional () and bom_json [base_key ][i ]['version' ] == "" :
148
+ del bom_json [base_key ][i ]['version' ]
149
+
150
+ if not self .component_supports_pedigree () and 'pedigree' in bom_json [base_key ][i ].keys ():
151
+ del bom_json [base_key ][i ]['pedigree' ]
152
+ elif 'pedigree' in bom_json [base_key ][i ].keys ():
153
+ if 'ancestors' in bom_json [base_key ][i ]['pedigree' ].keys ():
154
+ # recurse into ancestors
155
+ bom_json [base_key ][i ]['pedigree' ] = self ._recurse_specialise_component (
156
+ bom_json = bom_json [base_key ][i ]['pedigree' ], base_key = 'ancestors'
157
+ )
158
+ if 'descendants' in bom_json [base_key ][i ]['pedigree' ].keys ():
159
+ # recurse into descendants
160
+ bom_json [base_key ][i ]['pedigree' ] = self ._recurse_specialise_component (
161
+ bom_json = bom_json [base_key ][i ]['pedigree' ], base_key = 'descendants'
162
+ )
163
+ if 'variants' in bom_json [base_key ][i ]['pedigree' ].keys ():
164
+ # recurse into variants
165
+ bom_json [base_key ][i ]['pedigree' ] = self ._recurse_specialise_component (
166
+ bom_json = bom_json [base_key ][i ]['pedigree' ], base_key = 'variants'
167
+ )
168
+
169
+ if not self .external_references_supports_hashes () and 'externalReferences' \
170
+ in bom_json [base_key ][i ].keys ():
171
+ for j in range (len (bom_json [base_key ][i ]['externalReferences' ])):
172
+ del bom_json [base_key ][i ]['externalReferences' ][j ]['hashes' ]
173
+
174
+ if not self .component_supports_properties () and 'properties' in bom_json [base_key ][i ].keys ():
175
+ del bom_json [base_key ][i ]['properties' ]
176
+
177
+ # recurse
178
+ if 'components' in bom_json [base_key ][i ].keys ():
179
+ bom_json [base_key ][i ] = self ._recurse_specialise_component (bom_json = bom_json [base_key ][i ])
180
+
181
+ if not self .component_supports_evidence () and 'evidence' in bom_json [base_key ][i ].keys ():
182
+ del bom_json [base_key ][i ]['evidence' ]
183
+
184
+ if not self .component_supports_release_notes () and 'releaseNotes' in bom_json [base_key ][i ].keys ():
185
+ del bom_json [base_key ][i ]['releaseNotes' ]
186
+
187
+ return bom_json
188
+
154
189
155
190
class JsonV1Dot0 (Json , SchemaVersion1Dot0 ):
156
191
0 commit comments