Browse Source

Start adding ORM support

refactor_future
Jonathan Christison 3 years ago
parent
commit
045df604a0
  1. 30
      pom.xml
  2. 34
      src/main/java/com/redhat/pctsec/model/ScanCollection.java
  3. 8
      src/main/java/com/redhat/pctsec/model/ScanRequest.java
  4. 50
      src/main/java/com/redhat/pctsec/model/ScanRequests.java
  5. 11
      src/main/java/com/redhat/pctsec/rest/v1alpha1/Scan.java

30
pom.xml

@ -62,6 +62,14 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
@ -76,17 +84,17 @@
<build>
<plugins>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>

34
src/main/java/com/redhat/pctsec/model/ScanCollection.java

@ -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<Scan> scans = new HashSet<>();
private HashMap<String, String> 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();
}
}
}

8
src/main/java/com/redhat/pctsec/model/Scan.java → 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<String, String> metadata;
private HashMap<String, String> 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);
}
}

50
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<ScanRequest> scanRequests = new HashSet<>();
private HashMap<String, String> 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();
}
}
}

11
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<String, ScanCollection> scanCollection = new HashMap<>();
HashMap<String, ScanRequests> 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";
}

Loading…
Cancel
Save