package com.checkmarx.flow.dto; import com.checkmarx.flow.config.CliMode; import com.checkmarx.flow.config.FindingSeverity; import com.checkmarx.flow.config.external.ASTConfig; import com.checkmarx.flow.service.VulnerabilityScanner; import com.checkmarx.sdk.config.ScaConfig; import com.checkmarx.sdk.dto.filtering.FilterConfiguration; import com.checkmarx.sdk.dto.cx.CxEmailNotifications; import lombok.*; import java.util.*; /** * Object containing all applicable information about the scan request details */ @Data @Builder @NoArgsConstructor @AllArgsConstructor public class ScanRequest { @Getter @Setter @Builder.Default private Boolean scanSubmittedComment = true; @Getter @Setter @Builder.Default private Boolean deleteBranchedProject = false; private String id; private String namespace; private String application; private String org; private String team; private String project; private String altProject; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) private String altFields; private Map cxFields; private Map scanFields; private String site; @Getter @Setter @Builder.Default private boolean branchProtectionEnabled= false; @Getter @Setter @Builder.Default private boolean isForked= false; @Getter @Setter @Builder.Default private boolean isPRCloseEvent= false; @Getter @Setter @Builder.Default private boolean isDeleteForkedProject= false; /** * git commit ID, also known as 'SHA' or 'commit hash'. *
- For push event: ID of the last commit in the push event. *
- For pull request event: ID of the last commit in the pull request source branch. *
Currently supported for Bitbucket Cloud/Server, GitHub and GitLab. */ private String hash; private String repoUrl; private String repoUrlWithAuth; private String repoName; private String branch; private String defaultBranch; private String mergeTargetBranch; private String mergeNoteUri; //project repoProjectId used by GitLab private Integer repoProjectId; private String refs; private List email; private boolean forceScan; @Getter @Setter private String scanResubmit; private Boolean incremental; @Getter @Setter @Builder.Default private Boolean disablePolicyViolation=true; private String scanPreset; /** * Getting populated from the ControllerRequest. * Indicates whether we got a scm-instance parameter from a webhook event. * In case not null it will override the configuration default scm credentials */ private String scmInstance; /** * Indicates whether scan preset has been overridden. * Overrides may come from a webhook parameter or config-as-code. */ @Builder.Default private boolean scanPresetOverride = false; /** Also known as scan engine configuration. */ private String scanConfiguration; private List excludeFiles; private List excludeFolders; private Repository repoType; private Product product; private BugTracker bugTracker; private Type type; private List activeBranches; private FilterConfiguration filter; private Map thresholds; private Map additionalMetadata; private List vulnerabilityScanners; private ScaConfig scaConfig; private ASTConfig astConfig; @Getter @Setter private String scannerApiSec; @Getter @Setter private String commentSAST; @Getter @Setter private Boolean disableBreakbuild; @Getter @Setter private String branchPattern; /** * 'Organization' here means the top-most level of project hierarchy. * E.g. if SCM supports several levels of hierarchy, path to the project may look like org1/suborg/my-project. * In such case the value of organizationId should be 'org1'. */ @Getter @Setter private String organizationId; @Getter @Setter private String gitUrl; @Getter @Setter private boolean disableCertificateValidation; //SSH Key per repo @Getter @Setter private String sshKeyIdentifier; //command line mode @Getter @Setter private CliMode cliMode; @Getter @Setter private CxEmailNotifications emailNotifications; @Getter @Setter private Integer postBackActionId; @Getter @Setter private String zipExclude; @Getter @Setter private String zipInclude; @Getter @Setter private Integer scanId; @Getter @Setter private String modifiedProjectName; @Getter @Setter private boolean sbom; @Getter @Setter @Builder.Default private boolean publicScan=true; @Getter @Setter private String latestCommitterEmail; @Getter @Setter private Double sastVersion; // @Getter @Setter @Builder.Default // private Boolean overrideProjectSetting = false; public ScanRequest(ScanRequest other) { this.namespace = other.namespace; this.application = other.application; this.org = other.org; this.team = other.team; this.project = other.project; this.cxFields = other.cxFields; this.scanFields = other.scanFields; this.altProject = other.altProject; this.altFields = other.altFields; this.site = other.site; this.hash = other.hash; this.repoUrl = other.repoUrl; this.repoUrlWithAuth = other.repoUrlWithAuth; this.repoName = other.repoName; this.branch = other.branch; this.defaultBranch = other.defaultBranch; this.mergeTargetBranch = other.mergeTargetBranch; this.mergeNoteUri = other.mergeNoteUri; this.repoProjectId = other.repoProjectId; this.refs = other.refs; this.email = other.email; this.incremental = other.incremental; this.scanPreset = other.scanPreset; this.excludeFiles = other.excludeFiles; this.excludeFolders = other.excludeFolders; this.repoType = other.repoType; this.product = other.product; this.bugTracker = new BugTracker(other.getBugTracker()); this.type = other.type; this.activeBranches = other.activeBranches; this.filter = other.filter; this.forceScan = other.forceScan; this.scanResubmit = other.scanResubmit; this.vulnerabilityScanners = other.vulnerabilityScanners; this.scaConfig = other.scaConfig; this.astConfig = other.astConfig; this.thresholds = other.thresholds; this.scannerApiSec = other.scannerApiSec; this.organizationId = other.organizationId; this.gitUrl = other.gitUrl; this.disableCertificateValidation = other.disableCertificateValidation; this.sshKeyIdentifier = other.sshKeyIdentifier; this.cliMode = other.cliMode; this.emailNotifications = other.emailNotifications; this.zipExclude = other.zipExclude; this.modifiedProjectName = other.modifiedProjectName; this.sbom= other.sbom; } public Map getAltFields() { if(this.altFields == null){ return Collections.emptyMap(); } Map map = new HashMap<>(); for( String s : this.altFields.split(",")) { String[] split = s.split(":"); map.put(split[0],split[1]); } return map; } public void putAdditionalMetadata(String key, String value){ if(this.additionalMetadata == null){ this.additionalMetadata = new HashMap<>(); } this.additionalMetadata.put(key, value); } public String getAdditionalMetadata(String key){ if (this.additionalMetadata != null) { return this.additionalMetadata.get(key); } return null; } public String getFilename(){ return this.getAdditionalMetadata("filename"); } public void setFilename(String filename){ this.putAdditionalMetadata("filename", filename); } public String toString() { return "ScanRequest(namespace=" + this.getNamespace() + ", application=" + this.getApplication() + ", org=" + this.getOrg() + ", team=" + this.getTeam() + ", project=" + this.getProject() + ", cxFields=" + this.getCxFields() + ", site=" + this.getSite() + ", repoUrl=" + this.getRepoUrl() + ", repoName=" + this.getRepoName() + ", branch=" + this.getBranch() + ", mergeTargetBranch=" + this.getMergeTargetBranch() + ", mergeNoteUri=" + this.getMergeNoteUri() + ", repoProjectId=" + this.getRepoProjectId() + ", refs=" + this.getRefs() + ", email=" + this.getEmail() + ", incremental=" + this.isIncremental() + ", scanPreset=" + this.getScanPreset() + ", excludeFiles=" + this.getExcludeFiles() + ", excludeFolders=" + this.getExcludeFolders() + ", repoType=" + this.getRepoType() + ", product=" + this.getProduct() + ", bugTracker=" + this.getBugTracker() + ", type=" + this.getType() + ", activeBranches=" + this.getActiveBranches() + ", filter=" + this.getFilter()+ ", scanResubmit=" + this.getScanResubmit() + ")"; } public Boolean isIncremental() { return Optional.ofNullable(incremental).orElse(Boolean.FALSE); } public Boolean getIncrementalField() { return incremental; } public enum Product { CX("CX"), CXOSA("CXOSA"); private final String value; Product(String value) { this.value = value; } public String getProduct() { return value; } } public enum Type { SAST("SAST"), DAST("DAST"), IAST("IAST"); private final String value; Type(String value) { this.value = value; } public String getType() { return value; } } public enum Repository { GITHUB("GITHUB"), GITLAB("GITLAB"), BITBUCKET("BITBUCKET"), BITBUCKETSERVER("BITBUCKETSERVER"), ADO("ADO"), NA("NA"); private final String value; Repository(String value) { this.value = value; } public String getRepository() { return value; } } }