Skip to content

Commit

Permalink
clear triggers and skip loading when repo is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
benbroadaway committed Feb 9, 2024
1 parent 8e0e21b commit f95f279
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.walmartlabs.concord.server.org.ResourceAccessLevel;
import com.walmartlabs.concord.server.org.secret.SecretEntry;
import com.walmartlabs.concord.server.org.secret.SecretManager;
import com.walmartlabs.concord.server.org.triggers.TriggerManager;
import com.walmartlabs.concord.server.policy.EntityAction;
import com.walmartlabs.concord.server.policy.EntityType;
import com.walmartlabs.concord.server.policy.PolicyManager;
Expand All @@ -52,21 +53,24 @@ public class ProjectRepositoryManager {
private final AuditLog auditLog;
private final PolicyManager policyManager;
private final RepositoryRefresher repositoryRefresher;
private final TriggerManager triggerManager;

@Inject
public ProjectRepositoryManager(ProjectAccessManager projectAccessManager,
SecretManager secretManager,
RepositoryDao repositoryDao,
AuditLog auditLog,
PolicyManager policyManager,
RepositoryRefresher repositoryRefresher) {
RepositoryRefresher repositoryRefresher,
TriggerManager triggerManager) {

this.projectAccessManager = projectAccessManager;
this.secretManager = secretManager;
this.repositoryDao = repositoryDao;
this.auditLog = auditLog;
this.policyManager = policyManager;
this.repositoryRefresher = repositoryRefresher;
this.triggerManager = triggerManager;
}

public RepositoryEntry get(UUID projectId, String repositoryName) {
Expand Down Expand Up @@ -103,7 +107,9 @@ public void createOrUpdate(UUID projectId, RepositoryEntry entry) {
policyManager.checkEntity(project.getOrgId(), project.getId(), EntityType.REPOSITORY, repoId == null ? EntityAction.CREATE : EntityAction.UPDATE,
null, PolicyUtils.repositoryToMap(project, entry, secret));

ProcessDefinition processDefinition = processDefinition(project.getOrgId(), projectId, entry);
ProcessDefinition processDefinition = entry.isDisabled()
? null
: processDefinition(project.getOrgId(), projectId, entry);

InsertUpdateResult result = repositoryDao.txResult(tx -> insertOrUpdate(tx, projectId, repoId, entry, secret, processDefinition));
addAuditLog(project, result.prevEntry(), result.newEntry());
Expand Down Expand Up @@ -153,6 +159,12 @@ interface InsertUpdateResult {
}

private InsertUpdateResult insertOrUpdate(DSLContext tx, UUID projectId, UUID repoId, RepositoryEntry entry, SecretEntry secret, ProcessDefinition processDefinition) {
if (!entry.isDisabled() && processDefinition == null) {
// should have already thrown and exception by this point, but just in case
// something went wrong cloning/loading process definition
throw new ConcordApplicationException("Error while loading process definition", Response.Status.INTERNAL_SERVER_ERROR);
}

RepositoryEntry prevEntry = null;
if (repoId == null) {
repoId = repositoryDao.insert(tx, projectId,
Expand All @@ -178,7 +190,9 @@ private InsertUpdateResult insertOrUpdate(DSLContext tx, UUID projectId, UUID re
entry.isTriggersDisabled());
}

if (!entry.isDisabled()) {
if (entry.isDisabled()) {
triggerManager.clearTriggers(tx, projectId, repoId);
} else {
repositoryRefresher.refresh(tx, projectId, entry.getName(), processDefinition);
}

Expand Down

0 comments on commit f95f279

Please sign in to comment.