diff --git a/core/src/main/java/org/jboss/sbomer/core/features/sbom/config/DeliverableAnalysisConfig.java b/core/src/main/java/org/jboss/sbomer/core/features/sbom/config/DeliverableAnalysisConfig.java index afd8c0c5f..88fa6402d 100644 --- a/core/src/main/java/org/jboss/sbomer/core/features/sbom/config/DeliverableAnalysisConfig.java +++ b/core/src/main/java/org/jboss/sbomer/core/features/sbom/config/DeliverableAnalysisConfig.java @@ -19,6 +19,7 @@ import java.util.List; +import jakarta.validation.constraints.Size; import org.jboss.sbomer.core.features.sbom.config.runtime.ErrataConfig; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -32,6 +33,7 @@ import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; + /** * SBOMer configuration file to trigger a new PNC deliverable analysis. * @@ -60,6 +62,7 @@ public class DeliverableAnalysisConfig extends Config { /** * Deliverables entries for the given operation. */ + @Size(min = 1) List deliverableUrls; @JsonIgnore diff --git a/service/src/main/java/org/jboss/sbomer/service/feature/sbom/service/SbomService.java b/service/src/main/java/org/jboss/sbomer/service/feature/sbom/service/SbomService.java index 404d65998..d86fbd839 100644 --- a/service/src/main/java/org/jboss/sbomer/service/feature/sbom/service/SbomService.java +++ b/service/src/main/java/org/jboss/sbomer/service/feature/sbom/service/SbomService.java @@ -25,6 +25,7 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.jboss.pnc.dto.DeliverableAnalyzerOperation; import org.jboss.pnc.dto.requests.DeliverablesAnalysisRequest; +import org.jboss.pnc.dto.requests.ScratchDeliverablesAnalysisRequest; import org.jboss.sbomer.core.SchemaValidator.ValidationResult; import org.jboss.sbomer.core.config.ConfigSchemaValidator; import org.jboss.sbomer.core.config.SbomerConfigProvider; @@ -588,9 +589,14 @@ public V1Beta1RequestRecord searchLastSuccessfulAdvisoryRequestRecord(String ign public DeliverableAnalyzerOperation doAnalyzeDeliverables(DeliverableAnalysisConfig config) { try { - return pncClient.analyzeDeliverables( - config.getMilestoneId(), - DeliverablesAnalysisRequest.builder().deliverablesUrls(config.getDeliverableUrls()).build()); + if (config.getMilestoneId() == null) { + return pncClient.startScratchDeliverableAnalysis( + ScratchDeliverablesAnalysisRequest.builder().deliverablesUrls(config.getDeliverableUrls()).build()); + } else { + return pncClient.analyzeDeliverables( + config.getMilestoneId(), + DeliverablesAnalysisRequest.builder().deliverablesUrls(config.getDeliverableUrls()).build()); + } } catch (ClientException ex) { throw new ApplicationException("Operation could not be retrieved because PNC responded with an error", ex); } diff --git a/service/src/main/java/org/jboss/sbomer/service/pnc/PncClient.java b/service/src/main/java/org/jboss/sbomer/service/pnc/PncClient.java index ade779a84..c275583f2 100644 --- a/service/src/main/java/org/jboss/sbomer/service/pnc/PncClient.java +++ b/service/src/main/java/org/jboss/sbomer/service/pnc/PncClient.java @@ -31,6 +31,7 @@ import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import org.jboss.pnc.dto.requests.ScratchDeliverablesAnalysisRequest; @ApplicationScoped @ClientHeaderParam(name = "User-Agent", value = "SBOMer") @@ -51,4 +52,9 @@ DeliverableAnalyzerOperation analyzeDeliverables( @Path("/operations/deliverable-analyzer/{id}") DeliverableAnalyzerOperation getDeliverableAnalyzerOperation(@PathParam("id") String operationId); + @POST + @Path("/operations/deliverable-analyzer/start") + DeliverableAnalyzerOperation startScratchDeliverableAnalysis( + ScratchDeliverablesAnalysisRequest scratchDeliverablesAnalysisRequest); + }