From 045df604a055677589f320237dc346944464236d Mon Sep 17 00:00:00 2001 From: Jonathan Christison Date: Wed, 28 Jun 2023 08:55:43 +0100 Subject: [PATCH] Start adding ORM support --- pom.xml | 30 +++++++---- .../redhat/pctsec/model/ScanCollection.java | 34 ------------- .../model/{Scan.java => ScanRequest.java} | 8 +-- .../com/redhat/pctsec/model/ScanRequests.java | 50 +++++++++++++++++++ .../com/redhat/pctsec/rest/v1alpha1/Scan.java | 11 ++-- 5 files changed, 78 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/com/redhat/pctsec/model/ScanCollection.java rename src/main/java/com/redhat/pctsec/model/{Scan.java => ScanRequest.java} (84%) create mode 100644 src/main/java/com/redhat/pctsec/model/ScanRequests.java diff --git a/pom.xml b/pom.xml index 1641b36..715e16f 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,14 @@ org.apache.commons commons-lang3 + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-hibernate-orm-panache + io.quarkus quarkus-junit5 @@ -76,17 +84,17 @@ - io.smallrye - jandex-maven-plugin - 3.1.1 - - - make-index - - jandex - - - + io.smallrye + jandex-maven-plugin + 3.1.1 + + + make-index + + jandex + + + ${quarkus.platform.group-id} diff --git a/src/main/java/com/redhat/pctsec/model/ScanCollection.java b/src/main/java/com/redhat/pctsec/model/ScanCollection.java deleted file mode 100644 index 6d443d8..0000000 --- a/src/main/java/com/redhat/pctsec/model/ScanCollection.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.redhat.pctsec.model; - -import jakarta.enterprise.context.ApplicationScoped; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -@ApplicationScoped -public class ScanCollection { - - // - private Set scans = new HashSet<>(); - private HashMap globalScanProperties; - - public ScanCollection(pssaas pssaas){ - //Iterate scan payload and create scans - } - - public ScanCollection(String repo, String rev){ - //shortcut for single scans - scans.add(new Scan(repo, rev)); - } - - public ScanCollection(String brewBuildId){ - scans.add(new Scan(brewBuildId)); - } - - //Create tekton pipeline/taskrun - public void execute(){ - for(Scan s : scans){ - s.executeScan(); - } - } -} diff --git a/src/main/java/com/redhat/pctsec/model/Scan.java b/src/main/java/com/redhat/pctsec/model/ScanRequest.java similarity index 84% rename from src/main/java/com/redhat/pctsec/model/Scan.java rename to src/main/java/com/redhat/pctsec/model/ScanRequest.java index 530b10a..6e2a42c 100644 --- a/src/main/java/com/redhat/pctsec/model/Scan.java +++ b/src/main/java/com/redhat/pctsec/model/ScanRequest.java @@ -8,7 +8,7 @@ import jakarta.inject.Singleton; import java.util.HashMap; @ApplicationScoped -public class Scan { +public class ScanRequest { private HashMap metadata; private HashMap oshScanOptions; @@ -21,12 +21,12 @@ public class Scan { @Inject scmUrlPipelineRun plr; - public Scan(String brewBuildId) + public ScanRequest(String brewBuildId) { this.brewBuild = brewBuildId; } - public Scan(String repo, String ref) + public ScanRequest(String repo, String ref) { this.scmurl = new HashMap<>(); this.scmurl.put("repo", repo); @@ -34,7 +34,7 @@ public class Scan { } public void executeScan(){ if(this.brewBuild != null && !this.brewBuild.trim().isEmpty()){ - btr = new brewTaskRun(); + //btr = new brewTaskRun(); btr.invokeScanTask(this.brewBuild); } } diff --git a/src/main/java/com/redhat/pctsec/model/ScanRequests.java b/src/main/java/com/redhat/pctsec/model/ScanRequests.java new file mode 100644 index 0000000..185de6d --- /dev/null +++ b/src/main/java/com/redhat/pctsec/model/ScanRequests.java @@ -0,0 +1,50 @@ +package com.redhat.pctsec.model; + +import com.redhat.pctsec.rest.v1alpha1.Scan; +import jakarta.enterprise.context.ApplicationScoped; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +@ApplicationScoped +public class ScanRequests { + + @Id @GeneratedValue private Long id; + private Set scanRequests = new HashSet<>(); + private HashMap globalScanProperties; + + public ScanRequests(){ + this.id = + } + public ScanRequests(pssaas pssaas){ + //Iterate scan payload and create scans + } + + public ScanRequests(String repo, String rev){ + //shortcut for single scans + scanRequests.add(new ScanRequest(repo, rev)); + } + + public ScanRequests(String brewBuildId){ + scanRequests.add(new ScanRequest(brewBuildId)); + } + + public void addBrewBuild(String brewBuildId) + { + scanRequests.add(new ScanRequest(brewBuildId)); + } + + public void addGit(String repo, String rev) + { + scanRequests.add(new ScanRequest(repo, rev)); + } + + //Create tekton pipeline/taskrun + public void execute(){ + for(ScanRequest s : scanRequests){ + s.executeScan(); + } + } +} diff --git a/src/main/java/com/redhat/pctsec/rest/v1alpha1/Scan.java b/src/main/java/com/redhat/pctsec/rest/v1alpha1/Scan.java index a16d818..15931e8 100644 --- a/src/main/java/com/redhat/pctsec/rest/v1alpha1/Scan.java +++ b/src/main/java/com/redhat/pctsec/rest/v1alpha1/Scan.java @@ -1,6 +1,6 @@ package com.redhat.pctsec.rest.v1alpha1; -import com.redhat.pctsec.model.ScanCollection; +import com.redhat.pctsec.model.ScanRequests; import com.redhat.pctsec.model.pssaas; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.Valid; @@ -8,13 +8,12 @@ import jakarta.ws.rs.*; import org.jboss.resteasy.reactive.RestQuery; import java.util.HashMap; -import java.util.List; @ApplicationScoped @Path("/api/v1a/Scan") public class Scan { - HashMap scanCollection = new HashMap<>(); + HashMap scanCollection = new HashMap<>(); @POST @Path("PSSaaS") @Consumes({ "application/json" }) @@ -30,7 +29,7 @@ public class Scan { @GET @Path("{id}") - public ScanCollection scanRequest(String id){ + public ScanRequests scanRequest(String id){ return scanCollection.get(id.toString()); } @@ -45,7 +44,7 @@ public class Scan { @Path("single/git") public String singleGit(@RestQuery String repo, @RestQuery String ref) { - ScanCollection sc = new ScanCollection(repo, ref); + ScanRequests sc = new ScanRequests(repo, ref); scanCollection.put("1",sc); return "restult"; } @@ -54,7 +53,7 @@ public class Scan { @Path("single/brew") public String singleGit(@RestQuery String brewId) { - ScanCollection sc = new ScanCollection(brewId); + ScanRequests sc = new ScanRequests(brewId); scanCollection.put("2",sc); return "result"; }