Skip to content

Commit

Permalink
fix: exclude current request from the successful ones
Browse files Browse the repository at this point in the history
  • Loading branch information
vibe13 committed Dec 17, 2024
1 parent 57c2536 commit 1dd390a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ private void adjustProperties(List<Property> properties) {
properties.forEach(p -> {
String newName = p.getName().replace("syft:", "sbomer:");

//log.debug("Adjusting property name from '{}' to '{}'", p.getName(), newName);
// log.debug("Adjusting property name from '{}' to '{}'", p.getName(), newName);

p.setName(newName);
});
Expand All @@ -498,10 +498,10 @@ private void adjustProperties(List<Property> properties) {
.anyMatch(prefix -> prop.getName().startsWith(prefix));

if (!supportedProp) {
//log.debug(
// "Property '{}' with value '{}' is not on the supported properties list, removing...",
// prop.getName(),
// prop.getValue());
// log.debug(
// "Property '{}' with value '{}' is not on the supported properties list, removing...",
// prop.getName(),
// prop.getValue());
}

return !supportedProp;
Expand All @@ -521,7 +521,7 @@ private void adjustProperties(List<Property> properties) {

@Override
protected void cleanupComponent(Component component) {
//log.debug("Cleaning up component '{}'", component.getPurl());
// log.debug("Cleaning up component '{}'", component.getPurl());

// Remove CPE, we don't use it now
component.setCpe(null);
Expand All @@ -534,16 +534,17 @@ protected void cleanupComponent(Component component) {
if (component.getPurl() != null && propType != null) {
switch (propType.getValue()) {
case "java-archive":
//log.debug(
// "Adjusting purl for the '{}' Java component by adding '?type=jar' suffix...",
// component.getPurl());
// log.debug(
// "Adjusting purl for the '{}' Java component by adding '?type=jar' suffix...",
// component.getPurl());
component.setPurl(component.getPurl() + "?type=jar");
break;

case "rpm":
//log.debug(
// "Adjusting purl for the '{}' RPM component by removing all qualifiers besides 'arch' and 'epoch'...",
// component.getPurl());
// log.debug(
// "Adjusting purl for the '{}' RPM component by removing all qualifiers besides 'arch' and
// 'epoch'...",
// component.getPurl());

cleanupPurl(component);
break;
Expand Down Expand Up @@ -591,7 +592,7 @@ private String doCleanupPurl(String purl) throws MalformedPackageURLException {
qualifiers,
packageURL.getSubpath()).canonicalize();

//log.debug("Updating purl to: '{}'", updatedPurl);
// log.debug("Updating purl to: '{}'", updatedPurl);
return updatedPurl;
}
return packageURL.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,12 @@ private Collection<SbomGenerationRequest> handleStandardAdvisory(RequestEvent re
// Otherwise SBOMer will default to the creation of build manifests. Will change in future!
V1Beta1RequestRecord successfulRequestRecord = null;
if (ErrataStatus.SHIPPED_LIVE.equals(details.getStatus())) {
log.debug("Errata status is SHIPPED_LIVE, looking for successful request records for advisory {}", erratum.getDetails().get().getId());
successfulRequestRecord = sbomService
.searchLastSuccessfulAdvisoryRequestRecord(String.valueOf(erratum.getDetails().get().getId()));
log.debug(
"Errata status is SHIPPED_LIVE, looking for successful request records for advisory {}",
erratum.getDetails().get().getId());
successfulRequestRecord = sbomService.searchLastSuccessfulAdvisoryRequestRecord(
requestEvent.getId(),
String.valueOf(erratum.getDetails().get().getId()));
}

log.debug("Successful request records found: {}", successfulRequestRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.pnc.dto.DeliverableAnalyzerOperation;
Expand Down Expand Up @@ -553,19 +554,32 @@ public void notifyCompleted(@SpanAttribute(value = "sbom") Sbom sbom) {
}

@Transactional
public V1Beta1RequestRecord searchLastSuccessfulAdvisoryRequestRecord(String advisoryId) {
public V1Beta1RequestRecord searchLastSuccessfulAdvisoryRequestRecord(String ignoreRequestId, String advisoryId) {
// Get all the request events generations for this advisory
List<V1Beta1RequestRecord> allAdvisoryRequestRecords = searchAggregatedResultsNatively(
ErrataAdvisoryRequestConfig.TYPE_NAME + "=" + advisoryId);

if (allAdvisoryRequestRecords == null || allAdvisoryRequestRecords.isEmpty()) {
log.debug("No records found for advisory {}", advisoryId);
return null;
}

// Filter the results and remove the current (IN_PROGRESS) requestId
List<V1Beta1RequestRecord> allAdvisoryRequestRecordsFiltered = allAdvisoryRequestRecords.stream()
.filter(record -> !record.id().equals(ignoreRequestId))
.collect(Collectors.toList());
log.debug("Filtering found records to ignore current IN_PROGRESS event {}", ignoreRequestId);

// Check whether the last one was completed successfully
if (allAdvisoryRequestRecords == null || allAdvisoryRequestRecords.isEmpty()
|| !RequestEventStatus.SUCCESS.equals(allAdvisoryRequestRecords.get(0).eventStatus())) {
if (allAdvisoryRequestRecordsFiltered.isEmpty()
|| !RequestEventStatus.SUCCESS.equals(allAdvisoryRequestRecordsFiltered.get(0).eventStatus())) {

log.debug("No successful records found for advisory {}", advisoryId);
return null;
}

// Get the latest request and verify there are manifests
V1Beta1RequestRecord latestAdvisoryRequestManifest = allAdvisoryRequestRecords.get(0);
V1Beta1RequestRecord latestAdvisoryRequestManifest = allAdvisoryRequestRecordsFiltered.get(0);
if (latestAdvisoryRequestManifest.manifests() == null || latestAdvisoryRequestManifest.manifests().isEmpty()) {
return null;
}
Expand Down

0 comments on commit 1dd390a

Please sign in to comment.