You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.7 KiB
150 lines
3.7 KiB
package com.redhat.pctsec.rest.v1alpha1; |
|
|
|
import com.redhat.pctsec.model.*; |
|
import com.redhat.pctsec.model.api.request.pssaas; |
|
import com.redhat.pctsec.model.api.request.scanChain; |
|
import com.redhat.pctsec.model.jpa.ScanRepository; |
|
import io.quarkus.security.Authenticated; |
|
import io.vertx.mutiny.core.eventbus.EventBus; |
|
import jakarta.enterprise.context.ApplicationScoped; |
|
import jakarta.inject.Inject; |
|
import jakarta.transaction.Transactional; |
|
import jakarta.validation.Valid; |
|
import jakarta.ws.rs.*; |
|
import org.jboss.resteasy.reactive.RestQuery; |
|
|
|
|
|
import java.util.HashMap; |
|
import java.util.List; |
|
import java.util.Set; |
|
import java.util.UUID; |
|
|
|
@ApplicationScoped |
|
@Path("/api/v1a/Scan") |
|
public class ScanResource { |
|
|
|
@Inject |
|
ScanRepository sr; |
|
|
|
@Inject |
|
EventBus bus; |
|
|
|
@POST |
|
@Path("PSSaaS") |
|
@Consumes({ "application/json" }) |
|
@Transactional |
|
@Authenticated |
|
public Scan createPSSAAS(@Valid pssaas scanRequest) |
|
{ |
|
ScanRequests scanRequests = new ScanRequests(scanRequest); |
|
Scan s = new Scan(); |
|
s.setRequestor("cpaas"); |
|
s.setProductName(scanRequest.productId); |
|
s.setScanRequests(scanRequests); |
|
sr.persist(s); |
|
return s; |
|
} |
|
@POST |
|
@Path("PSSaaS/run") |
|
@Consumes({ "application/json" }) |
|
@Transactional |
|
@Authenticated |
|
public List<ScanTask> createRunPSSAAS(@Valid pssaas scanRequest) |
|
{ |
|
Scan s = this.createPSSAAS(scanRequest); |
|
return s.scanRequests.execute(bus); |
|
} |
|
|
|
@POST |
|
@Path("ScanChain") |
|
@Consumes({ "application/json" }) |
|
@Transactional |
|
@Authenticated |
|
public Scan createScanChain(@Valid scanChain scanRequest) |
|
{ |
|
ScanRequests scanRequests = new ScanRequests(scanRequest); |
|
Scan s = new Scan(); |
|
s.setRequestor(scanRequest.requestor); |
|
s.setProductName(scanRequest.productName); |
|
s.setScanRequests(scanRequests); |
|
sr.persist(s); |
|
return s; |
|
} |
|
@POST |
|
@Path("ScanChain/run") |
|
@Consumes({ "application/json" }) |
|
@Transactional |
|
@Authenticated |
|
public List<ScanTask> createRunScanChain(@Valid scanChain scanRequest) |
|
{ |
|
Scan s = this.createScanChain(scanRequest); |
|
return s.scanRequests.execute(bus); |
|
} |
|
@GET |
|
@Path("All") |
|
@Produces({"application/json"}) |
|
public List<Scan> list() |
|
{ |
|
return sr.listAll(); |
|
} |
|
|
|
@GET |
|
@Path("{id}") |
|
@Produces({"application/json"}) |
|
public Scan scanRequest(String id) |
|
{ |
|
Scan s = sr.findById(UUID.fromString(id)); |
|
return s; |
|
} |
|
|
|
@GET |
|
@Path("{id}/run") |
|
@Authenticated |
|
public List<ScanTask> scanRequestExe(String id) |
|
{ |
|
Scan s = sr.findById(UUID.fromString(id)); |
|
return s.scanRequests.execute(bus); |
|
} |
|
|
|
|
|
@GET |
|
@Path("single/git") |
|
@Produces({"application/json"}) |
|
@Transactional |
|
@Authenticated |
|
public Scan singleGit(@RestQuery String repo, @RestQuery String ref) |
|
{ |
|
Scan s = new Scan(); |
|
s.setRequestor("jochrist"); |
|
s.getScanRequests().addGit(repo,ref); |
|
sr.persist(s); |
|
return s; |
|
} |
|
|
|
@GET |
|
@Path("single/brew") |
|
@Produces({"application/json"}) |
|
@Transactional |
|
@Authenticated |
|
public Scan singleGit(@RestQuery String brewId) |
|
{ |
|
Scan s = new Scan(); |
|
s.setRequestor("jochrist"); |
|
s.getScanRequests().addBrewBuild(brewId); |
|
sr.persist(s); |
|
return s; |
|
} |
|
@GET |
|
@Path("single/pnc") |
|
@Produces({"application/json"}) |
|
@Transactional |
|
@Authenticated |
|
public Scan singlePNC(@RestQuery String pncId) |
|
{ |
|
Scan s = new Scan(); |
|
s.setRequestor("jochrist"); |
|
s.getScanRequests().addPNCBuild(pncId); |
|
sr.persist(s); |
|
return s; |
|
} |
|
}
|
|
|