Skip to content

Commit

Permalink
add policy checks to releaseJobTrigger
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Oct 20, 2024
1 parent 9847c64 commit eb74bb1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions apps/jobs/src/policy-checker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eq } from "@ctrlplane/db";
import { and, eq, isNull, or } from "@ctrlplane/db";
import { db } from "@ctrlplane/db/client";
import * as schema from "@ctrlplane/db/schema";
import {
Expand All @@ -10,11 +10,30 @@ import { JobStatus } from "@ctrlplane/validators/jobs";

export const run = async () => {
const releaseJobTriggers = await db
.select()
.select({ releaseJobTrigger: schema.releaseJobTrigger })
.from(schema.releaseJobTrigger)
.innerJoin(schema.job, eq(schema.releaseJobTrigger.jobId, schema.job.id))
.where(eq(schema.job.status, JobStatus.Pending))
.then((rows) => rows.map((row) => row.release_job_trigger));
.innerJoin(
schema.environment,
eq(schema.releaseJobTrigger.environmentId, schema.environment.id),
)
.leftJoin(
schema.environmentPolicyApproval,
eq(
schema.environment.policyId,
schema.environmentPolicyApproval.policyId,
),
)
.where(
and(
eq(schema.job.status, JobStatus.Pending),
or(
isNull(schema.environmentPolicyApproval.id),
eq(schema.environmentPolicyApproval.status, "approved"),
),
),
)
.then((rows) => rows.map((row) => row.releaseJobTrigger));

if (releaseJobTriggers.length === 0) return;
console.log(
Expand Down

0 comments on commit eb74bb1

Please sign in to comment.