Skip to content

Add button to remove SBOM #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
"authenticated": "Authenticated",
"authors": "Authors",
"bom": "BOM",
"bom_deleted": "BOM successfully deleted",
"bom_format": "BOM Format",
"bom_uploaded": "BOM uploaded",
"browse": "Browse",
Expand Down Expand Up @@ -493,6 +494,7 @@
"data": "Data",
"dates": "Dates",
"delete": "Delete",
"delete_bom_tooltip": "Delete BOM from project.",
"delete_license_group": "Delete License Group",
"delete_policy": "Delete Policy",
"delete_selected": "Delete selected items",
Expand Down Expand Up @@ -593,6 +595,7 @@
"matrix": "Matrix",
"metric_refresh_requested": "A refresh has been requested. Metrics will be updated when the refresh task has completed.",
"name": "Name",
"no_bom_available": "No BOM exists for project",
"no_file_chosen": "No file chosen",
"non_vulnerable": "Non Vulnerable",
"not_affected": "Not Affected",
Expand Down Expand Up @@ -780,7 +783,9 @@
"references": "References",
"reindex": "Rebuild index(es)",
"rejected": "Rejected",
"remove_bom": "Remove BOM",
"remove_component": "Remove Component",
"removing_dependencies": "Removing dependencies, {n} left",
"reported_by": "Reported By",
"required_component_identifier": "A component identifier is required",
"required_component_name": "The component name is required",
Expand Down
70 changes: 70 additions & 0 deletions src/views/portfolio/projects/ProjectComponents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
<b-tooltip target="upload-button" triggers="hover focus">{{
$t('message.upload_bom_tooltip')
}}</b-tooltip>
<b-button
size="md"
variant="outline-primary"
@click="$refs.confirmModal.show()"
v-permission="PERMISSIONS.PORTFOLIO_MANAGEMENT"
style="margin-left: 0px"
>
<span class="fa fa-minus"></span> {{ $t('message.remove_bom') }}
</b-button>
<b-dropdown
variant="outline-primary"
v-permission="PERMISSIONS.VIEW_PORTFOLIO"
Expand Down Expand Up @@ -115,6 +124,17 @@
:uuid="this.uuid"
v-on:refreshTable="refreshTable"
/>
<b-modal ref="confirmModal" title="Confirm Removal">
<p>Are you sure you want to remove the BOM and all its components?</p>
<div slot="modal-footer">
<b-button variant="outline-primary" @click="$refs.confirmModal.hide()"
>Cancel</b-button
>
<b-button variant="outline-danger" @click="handleRemoveBom"
>Remove</b-button
>
</div>
</b-modal>
</div>
</template>

Expand Down Expand Up @@ -400,6 +420,56 @@ export default {
}
this.$refs.table.uncheckAll();
},
handleRemoveBom() {
this.$refs.confirmModal.hide();
this.removeBom();
},
removeBom: async function () {
let getDependenciesUrl = `${this.$api.BASE_URL}/${this.$api.URL_COMPONENT}/project/${this.uuid}`;
let deleteBomUrl = `${this.$api.BASE_URL}/${this.$api.URL_BOM}/project/${this.uuid}`;
try {
let allDependencies = [];
let page = 1;
let pageSize = 100;
while (true) {
let response = await this.axios.get(
`${getDependenciesUrl}?page=${page}&size=${pageSize}`,
);
let dependencies = response.data;
if (!dependencies || dependencies.length === 0) break;
allDependencies = allDependencies.concat(dependencies);
page++;
}
let batchSize = 50;
let lengthAllDependencies = allDependencies.length;
if (lengthAllDependencies !== 0) {
for (let i = 0; i < allDependencies.length; i += batchSize) {
let batch = allDependencies.slice(i, i + batchSize);
this.$toastr.s(
this.$t('message.removing_dependencies', {
n: lengthAllDependencies,
}),
);
lengthAllDependencies -= batch.length;
let deletePromises = batch.map((dep) =>
this.axios.delete(
`${this.$api.BASE_URL}/${this.$api.URL_COMPONENT}/${dep.uuid}`,
),
);
await Promise.all(deletePromises);
this.$refs.table.refresh({ silent: true });
}
await this.axios.delete(deleteBomUrl);
this.$toastr.s(this.$t('message.bom_deleted'));
this.$refs.table.removeAll();
await this.axios.get(`/api/v1/metrics/project/${this.uuid}/refresh`);
} else {
this.$toastr.w(this.$t('message.no_bom_available'));
}
} catch (error) {
this.$toastr.w(this.$t('condition.unsuccessful_action'));
}
},
downloadBom: function (data) {
let url = `${this.$api.BASE_URL}/${this.$api.URL_BOM}/cyclonedx/project/${this.uuid}`;
this.axios
Expand Down