21 class CycloneDXConfigDialog(QDialog, Ui_CycloneDXConfigDialog): |
21 class CycloneDXConfigDialog(QDialog, Ui_CycloneDXConfigDialog): |
22 """ |
22 """ |
23 Class implementing a dialog to configure the CycloneDX SBOM generation. |
23 Class implementing a dialog to configure the CycloneDX SBOM generation. |
24 """ |
24 """ |
25 SupportedSchemas = { |
25 SupportedSchemas = { |
26 "JSON": ["1.4", "1.3", "1.2"], |
26 "JSON": [ |
27 "XML": ["1.4", "1.3", "1.2", "1.1", "1.0"], |
27 (1, 4), |
|
28 (1, 3), |
|
29 (1, 2), |
|
30 ], |
|
31 "XML": [ |
|
32 (1, 4), |
|
33 (1, 3), |
|
34 (1, 2), |
|
35 (1, 1), |
|
36 (1, 0), |
|
37 ], |
28 } |
38 } |
29 Sources = { |
39 Sources = { |
30 "pipenv": "Pipfile.lock", |
40 "pipenv": "Pipfile.lock", |
31 "poetry": "poetry.lock", |
41 "poetry": "poetry.lock", |
32 "requirements": "requirements.txt", |
42 "requirements": "requirements.txt", |
70 self.requirementsButton.setEnabled(os.path.isfile(os.path.join( |
80 self.requirementsButton.setEnabled(os.path.isfile(os.path.join( |
71 self.__defaultDirectory, |
81 self.__defaultDirectory, |
72 CycloneDXConfigDialog.Sources["requirements"] |
82 CycloneDXConfigDialog.Sources["requirements"] |
73 ))) |
83 ))) |
74 |
84 |
|
85 self.vulnerabilityCheckBox.toggled.connect( |
|
86 self.__repopulateSchemaVersionComboBox) |
|
87 |
75 self.filePicker.setMode(EricPathPickerModes.SAVE_FILE_OVERWRITE_MODE) |
88 self.filePicker.setMode(EricPathPickerModes.SAVE_FILE_OVERWRITE_MODE) |
76 self.filePicker.setDefaultDirectory(self.__defaultDirectory) |
89 self.filePicker.setDefaultDirectory(self.__defaultDirectory) |
77 |
90 |
78 self.fileFormatComboBox.setCurrentText( |
91 self.fileFormatComboBox.setCurrentText( |
79 CycloneDXConfigDialog.DefaultFileFormat) |
92 CycloneDXConfigDialog.DefaultFileFormat) |
81 CycloneDXConfigDialog.DefaultFileFormat) |
94 CycloneDXConfigDialog.DefaultFileFormat) |
82 |
95 |
83 msh = self.minimumSizeHint() |
96 msh = self.minimumSizeHint() |
84 self.resize(max(self.width(), msh.width()), msh.height()) |
97 self.resize(max(self.width(), msh.width()), msh.height()) |
85 |
98 |
|
99 @pyqtSlot() |
|
100 def __repopulateSchemaVersionComboBox(self): |
|
101 """ |
|
102 Private slot to repopulate the schema version selector. |
|
103 """ |
|
104 fileFormat = self.fileFormatComboBox.currentText() |
|
105 minSchemaVersion = ( |
|
106 (1, 4) |
|
107 if self.vulnerabilityCheckBox.isChecked() else |
|
108 (1, 0) |
|
109 ) |
|
110 self.schemaVersionComboBox.clear() |
|
111 self.schemaVersionComboBox.addItems( |
|
112 "{0}.{1}".format(*f) |
|
113 for f in CycloneDXConfigDialog.SupportedSchemas[fileFormat] |
|
114 if f >= minSchemaVersion |
|
115 ) |
|
116 |
86 @pyqtSlot(str) |
117 @pyqtSlot(str) |
87 def on_fileFormatComboBox_currentTextChanged(self, fileFormat): |
118 def on_fileFormatComboBox_currentTextChanged(self, fileFormat): |
88 """ |
119 """ |
89 Private slot to handle the selection of a SBOM file format. |
120 Private slot to handle the selection of a SBOM file format. |
90 |
121 |
91 @param fileFormat selected format |
122 @param fileFormat selected format |
92 @type str |
123 @type str |
93 """ |
124 """ |
94 # re-populate the file schema combo box |
125 # re-populate the file schema combo box |
95 self.schemaVersionComboBox.clear() |
126 self.__repopulateSchemaVersionComboBox() |
96 self.schemaVersionComboBox.addItems( |
|
97 CycloneDXConfigDialog.SupportedSchemas[fileFormat]) |
|
98 |
127 |
99 # set the file filter |
128 # set the file filter |
100 if fileFormat == "JSON": |
129 if fileFormat == "JSON": |
101 self.filePicker.setFilters( |
130 self.filePicker.setFilters( |
102 self.tr("JSON Files (*.json);;All Files (*)")) |
131 self.tr("JSON Files (*.json);;All Files (*)")) |
109 def getData(self): |
138 def getData(self): |
110 """ |
139 """ |
111 Public method to get the SBOM configuration data. |
140 Public method to get the SBOM configuration data. |
112 |
141 |
113 @return tuple containing the input source, the input file name, the |
142 @return tuple containing the input source, the input file name, the |
114 file format, the schema version and the path of the SBOM file to |
143 file format, the schema version, the path of the SBOM file to be |
115 be written |
144 written and a flag indicating to include vulnerability information |
116 @rtype tuple of (str, str, str, str, str) |
145 @rtype tuple of (str, str, str, str, str, bool) |
117 """ |
146 """ |
118 if self.environmentButton.isChecked(): |
147 if self.environmentButton.isChecked(): |
119 inputSource = "environment" |
148 inputSource = "environment" |
120 inputFile = None |
149 inputFile = None |
121 elif self.pipenvButton.isChecked(): |
150 elif self.pipenvButton.isChecked(): |