Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create workflow steps on reanalysis #254

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,9 @@ public void createWorkflowSteps(UUID token) {
getWorkflowStateQueryManager().createWorkflowSteps(token);
}

public void createReanalyzeSteps(UUID token) {
getWorkflowStateQueryManager().createReanalyzeSteps(token);
}

public List<WorkflowState> getAllWorkflowStatesForAToken(UUID token) {
return getWorkflowStateQueryManager().getAllWorkflowStatesForAToken(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,36 @@ public void updateWorkflowStateToFailed(WorkflowState workflowState, String fail
}
}

public void createReanalyzeSteps(UUID token) {
final Transaction trx = pm.currentTransaction();
try {
trx.begin();
Date now = new Date();

WorkflowState vulnAnalysisState = new WorkflowState();
vulnAnalysisState.setParent(null);
vulnAnalysisState.setToken(token);
vulnAnalysisState.setStep(WorkflowStep.VULN_ANALYSIS);
vulnAnalysisState.setStatus(WorkflowStatus.PENDING);
vulnAnalysisState.setUpdatedAt(now);
WorkflowState vulnAnalysisParent = pm.makePersistent(vulnAnalysisState);

WorkflowState policyEvaluationState = new WorkflowState();
policyEvaluationState.setParent(vulnAnalysisParent);
policyEvaluationState.setToken(token);
policyEvaluationState.setStep(WorkflowStep.POLICY_EVALUATION);
policyEvaluationState.setStatus(WorkflowStatus.PENDING);
policyEvaluationState.setUpdatedAt(now);
pm.makePersistent(policyEvaluationState);

trx.commit();
} finally {
if (trx.isActive()) {
trx.rollback();
}
}
}

public void createWorkflowSteps(UUID token) {
final Transaction trx = pm.currentTransaction();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.swagger.annotations.ResponseHeader;
import org.dependencytrack.auth.Permissions;
import org.dependencytrack.event.PortfolioRepositoryMetaAnalysisEvent;
import org.dependencytrack.event.ProjectMetricsUpdateEvent;
import org.dependencytrack.event.ProjectRepositoryMetaAnalysisEvent;
import org.dependencytrack.event.ProjectVulnerabilityAnalysisEvent;
import org.dependencytrack.integrations.FindingPackagingFormat;
Expand Down Expand Up @@ -179,6 +178,7 @@ public Response analyzeProject(
LOGGER.info("Analysis of project " + project.getUuid() + " requested by " + super.getPrincipal().getName());

final ProjectVulnerabilityAnalysisEvent vae = new ProjectVulnerabilityAnalysisEvent(project.getUuid());
qm.createReanalyzeSteps(vae.getChainIdentifier());
Event.dispatch(vae);
final ProjectRepositoryMetaAnalysisEvent projectRepositoryMetaAnalysisEvent = new ProjectRepositoryMetaAnalysisEvent(project.getUuid());
Event.dispatch(projectRepositoryMetaAnalysisEvent);
Expand Down
Loading
Loading