9 changed files with 165 additions and 5 deletions
@ -1,2 +1,41 @@ |
|||||||
package com.redhat.pctsec.model;public class Scan { |
package com.redhat.pctsec.model; |
||||||
|
|
||||||
|
import com.redhat.pctsec.tekton.brewTaskRun; |
||||||
|
import com.redhat.pctsec.tekton.scmUrlPipelineRun; |
||||||
|
import jakarta.enterprise.context.ApplicationScoped; |
||||||
|
import jakarta.inject.Inject; |
||||||
|
import jakarta.inject.Singleton; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
@ApplicationScoped |
||||||
|
public class Scan { |
||||||
|
|
||||||
|
private HashMap<String, String> metadata; |
||||||
|
private HashMap<String, String> oshScanOptions; |
||||||
|
private String brewBuild; |
||||||
|
private HashMap<String, String> scmurl; |
||||||
|
|
||||||
|
@Inject |
||||||
|
brewTaskRun btr; |
||||||
|
|
||||||
|
@Inject |
||||||
|
scmUrlPipelineRun plr; |
||||||
|
|
||||||
|
public Scan(String brewBuildId) |
||||||
|
{ |
||||||
|
this.brewBuild = brewBuildId; |
||||||
|
} |
||||||
|
|
||||||
|
public Scan(String repo, String ref) |
||||||
|
{ |
||||||
|
this.scmurl = new HashMap<>(); |
||||||
|
this.scmurl.put("repo", repo); |
||||||
|
this.scmurl.put("ref", repo); |
||||||
|
} |
||||||
|
public void executeScan(){ |
||||||
|
if(this.brewBuild != null && !this.brewBuild.trim().isEmpty()){ |
||||||
|
btr = new brewTaskRun(); |
||||||
|
btr.invokeScanTask(this.brewBuild); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
@ -1,4 +1,34 @@ |
|||||||
package com.redhat.pctsec.model; |
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 { |
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(); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
@ -1,4 +1,4 @@ |
|||||||
package com.redhat.pctsec.model; |
package com.redhat.pctsec.model; |
||||||
|
|
||||||
public class scanchain { |
public class scanChain { |
||||||
} |
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package com.redhat.pctsec.tekton; |
||||||
|
|
||||||
|
import io.fabric8.tekton.client.DefaultTektonClient; |
||||||
|
import io.fabric8.tekton.client.TektonClient; |
||||||
|
import io.fabric8.tekton.pipeline.v1beta1.ArrayOrString; |
||||||
|
import io.fabric8.tekton.pipeline.v1beta1.Param; |
||||||
|
import io.fabric8.tekton.pipeline.v1beta1.TaskRun; |
||||||
|
import io.fabric8.tekton.pipeline.v1beta1.TaskRunBuilder; |
||||||
|
import jakarta.enterprise.context.ApplicationScoped; |
||||||
|
import jakarta.inject.Singleton; |
||||||
|
import org.apache.commons.lang3.RandomStringUtils; |
||||||
|
|
||||||
|
import jakarta.inject.Inject; |
||||||
|
|
||||||
|
@io.quarkus.arc.Unremovable |
||||||
|
public class brewTaskRun { |
||||||
|
public static final String NAMESPACE = "pct-security-tooling"; |
||||||
|
public static final String BUILD_ID = "buildId"; |
||||||
|
public static final String SCAN_PROFILE = "scanProfile"; |
||||||
|
public static final String TASK_REFERENCE = "osh-scan-task"; |
||||||
|
public static final String SERVICE_ACCOUNT = "osh"; |
||||||
|
|
||||||
|
//@Inject
|
||||||
|
TektonClient tektonClient = new DefaultTektonClient(); |
||||||
|
|
||||||
|
public String invokeScanTask(String buildId) { |
||||||
|
// String buildId = "xterm-366-8.el9";
|
||||||
|
String scanProfile = "snyk-only-unstable"; |
||||||
|
|
||||||
|
// random taskrun name generating for now
|
||||||
|
TaskRun taskRun = new TaskRunBuilder().withNewMetadata().withName("osh-scan-taskrun-" + RandomStringUtils.randomAlphanumeric(8).toLowerCase()) |
||||||
|
.endMetadata() |
||||||
|
.withNewSpec() |
||||||
|
.withServiceAccountName(SERVICE_ACCOUNT) |
||||||
|
.withNewTaskRef() |
||||||
|
.withName(TASK_REFERENCE) |
||||||
|
.endTaskRef() |
||||||
|
.withParams( |
||||||
|
new Param("buildId", new ArrayOrString(buildId)), |
||||||
|
new Param("scanProfile", new ArrayOrString(scanProfile))) |
||||||
|
.endSpec() |
||||||
|
.build(); |
||||||
|
|
||||||
|
tektonClient.v1beta1().taskRuns().inNamespace(NAMESPACE).resource(taskRun).create(); |
||||||
|
|
||||||
|
return "Scan invoked"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
package com.redhat.pctsec.tekton; |
||||||
|
|
||||||
|
public class scmUrlPipelineRun { |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue