|
|
|
|
@ -2,20 +2,16 @@ 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.quarkus.security.identity.SecurityIdentity; |
|
|
|
|
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.validation.constraints.Email; |
|
|
|
|
import jakarta.ws.rs.*; |
|
|
|
|
import org.jboss.resteasy.reactive.RestQuery; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
@ -31,10 +27,6 @@ public class ScanResource {
|
|
|
|
|
@Inject |
|
|
|
|
EventBus bus; |
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
|
SecurityIdentity identity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST |
|
|
|
|
@Path("PSSaaS") |
|
|
|
|
@Consumes({ "application/json" }) |
|
|
|
|
@ -44,12 +36,8 @@ public class ScanResource {
|
|
|
|
|
{ |
|
|
|
|
ScanRequests scanRequests = new ScanRequests(scanRequest); |
|
|
|
|
Scan s = new Scan(); |
|
|
|
|
s.setProductName(scanRequest.productId); |
|
|
|
|
s.setRequestor("cpaas"); |
|
|
|
|
s.setScanRequests(scanRequests); |
|
|
|
|
if(!identity.getPrincipal().getName().isEmpty()) |
|
|
|
|
s.setRequestor(identity.getPrincipal().getName()); |
|
|
|
|
else |
|
|
|
|
s.setRequestor("CPaaS"); |
|
|
|
|
sr.persist(s); |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
@ -64,37 +52,6 @@ public class ScanResource {
|
|
|
|
|
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(); |
|
|
|
|
//Set the requestor to kerberos uid first
|
|
|
|
|
if(!identity.getPrincipal().getName().isEmpty()) |
|
|
|
|
s.setRequestor(identity.getPrincipal().getName()); |
|
|
|
|
//Set the email to be our kerberos id + @redhat.com
|
|
|
|
|
s.setEmail(s.getEmail()); |
|
|
|
|
//Now set the actual payload requestor
|
|
|
|
|
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"}) |
|
|
|
|
@ -121,19 +78,6 @@ public class ScanResource {
|
|
|
|
|
return s.scanRequests.execute(bus); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PATCH |
|
|
|
|
@Path("{id}/{email}") |
|
|
|
|
@Consumes({"application/octet-stream"}) |
|
|
|
|
@Produces({"application/json"}) |
|
|
|
|
@Authenticated |
|
|
|
|
@Transactional |
|
|
|
|
public Scan patchScanEmail(String id, @Email String email) |
|
|
|
|
{ |
|
|
|
|
Scan s = sr.findById(UUID.fromString(id)); |
|
|
|
|
s.setEmail(email); |
|
|
|
|
sr.persist(s); |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@GET |
|
|
|
|
@Path("single/git") |
|
|
|
|
@ -143,8 +87,7 @@ public class ScanResource {
|
|
|
|
|
public Scan singleGit(@RestQuery String repo, @RestQuery String ref) |
|
|
|
|
{ |
|
|
|
|
Scan s = new Scan(); |
|
|
|
|
if(!identity.getPrincipal().getName().isEmpty()) |
|
|
|
|
s.setRequestor(identity.getPrincipal().getName()); |
|
|
|
|
s.setRequestor("jochrist"); |
|
|
|
|
s.getScanRequests().addGit(repo,ref); |
|
|
|
|
sr.persist(s); |
|
|
|
|
return s; |
|
|
|
|
@ -158,8 +101,7 @@ public class ScanResource {
|
|
|
|
|
public Scan singleGit(@RestQuery String brewId) |
|
|
|
|
{ |
|
|
|
|
Scan s = new Scan(); |
|
|
|
|
if(!identity.getPrincipal().getName().isEmpty()) |
|
|
|
|
s.setRequestor(identity.getPrincipal().getName()); |
|
|
|
|
s.setRequestor("jochrist"); |
|
|
|
|
s.getScanRequests().addBrewBuild(brewId); |
|
|
|
|
sr.persist(s); |
|
|
|
|
return s; |
|
|
|
|
@ -172,8 +114,7 @@ public class ScanResource {
|
|
|
|
|
public Scan singlePNC(@RestQuery String pncId) |
|
|
|
|
{ |
|
|
|
|
Scan s = new Scan(); |
|
|
|
|
if(!identity.getPrincipal().getName().isEmpty()) |
|
|
|
|
s.setRequestor(identity.getPrincipal().getName()); |
|
|
|
|
s.setRequestor("jochrist"); |
|
|
|
|
s.getScanRequests().addPNCBuild(pncId); |
|
|
|
|
sr.persist(s); |
|
|
|
|
return s; |
|
|
|
|
|