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.
114 lines
3.2 KiB
114 lines
3.2 KiB
package com.redhat.pctsec.model; |
|
|
|
import com.redhat.pctsec.model.api.request.pssaas; |
|
import com.redhat.pctsec.model.api.request.scanChain; |
|
import io.vertx.mutiny.core.eventbus.EventBus; |
|
import jakarta.enterprise.context.ApplicationScoped; |
|
|
|
import java.util.*; |
|
import java.util.stream.Collectors; |
|
|
|
import jakarta.persistence.*; |
|
|
|
@ApplicationScoped |
|
@Entity |
|
@Table(name="ScanRequests") |
|
public class ScanRequests { |
|
|
|
@Id |
|
@GeneratedValue |
|
protected UUID id; |
|
|
|
@OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL) |
|
@JoinColumn(name = "scan_request_id", referencedColumnName = "id") |
|
private Set<ScanRequest> scanRequests;// = new HashSet<>(); |
|
|
|
|
|
@Column(name="scan_properties") |
|
private String globalScanProperties; |
|
|
|
@Column(name="scan_metadata") |
|
private String scanMetadata; |
|
|
|
|
|
public ScanRequests(){ |
|
//Default to the Snyk scan |
|
this.globalScanProperties = "-p snyk-only-unstable --tarball-build-script=\":\""; |
|
this.scanRequests = new HashSet<>(); |
|
} |
|
|
|
public ScanRequests(pssaas pssaas){ |
|
this(); |
|
pssaas.componentList.stream().filter(c -> c.getType().equals("git")).forEach(g -> this.addGit(g.getRepo().toString(), g.getRef())); |
|
pssaas.componentList.stream().filter(c -> c.getType().equals("brew")).forEach(g -> this.addBrewBuild(g.getBuildId())); |
|
pssaas.componentList.stream().filter(c -> c.getType().equals("pnc")).forEach(g -> this.addPNCBuild(g.getBuildId())); |
|
} |
|
|
|
|
|
public ScanRequests(scanChain scanChain){ |
|
|
|
this(); |
|
scanChain.urls.stream().forEach(g -> this.addGit(g.getRepo().toString(), g.getRef())); |
|
} |
|
|
|
//public ScanRequests(String repo, String rev){ |
|
// //shortcut for single scans |
|
// scanRequests.add(new ScanRequest(repo, rev)); |
|
//} |
|
|
|
/* |
|
public ScanRequests(String brewBuildId){ |
|
scanRequests.add(new ScanRequest(new B)); |
|
} |
|
*/ |
|
|
|
public void addBrewBuild(String brewBuildId) |
|
{ |
|
scanRequests.add(new ScanRequest(new BrewBuild(brewBuildId))); |
|
} |
|
|
|
public void addGit(String repo, String rev) |
|
{ |
|
scanRequests.add(new ScanRequest(new Git(repo, rev))); |
|
} |
|
|
|
public void addPNCBuild(String pncBuildId) |
|
{ |
|
scanRequests.add(new ScanRequest(new PNCBuild(pncBuildId))); |
|
} |
|
|
|
//Create tekton pipeline/taskrun |
|
public List<ScanTask> execute(EventBus eventBus){ |
|
scanRequests.stream().forEach(s -> s.setBus(eventBus)); |
|
return scanRequests.stream().map(s -> s.executeScan()).collect(Collectors.toList()); |
|
/* |
|
for(ScanRequest s : scanRequests){ |
|
s.executeScan(); |
|
} |
|
*/ |
|
} |
|
|
|
public Set<ScanRequest> getScanRequests() { |
|
return scanRequests; |
|
} |
|
|
|
public void setScanRequests(Set<ScanRequest> scanRequests) { |
|
this.scanRequests = scanRequests; |
|
} |
|
|
|
public String getGlobalScanProperties() { |
|
return globalScanProperties; |
|
} |
|
|
|
public void setGlobalScanProperties(String globalScanProperties) { |
|
this.globalScanProperties = globalScanProperties; |
|
} |
|
|
|
public String getScanMetadata() { |
|
return scanMetadata; |
|
} |
|
|
|
public void setScanMetadata(String scanMetadata) { |
|
this.scanMetadata = scanMetadata; |
|
} |
|
}
|
|
|